FAQ:NewInstanceMsSql Windows: Difference between revisions

From Wiki_dbSQWare
Jump to navigation Jump to search
mNo edit summary
Line 130: Line 130:
</syntaxhighlight>
</syntaxhighlight>


====Creating a Specific SQL-SERVER Account (dbSQWare) ====
====Création de la connexion à l'instance SQL====
Example for a "Remote" Connection
Vous avez 2 solutions pour connecter dbSQWare à vos instances SQL SERVER :
* la création d'un compte sql dans l'instance, il faut avoir activé la connexion mixte.
* l'utilisation d'un compte de service (déclaré dans l'Active Directory).
=====Création d'un compte Sql-Serveur spécifique dbSQWare=====
/!\ Il faut autoriser l'accès SQL sur les instances si ce n'est pas le cas !<br/>
Exemple d'ordre de création :
<syntaxhighlight lang="sql" line>
<syntaxhighlight lang="sql" line>
grant all privileges on *.* to 'DBSDBA'@'%' IDENTIFIED BY 'DoNotSetThisPassword!' with grant option;
USE [master]
GO
CREATE LOGIN [msq_dba] WITH PASSWORD=N'NePasMettreCePassword!', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
EXEC master..sp_addsrvrolemember @loginame = N'msq_dba', @rolename = N'sysadmin'
GO
</syntaxhighlight>
'sysadmin' est obligatoire à cause notamment des commandes "DBCC".
 
Vous pouvez mettre le nom et le mot de passe que vous souhaitez !<br/>
Ce compte devra être déclaré sur le compte unix mssql@sqwarebox ...<br/>
Si une entrée spécifique est trouvée c'est elle sui est prise, si non, on prend l'entrée "DEFAULT".<br/>
<syntaxhighlight lang="sh" line>
mssql@sqwarebox:/home/mssql (NoSID) $ cat .passwd_mssql
DEFAULT;msq_dba;NePasMettreCePassword!
SPECIFIC_MSSQL;sa;sapass
</syntaxhighlight>
 
=====Création d'une connexion avec un compte de service spécifique dbSQWare=====
Exemple d'ordre de création :
<syntaxhighlight lang="sql" line>
USE [master]
GO
CREATE LOGIN [domain\svc-dbsqware] FROM WINDOWS;
GO
EXEC master..sp_addsrvrolemember @loginame = N'domain\svc-dbsqware', @rolename = N'sysadmin'
GO
</syntaxhighlight>
'sysadmin' est obligatoire à cause notamment des commandes "DBCC".


/* or */
Ce compte devra être déclaré sur le compte unix mssql@sqwarebox ...<br/>
create user 'DBSDBA'@'%' IDENTIFIED BY 'DoNotSetThisPassword!';
Si une entrée spécifique est trouvée c'est elle sui est prise, si non, on prend l'entrée "DEFAULT".<br/>
grant all privileges on *.* to 'DBSDBA'@'%' with grant option;
<syntaxhighlight lang="sh" line>
flush privileges;
mssql@sqwarebox:/home/mssql (NoSID) $ cat .passwd_mssql
DEFAULT;domain\svc-dbsqware;MettreLePasswordDuCompte!
SPECIFIC_MSSQL;sa;sapass
</syntaxhighlight>
</syntaxhighlight>


You can enter any username and password you like!<br/>
====Vérifier l'entrée dans freetds.conf====
This account must be registered under the Unix account mysql@sqwarebox...<br/>
On vérifie que les informations dbalias, host et port se soient bien inscrite dans le fichier !<br/>
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
vi /home/mysql/.passwd_mysql
# Sur mssql@sqwarebox /applis/mssql/freetds/etc/freetds.conf
DbAlias;UserName;Passwd;HostName;Port
#Exemple
MYS_INST_PRD;DBSDBA;DoNotSetThisPassword!;srvdbmys01;3306
[WINMSQ_INST1]
host = WINMSQ
port = 1433
</syntaxhighlight>
</syntaxhighlight>


====Test "remote" connection====
====Test sendmail (non obligatoire)====
/!\ Faire la première fois, inutile après car toujours la même machine !
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
# From : dbsqware@sqwarebox
# From : dbsqware@sqwarebox
menu_mys TestInstConnectionDistNoMail GenLstInstanceNew
menu_msq TestSendmail GenLstInstanceNew
</syntaxhighlight>
</syntaxhighlight>


==Starting the Instance==
===Tests de connexion "manuels" à l'instance Sql-Serveur===
===Generating the Default SQWareProduction Configuration===
Le but étant de tester la connexion automatique à l'instance Sql-Serveur.
/!\ Only instances that will be in "ON" status!
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
# From : dbsqware@sqwarebox
# From : dbsqware@sqwarebox
menu_mys GenDefConf_SQWareProduction GenLstInstanceNew
menu_msq TestInstConnectionOnNoMail GenLstInstanceNew
</syntaxhighlight>
</syntaxhighlight>


===Update SQWare Repository===
Vérifiez que vous êtes connectés à la bonne instance (champ FullName).<br/>
In the dbSQWare repository via the administration console, update the status of the new MySQL/MariaDB instance (currently NEW) to the desired value (ON, DIST).
Exemple:
############################################################################
TestType;InstanceParam;DbAlias;FullName;VersionMajInt;VersionPatch;ProductEdition;BackupPath
TestConnection;MSSQL_INST1;MSSQL_INST1;MSSQL\INST1;2008;10.50.1600.1;Developer;E:/BackupsMssql
############################################################################
 
Si la version de Windows Server est inférieure ou égale à Windows Server 2012, vous devez ajouter "tds version = 7.0" dans la colonne Custom 2 du référentiel. Cela permet de forcer l’utilisation d’une version de FreeTDS compatible avec le serveur


===Testing the "Recovery" of Indicators===
==Mise en exploitation de l'instance==
At this point, you can test the recovery of missing indicators (in principle, only the instances you have just integrated!).
===Génération de la configuration par défaut SQWareProduction===
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
# From : dbsqware@sqwarebox
# From : dbsqware@sqwarebox
## for those with status "ON"
menu_msq GenDefConf_SQWareProduction GenLstInstanceNew
repind_mys
## for those with status "DIST"
repind_mys_dist
</syntaxhighlight>
</syntaxhighlight>


===Operation (stats, backups, etc.) for "ON" instances===
===Mise à jour de SQWareRepository===
====Generating SQWareProduction configs====
Dans le repository dbSQWare via la console d’administration, mettre à jour le statut de la nouvelle instance Sql-Serveur (à NEW actuellement) avec la valeur '''ON'''.
If you followed the instance insertion procedure, this part is already done by step "menu_mys GenDefConf_SQWareProduction GenLstInstanceNew".<br/>
You can check with the next chapter.<br/>
<br/>
Connect to the machine that has the “MySQL/MariaDB” instance and type the following commands: <br/>
<syntaxhighlight lang="sh" line>
# From dbsqware@vmyswarebox
c MYS_INST_PRD
</syntaxhighlight>


===Test de "reprise" des indicateurs===
A ce moment là, vous pouvez tester la reprise des indicateurs manquants (en principe, uniquement les instances que vous venez d'intégrer !)
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
#Source de l'env si multi-instance (from mysql@my_mysql_host)
# From : dbsqware@sqwarebox
e MYS_INST_PRD
repind_msq
</syntaxhighlight>
</syntaxhighlight>


===Exploitation (stats, backups, …)===
====Génération des conf SQWareProduction====
Si vous avez suivi la procédure d’insertion de l’instance, cette partie est déjà fait par l’étape "menu_msq GenDefConf_SQWareProduction GenLstInstanceNew".<br/>
Vous pouvez vérifier avec le chapitre suivant.<br/>
<br/>
Se connecter à la machine unix du point central avec le compte « mssql » et taper les commandes suivantes :<br/>
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
# From mssql@vmsqwarebox
#Entrez le nom de l’instance
too
too
./sqwmys_GenerateCreateInstance.ksh -dbsOnly
./sqwmsq_GenerateCreateInstance.ksh -I WINMSQ_INST1
</syntaxhighlight>
</syntaxhighlight>
Vérifier que ce qui est proposé est bon et tapez « y » si c’est le cas.<br/>
Vérifier que ce qui est proposé est bon et tapez « y » si c’est le cas.<br/>
A ce moment, vous avez généré les fichiers de configuration par défaut de SQWareProduction.
A ce moment, vous avez généré les fichiers de configuration par défaut de SQWareProduction.


====Explanations====
====Explications====
The previous steps created some default files. ($HOME/MYS_INST_PRD/sqwConfig)
Les étapes précédentes ont créé certains fichiers par défaut. ($HOME/admin/WINMSQ_INST1/sqwConfig)
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
#Enter the instance name
#Entrez le nom de l’instance
e MYS_INST_PRD
e WINMSQ_INST1
cfg
cfg
cat sqwmys_Jobs.cfg
cat sqwmsq_Jobs.cfg
</syntaxhighlight>
</syntaxhighlight>


Line 211: Line 253:
#############################################
#############################################
#IndicDba: Gather DBAs indicators
#IndicDba: Gather DBAs indicators
IndicDba:$gvsqw_MysBin/sqwmys_GatherIndicators.ksh -I MYS_INST_PRD
IndicDba:$gvsqw_MsqBin/sqwmsq_GatherIndicators.ksh -I WINMSQ_INST1
 
#Dump: backup all databases with mysqlDump
Dump:$gvsqw_MysBin/sqwmys_DumpAllDatabases.ksh -I MYS_INST_PRD -Exec


#Optimize : optimize tables for all databases
#RotateErrorLog: Rotate error log
Optimize:$gvsqw_MysBin/sqwmys_OptimizeAllDatabases.ksh -I MYS_INST_PRD -Exec
RotateErrorLog:$gvsqw_MsqBin/sqwmsq_RotateErrorLog.ksh -I WINMSQ_INST1 -Exec


#Analyse : analyze tables for all databases
#BackupAll: backup all databases
Analyze:$gvsqw_MysBin/sqwmys_AnalyzeAllDatabases.ksh -I MYS_INST_PRD -Exec
BackupAll:$gvsqw_MsqBin/sqwmsq_BackupAllDatabases.ksh -I WINMSQ_INST1 -Exec


#XtraFull: Backup full with XtraBackup
#BackupAllRep: run failed backups from BackupAll
XtraFull:$gvsqw_MysBin/sqwmys_XtraBackup.ksh -I MYS_INST_PRD -Type full -Exec
BackupAllRep:$gvsqw_MsqBin/sqwmsq_BackupAllDatabases.ksh -I WINMSQ_INST1 -REP -Exec


#XtraInc: Backup incremental with XtraBackup
#StatisticsAll : update statistics tables for all databases
XtraInc:$gvsqw_MysBin/sqwmys_XtraBackup.ksh -I MYS_INST_PRD -Type inc -Exec
StatisticsAll:$gvsqw_MsqBin/sqwmsq_StatisticsAllDatabases.ksh -I WINMSQ_INST1 -Exec


#MariaFull: Backup full with MariaBackup
#RebuildAll : Rebuild indexes tables for all databases
MariaFull:$gvsqw_MysBin/sqwmys_MariaBackup.ksh -I MYS_INST_PRD -Type full -Exec
RebuildAll:$gvsqw_MsqBin/sqwmsq_RebuildIndexAllDatabases.ksh -I WINMSQ_INST1 -Exec


#MariaInc: Backup incremental with MariaBackup
#RestoreParfile : restore list of databases content in parfile
MariaInc:$gvsqw_MysBin/sqwmys_MariaBackup.ksh -I MYS_INST_PRD -Type inc -Exec
RestoreParfile:$gvsqw_MsqBin/sqwmsq_RestoreAllDatabases.ksh -I WINMSQ_INST1 -PAR $Parfile -Exec


#PurgeAlert: Rotate error log
#CheckdbAll : DBCC CheckDB for all databases
PurgeAlert:$gvsqw_MysBin/sqwmys_PurgeAlert.ksh -I MYS_INST_PRD
CheckdbAll:$gvsqw_MsqBin/sqwmsq_CheckdbAllDatabases.ksh -I WINMSQ_INST1 -Exec
</syntaxhighlight>
</syntaxhighlight>


This is a configuration file used by the sqwmys_RunJob.ksh script to execute actions.<br/>
C’est un fichier de paramétrage qui est utilisé par le script sqwmsq_RunJob.ksh pour exécuter des actions.<br/>
<br/>
<br/>
File for a default cron job $HOME/CrontabRef_MYS_INST_PRD:
Fichier pour une cron par défaut $HOME/CrontabRef_WINMSQ_INST1 :
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
## mm(0-59) hh(0-23) dd(1-31) MM(0-12) DAY(0-sunday, 1-monday, ...) command
## mm(0-59) hh(0-23) dd(1-31) MM(0-12) DAY(0-sunday, 1-monday, ...) command
## MYS_INST_PRD
## WINMSQ_INST1
#Purge alert
# Backup all databases
00 08 * * 0 bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A PurgeAlert > $HOME/tmp/PurgeAlert_MYS_INST_PRD.log 2>&1'
00 22 * * 1-6 bash -c '. $HOME/.profile ;$gvsqw_MsqBin/sqwmsq_RunJob.ksh -I WINMSQ_INST1 -A BackupAll > $HOME/tmp/BackupAll_WINMSQ_INST1.log 2>&1'
# Dump
# Rebuild all databases
00 20 * * * bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A Dump > $HOME/tmp/Dump_MYS_INST_PRD.log 2>&1'
30 07 * * 6 bash -c '. $HOME/.profile ;$gvsqw_MsqBin/sqwmsq_RunJob.ksh -I WINMSQ_INST1 -A RebuildAll > $HOME/tmp/RebuildAll_WINMSQ_INST1.log 2>&1'
# Optimize
# Stats all databases
00 04 * * 6 bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A Optimize > $HOME/tmp/Optimize_MYS_INST_PRD.log 2>&1'
00 07 * * bash -c '. $HOME/.profile ;$gvsqw_MsqBin/sqwmsq_RunJob.ksh -I WINMSQ_INST1 -A StatisticsAll > $HOME/tmp/StatisticsAll_WINMSQ_INST1.log 2>&1'
# Analyze
00 05 * * 6 bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A Analyze > $HOME/tmp/Analyze_MYS_INST_PRD.log 2>&1'
# XtraBackup
#00 21 * * 6  bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A XtraFull > $HOME/tmp/XtraFull_MYS_INST_PRD.log 2>&1'
#00 21 * * 1-5 bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A XtraInc > $HOME/tmp/XtraInc_MYS_INST_PRD.log 2>&1'
# MariaBackup
#00 21 * * 6  bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A MariaFull > $HOME/tmp/MariaFull_MYS_INST_PRD.log 2>&1'
#00 21 * * 1-5 bash -c '. $HOME/.profile MYS_INST_PRD;$gvsqw_MysBin/sqwmys_RunJob.ksh -I MYS_INST_PRD -A MariaInc > $HOME/tmp/MariaInc_MYS_INST_PRD.log 2>&1'
</syntaxhighlight>
</syntaxhighlight>


====Startup====
====Paramétrage du chemin des backups====
Setting up cron:
Sur l’instance à gérer, voir le chemin des backups dans la clé de registre :
<syntaxhighlight lang="sql" line>
DECLARE  @v_regvalue varchar(256)
EXEC xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'BackupDirectory',  @v_regvalue OUTPUT
select 'lvsqw_BackupPath='+rtrim(@v_regvalue)+'='
go
</syntaxhighlight>
 
Pour modifier le chemin, les scripts se basent sur la clé de registre :
<syntaxhighlight lang="sql" line>
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'BackupDirectory', REG_SZ, N'E:\Backups_db'
go
</syntaxhighlight>
 
Test avec backup de master :
<syntaxhighlight lang="sh" line>
#From mssql@vmsqwarebox
$gvsqw_MsqBin/sqwmsq_BackupDatabase.ksh -I WINMSQ_INST1 -D master -Type full -Exec
</syntaxhighlight>
 
/!\ Faites attention pour cette partie, si vous n'êtes pas sûrs, ne faites rien :
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
mv $HOME/CrontabRef_MYS_INST_PRD $HOME/CrontabRef
#From mssql@vmsqwarebox pour passer toutes les databases en 'RECOVERY SIMPLE'
$gvsqw_MsqBin/../tools/sqwmsq_AlterDatabaseRecoverySimple.ksh -I WINMSQ_INST1 -Exec
 
#From mssql@vmsqwarebox pour modifier l'autogrowth toutes les logs de % en Mo
$gvsqw_MsqBin/../tools/sqwmsq_AlterDatabaseModifyLogGrowth.ksh -I WINMSQ_INST1 -Exec
 
#From mssql@vmsqwarebox faire un SHRINK de toutes les logs
$gvsqw_MsqBin/../tools/sqwmsq_AlterDatabaseShrinkLogs.ksh -I WINMSQ_INST1 -Exec
</syntaxhighlight>
 
====Mise en exploitation====
Mise en place de la cron :
<syntaxhighlight lang="sh" line>
crontab -l > $HOME/CrontabRef
vi $HOME/CrontabRef_WINMSQ_INST1
cat $HOME/CrontabRef_WINMSQ_INST1 >> $HOME/CrontabRef
vi $HOME/CrontabRef
vi $HOME/CrontabRef
crontab $HOME/CrontabRef
crontab $HOME/CrontabRef
Line 269: Line 335:
</syntaxhighlight>
</syntaxhighlight>


Update the file CrontabRef  :
Mise à jour du fichier CrontabRef  :
<syntaxhighlight lang="sh" line>
<syntaxhighlight lang="sh" line>
crontab -l > $HOME/CrontabRef
crontab -l > $HOME/CrontabRef
Line 275: Line 341:
</syntaxhighlight>
</syntaxhighlight>


====Useful commands====
====Commandes utiles====
alias :
alias intéressants :
e DBALIAS => source env for the instance
e DBALIAS => source l'env pour l'instance
bin, etc, too ... => to go to the standard SQWareProduction tree
bin, etc, too ... => pour aller dans arbo SQWareProduction standard
cbin, cetc, ctoo ... => to go to the custom SQWareProduction tree
cbin, cetc, ctoo ... => pour aller dans arbo SQWareProduction custom
log => SQWareProduction logs
log => logs SQWareProduction
dmp => go to the backup paths


Some script options:
Quelques options des scripts :
-h => online help
-h => aide en ligne
-s => online examples
-s => exemples en ligne
-Exec => when present; if not set, only outputs commands without executing them.
-Exec => lorsque elle est présente, si non settée ne sort que les commandes sans les exécuter


Examples :
Exemples :
  mysql@my_mysql_host:$HOME/admin/MYS_INST_PRD/logs/DumpAllDatabases (MYS_DBA_PRD) $ bin
  mssql@HOSTCENTRAL:$HOME/admin/WINMSQ_INST1/logs/StatisticsDatabase (WINMSQ_INST1) $ bin
  total 100
  total 112
  drwxr-x---  2 dbsqware dba 4096 Sep 6 14:09 .
  drwxr-x---  2 dbsqware dba 4096 Sep 25 21:22 .
  drwxr-x--- 15 dbsqware dba  187 Aug 16 15:50 ..
  drwxr-x--- 15 dbsqware dba  4096 Sep 25 21:22 ..
  -rwxr-x---  1 dbsqware dba 2957 Aug 16 15:50 sqwmys_AnalyzeAllDatabases.ksh
  -rwxr-x---  1 dbsqware dba 10858 Sep 25 21:22 sqwmsq_BackupAllDatabases.ksh
  -rwxr-x---  1 dbsqware dba 2514 Aug 16 15:50 sqwmys_AnalyzeDatabase.ksh
  -rwxr-x---  1 dbsqware dba  6013 Sep 25 21:22 sqwmsq_BackupDatabase.ksh
  -rwxr-x---  1 dbsqware dba 2608 Aug 16 15:50 sqwmys_CheckAllDatabases.ksh
  -rwxr-x---  1 dbsqware dba  7663 Sep 25 21:22 sqwmsq_CheckdbAllDatabases.ksh
  -rwxr-x---  1 dbsqware dba 2257 Aug 16 15:50 sqwmys_CheckDatabase.ksh
  -rwxr-x---  1 dbsqware dba  4809 Sep 25 21:22 sqwmsq_CheckdbDatabase.ksh
  -rwxr-x---  1 dbsqware dba 5418 Aug 16 15:50 sqwmys_CopyDumpAllDatabases.ksh
  ...
-rwxr-x---  1 dbsqware dba 5324 Aug 16 15:50 sqwmys_CopyDumpDatabase.ksh
  -rwxr-x---  1 dbsqware dba 5610 Sep 6 10:45 sqwmys_CopyMariaBackup.ksh
-rwxr-x---  1 dbsqware dba 5594 Sep 6 14:08 sqwmys_CopyXtraBackup.ksh
-rwxr-x---  1 dbsqware dba 3248 Aug 16 15:50 sqwmys_DumpAllDatabases.ksh
-rwxr-x---  1 dbsqware dba 3541 Aug 16 15:50 sqwmys_DumpDatabase.ksh
lrwxrwxrwx  1 dbsqware dba  36 Jan  2  2022 sqwmys_ExecSQL.ksh -> ../../generic/bin/sqwgen_ExecSQL.ksh
-rwxr-x---  1 dbsqware dba 2455 Aug 16 15:50 sqwmys_GatherIndicators.ksh
-rwxr-x---  1 dbsqware dba 2454 Aug 16 15:50 sqwmys_GatherStructure.ksh
-rwxr-x---  1 dbsqware dba 3043 Aug 16 15:50 sqwmys_MariaBackup.ksh
lrwxrwxrwx  1 dbsqware dba  38 Jan  2  2022 sqwmys_NetBackup.ksh -> ../../generic/bin/sqwgen_NetBackup.ksh
-rwxr-x---  1 dbsqware dba 2959 Aug 16 15:50 sqwmys_OptimizeAllDatabases.ksh
-rwxr-x---  1 dbsqware dba 2522 Aug 16 15:50 sqwmys_OptimizeDatabase.ksh
lrwxrwxrwx  1 dbsqware dba  40 Jan  2  2022 sqwmys_ParallelRun.ksh -> ../../generic/bin/sqwgen_ParallelRun.ksh
-rwxr-x---  1 dbsqware dba 2252 Aug 16 15:50 sqwmys_PurgeAlert.ksh
-rwxr-x---  1 dbsqware dba 3855 Aug 16 15:50 sqwmys_RestoreAllDatabases.ksh
-rwxr-x---  1 dbsqware dba 3463 Aug 16 15:50 sqwmys_RestoreDatabase.ksh
-rwxr-x---  1 dbsqware dba 3825 Aug 16 15:50 sqwmys_RotateLogSlowQuery.ksh
lrwxrwxrwx  1 dbsqware dba  40 Jan  2  2022 sqwmys_RsyncBackup.ksh -> ../../generic/bin/sqwgen_RsyncBackup.ksh
  lrwxrwxrwx  1 dbsqware dba  35 Jan  2  2022 sqwmys_RunJob.ksh -> ../../generic/bin/sqwgen_RunJob.ksh
-rwxr-x---  1 dbsqware dba 3025 Aug 16 15:50 sqwmys_XtraBackup.ksh


  mysql@my_mysql_host:$HOME/SQWareProduction/mysql/bin (MYS_INST_PRD) $  
  mssql@HOSTCENTRAL:$HOME/SQWareProduction/mssql/bin (WINMSQ_INST1) $  
  ./sqwmys_DumpAllDatabases.ksh -h
  ./sqwmsq_StatisticsAllDatabases.ksh -h
   
   
  Sourcing sqwmys_Global.lib v2023.06 SQWareProduction for MySQL (dbSQWare) ...
  Sourcing sqwmsq_Global.lib v2021.02 SQWareProduction for MsSql ...
   
   
  Usage: sqwmys_DumpAllDatabases.ksh [-h] -I instance [+ options]
  Usage: sqwmsq_StatisticsAllDatabases.ksh [-h] -S|-I <FreeTdsAlias> [+ options]
   
   
  DESCRIPTION
  DESCRIPTION
     sqwmys_DumpAllDatabases.ksh dump databases in parallel
     sqwmsq_StatisticsAllDatabases.ksh update Statistics databases in //
  SUPPORT
  SUPPORT
     MySql  supported versions: 5.0 <= v <= 8
     MsSql supported versions: 2000 <= v <= 2019
    MariaDB supported versions: 5.5 <= v <= 11.6
   
   
  PARAMETERS
  PARAMETERS
       -I  instance      : Target instance to mysqldump.
       -S|-I  Instance    : Target instance (freeTds alias).
  OPTIONS
  OPTIONS
       -h help           : Display the full usage.
       -h   help         : Display the full usage.
       -s                : Display samples of usage.
       -s                : Display samples of usage.
       -P Nb threads    : Number of threads in parallel (by default 2).
       -P   Nb_threads    : Number of threads in parallel (by default 4).
      -RD directory      : Directory to write dump file (default /backups/mysql/$MYSQL_SID).
       -ID listdb       : Databases list to include.
       -ID listdb         : List of databases to be dumped (by default all).
       -ED listdb       : Databases list to exclude.
       -ED listdb         : List of databases to exclude from dump.
       -IL likeclause   : Like clause to generate databases list (example: 'db%').
       -IL likeclause     : Like clause to generate databases list (example: 'db%').
       -EL likeclause   : Like clause to exclude databases (example: 'nodb%').
       -EL likeclause     : Like clause to exclude databases (example: 'nodb%').
       -WCD whereclause   : Where clause to generate databases list.
      -HI Nb_Generations : Number of generations to keep (by default 2).
       -FRT return_code   : Force return code value on error.
       -WCD whereclause : Where clause to generate databases list.
       -AddMail email    : Email Address to add at 'xxx'.
      -AGR  Nb sec      : Nb of seconds between two runs (by default 1s).
      -AGE  Nb sec      : Nb of seconds between two checks of end (by default 10s).
       -FRT return_code : Force return code value on error.
      -Opt  option      : Additional options for mysqldump.
      -Dist              : For distant connection to database (change $gvsqw_ConnectString to $gvsqw_DistConnectString ).
       -AddMail email    : Email address to add at 'xxx'.
       -SendReport        : Send execution log report.
       -SendReport        : Send execution log report.
       -NoMail            : Deactivate sendmail on error xxx (by default, send on error).
       -PAR parfile      : Parfile file for databases list.
       -Locale  locale  : Force Locale for help display (fr,en).
      -AGR Nb_sec        : Nb of seconds between two run (by default 5s).
       -Consistent        : Lock for consistent mode (by default, no lock).
       -AGE Nb_sec        : Nb of seconds between two check of end (by default 5s).
       -NoMail            : Desactivate sendmail on error xxx (by default, send on error).
       -Exec              : Execute commands (default, display generated commands)
       -Exec              : Execute commands (default, display generated commands)


Enjoy !
Enjoy !

Revision as of 15:24, 5 December 2025

Generalties


Warning:
Before anything, don't go further if you don't have read the first section "dbSQWare Concepts " !.

In this chapter, we will consider that SQWareCentral has been installed on dbsqware@sqwarebox.

Limits of this section

This chapter only deals with adding a new instance to a base that is already configured and functional.
Use the portions that apply to your environment, and choose either the automatic or manual method as desired

General operating procedure for integrating a new Sql-Server instance

There is only the case of remote connection to handle. We make an SQL connection from mssql@sqwarebox via FreeTds (OpenSource TDS connection client).

Classic steps:

  • Setting up the environment
  • Manual tests
  • Deployment of the instance

You will see that these steps can be handled one by one or in batches!

Integration of an SQL-server instance

Setting up the environment

General

Explanation of "DbAlias" (the unique dbSQWare key)

The dbSQWare key must be unique and must match the entry configured in the freetds.conf file to connect to the instance. Generally, when there is no named instance, we use the name of the Windows host that holds the instance. When there is a named instance, we concatenate the name of the Windows host and the instance name, separated by an underscore (do not use a backslash, we are on Linux!)."
Examples :

  • WINMSQ => WINMSQ (status ON)
  • WINMSQ\INST1 => WINMSQ_INST1 (status ON)
Explanation of statuses

Classically, for SQL Server, the status is 'ON'
The 'OFF' status makes the instance disappear from the web view.
The 'NEW' status is used as an intermediate status between the beginning and the end of setting up a new instance.
All other statuses allow the instance to be displayed in the repository (especially 'KEEP'), but they will not be taken into account by the automatic processes."

Resume of statuses :

Status Description
ON locale under Unix (the most common)
KEEP temporary status, during maintenance for example or before complete deletion
NEW temporary status, during configuration
OFF visual removal of the instance (without deleting its configuration)
XXX not supported...

Instance declaration in SQWareRepository with SQWareWeb

We will declare the new instance from the SQWareWeb administration interface.
Admin dbSQWare


Declare the new instance with the status "NEW" (Add or Duplicate).
Ajout d'une instance Ajout par duplication d'une instance
Add a new instance by duplicate an other one.
Explanation of the fields :

Fields Description
Db Alias Unique key that identifies the instance in dbSQWare (no value for MySQL/MariaDB).
Dbms Name Type of SGBD
Virtual Host Virtual Host (same as Host if not clustered)

.

Host Name Hostname of the instance
User Name User associated with the instance
Port Listening port of the instance.
Comments A brief description of what the instance hosts
Status Instance status (see above for explanations).
Contact A contact if needed
Environnement Instance environment (PRD, PPR, REC, DEV, TST, ...)
Client Used only for filtering (enter a client name and/or department and/or service...)
GlobalHost Free field in which the hypervisor host is often entered, for example.
Custom1 Free field 1
Custom2 Free field 2
Regenerate the reference files of SQWareCentral.

Type the following command which will generate the reference files:

# From : dbsqware@sqwarebox
gen_all

Création de la connexion à l'instance SQL

Vous avez 2 solutions pour connecter dbSQWare à vos instances SQL SERVER :

  • la création d'un compte sql dans l'instance, il faut avoir activé la connexion mixte.
  • l'utilisation d'un compte de service (déclaré dans l'Active Directory).
Création d'un compte Sql-Serveur spécifique dbSQWare

/!\ Il faut autoriser l'accès SQL sur les instances si ce n'est pas le cas !
Exemple d'ordre de création :

USE [master]
GO
CREATE LOGIN [msq_dba] WITH PASSWORD=N'NePasMettreCePassword!', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
EXEC master..sp_addsrvrolemember @loginame = N'msq_dba', @rolename = N'sysadmin'
GO

'sysadmin' est obligatoire à cause notamment des commandes "DBCC".

Vous pouvez mettre le nom et le mot de passe que vous souhaitez !
Ce compte devra être déclaré sur le compte unix mssql@sqwarebox ...
Si une entrée spécifique est trouvée c'est elle sui est prise, si non, on prend l'entrée "DEFAULT".

mssql@sqwarebox:/home/mssql (NoSID) $ cat .passwd_mssql
DEFAULT;msq_dba;NePasMettreCePassword!
SPECIFIC_MSSQL;sa;sapass
Création d'une connexion avec un compte de service spécifique dbSQWare

Exemple d'ordre de création :

USE [master]
GO
CREATE LOGIN [domain\svc-dbsqware] FROM WINDOWS;
GO
EXEC master..sp_addsrvrolemember @loginame = N'domain\svc-dbsqware', @rolename = N'sysadmin'
GO

'sysadmin' est obligatoire à cause notamment des commandes "DBCC".

Ce compte devra être déclaré sur le compte unix mssql@sqwarebox ...
Si une entrée spécifique est trouvée c'est elle sui est prise, si non, on prend l'entrée "DEFAULT".

mssql@sqwarebox:/home/mssql (NoSID) $ cat .passwd_mssql
DEFAULT;domain\svc-dbsqware;MettreLePasswordDuCompte!
SPECIFIC_MSSQL;sa;sapass

Vérifier l'entrée dans freetds.conf

On vérifie que les informations dbalias, host et port se soient bien inscrite dans le fichier !

# Sur mssql@sqwarebox /applis/mssql/freetds/etc/freetds.conf
#Exemple
[WINMSQ_INST1]
	host = WINMSQ
	port = 1433

Test sendmail (non obligatoire)

/!\ Faire la première fois, inutile après car toujours la même machine !

# From : dbsqware@sqwarebox
menu_msq TestSendmail GenLstInstanceNew

Tests de connexion "manuels" à l'instance Sql-Serveur

Le but étant de tester la connexion automatique à l'instance Sql-Serveur.

# From : dbsqware@sqwarebox
menu_msq TestInstConnectionOnNoMail GenLstInstanceNew

Vérifiez que vous êtes connectés à la bonne instance (champ FullName).
Exemple:

############################################################################
TestType;InstanceParam;DbAlias;FullName;VersionMajInt;VersionPatch;ProductEdition;BackupPath
TestConnection;MSSQL_INST1;MSSQL_INST1;MSSQL\INST1;2008;10.50.1600.1;Developer;E:/BackupsMssql
############################################################################

Si la version de Windows Server est inférieure ou égale à Windows Server 2012, vous devez ajouter "tds version = 7.0" dans la colonne Custom 2 du référentiel. Cela permet de forcer l’utilisation d’une version de FreeTDS compatible avec le serveur

Mise en exploitation de l'instance

Génération de la configuration par défaut SQWareProduction

# From : dbsqware@sqwarebox
menu_msq GenDefConf_SQWareProduction GenLstInstanceNew

Mise à jour de SQWareRepository

Dans le repository dbSQWare via la console d’administration, mettre à jour le statut de la nouvelle instance Sql-Serveur (à NEW actuellement) avec la valeur ON.

Test de "reprise" des indicateurs

A ce moment là, vous pouvez tester la reprise des indicateurs manquants (en principe, uniquement les instances que vous venez d'intégrer !)

# From : dbsqware@sqwarebox
repind_msq

Exploitation (stats, backups, …)

Génération des conf SQWareProduction

Si vous avez suivi la procédure d’insertion de l’instance, cette partie est déjà fait par l’étape "menu_msq GenDefConf_SQWareProduction GenLstInstanceNew".
Vous pouvez vérifier avec le chapitre suivant.

Se connecter à la machine unix du point central avec le compte « mssql » et taper les commandes suivantes :

# From mssql@vmsqwarebox
#Entrez le nom de l’instance
too
./sqwmsq_GenerateCreateInstance.ksh -I WINMSQ_INST1

Vérifier que ce qui est proposé est bon et tapez « y » si c’est le cas.
A ce moment, vous avez généré les fichiers de configuration par défaut de SQWareProduction.

Explications

Les étapes précédentes ont créé certains fichiers par défaut. ($HOME/admin/WINMSQ_INST1/sqwConfig)

#Entrez le nom de l’instance
e WINMSQ_INST1
cfg
cat sqwmsq_Jobs.cfg
#############################################
#IndicDba: Gather DBAs indicators
IndicDba:$gvsqw_MsqBin/sqwmsq_GatherIndicators.ksh -I WINMSQ_INST1

#RotateErrorLog: Rotate error log
RotateErrorLog:$gvsqw_MsqBin/sqwmsq_RotateErrorLog.ksh -I WINMSQ_INST1 -Exec

#BackupAll: backup all databases
BackupAll:$gvsqw_MsqBin/sqwmsq_BackupAllDatabases.ksh -I WINMSQ_INST1 -Exec

#BackupAllRep: run failed backups from BackupAll
BackupAllRep:$gvsqw_MsqBin/sqwmsq_BackupAllDatabases.ksh -I WINMSQ_INST1 -REP -Exec

#StatisticsAll : update statistics tables for all databases
StatisticsAll:$gvsqw_MsqBin/sqwmsq_StatisticsAllDatabases.ksh -I WINMSQ_INST1 -Exec

#RebuildAll : Rebuild indexes tables for all databases
RebuildAll:$gvsqw_MsqBin/sqwmsq_RebuildIndexAllDatabases.ksh -I WINMSQ_INST1 -Exec

#RestoreParfile : restore list of databases content in parfile
RestoreParfile:$gvsqw_MsqBin/sqwmsq_RestoreAllDatabases.ksh -I WINMSQ_INST1 -PAR $Parfile -Exec

#CheckdbAll : DBCC CheckDB for all databases
CheckdbAll:$gvsqw_MsqBin/sqwmsq_CheckdbAllDatabases.ksh -I WINMSQ_INST1 -Exec

C’est un fichier de paramétrage qui est utilisé par le script sqwmsq_RunJob.ksh pour exécuter des actions.

Fichier pour une cron par défaut $HOME/CrontabRef_WINMSQ_INST1 :

## mm(0-59) hh(0-23) dd(1-31) MM(0-12) DAY(0-sunday, 1-monday, ...) command
## WINMSQ_INST1
# Backup all databases
00 22 * * 1-6  bash -c '. $HOME/.profile ;$gvsqw_MsqBin/sqwmsq_RunJob.ksh -I WINMSQ_INST1 -A BackupAll > $HOME/tmp/BackupAll_WINMSQ_INST1.log 2>&1'
# Rebuild all databases
30 07 * * 6  bash -c '. $HOME/.profile ;$gvsqw_MsqBin/sqwmsq_RunJob.ksh -I WINMSQ_INST1 -A RebuildAll > $HOME/tmp/RebuildAll_WINMSQ_INST1.log 2>&1'
# Stats all databases
00 07 * * 0  bash -c '. $HOME/.profile ;$gvsqw_MsqBin/sqwmsq_RunJob.ksh -I WINMSQ_INST1 -A StatisticsAll > $HOME/tmp/StatisticsAll_WINMSQ_INST1.log 2>&1'

Paramétrage du chemin des backups

Sur l’instance à gérer, voir le chemin des backups dans la clé de registre :

DECLARE  @v_regvalue varchar(256)
EXEC xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'BackupDirectory',  @v_regvalue OUTPUT
select 'lvsqw_BackupPath='+rtrim(@v_regvalue)+'='
go

Pour modifier le chemin, les scripts se basent sur la clé de registre :

EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'BackupDirectory', REG_SZ, N'E:\Backups_db'
go

Test avec backup de master :

#From mssql@vmsqwarebox
$gvsqw_MsqBin/sqwmsq_BackupDatabase.ksh -I WINMSQ_INST1 -D master -Type full -Exec

/!\ Faites attention pour cette partie, si vous n'êtes pas sûrs, ne faites rien :

#From mssql@vmsqwarebox pour passer toutes les databases en 'RECOVERY SIMPLE'
$gvsqw_MsqBin/../tools/sqwmsq_AlterDatabaseRecoverySimple.ksh -I WINMSQ_INST1 -Exec

#From mssql@vmsqwarebox pour modifier l'autogrowth toutes les logs de % en Mo
$gvsqw_MsqBin/../tools/sqwmsq_AlterDatabaseModifyLogGrowth.ksh -I WINMSQ_INST1 -Exec

#From mssql@vmsqwarebox faire un SHRINK de toutes les logs
$gvsqw_MsqBin/../tools/sqwmsq_AlterDatabaseShrinkLogs.ksh -I WINMSQ_INST1 -Exec

Mise en exploitation

Mise en place de la cron :

crontab -l > $HOME/CrontabRef
vi $HOME/CrontabRef_WINMSQ_INST1
cat $HOME/CrontabRef_WINMSQ_INST1 >> $HOME/CrontabRef
vi $HOME/CrontabRef
crontab $HOME/CrontabRef
crontab -l

Mise à jour du fichier CrontabRef  :

crontab -l > $HOME/CrontabRef
cat $HOME/CrontabRef

Commandes utiles

alias intéressants :

e DBALIAS => source l'env pour l'instance
bin, etc, too ... => pour aller dans arbo SQWareProduction standard
cbin, cetc, ctoo ... => pour aller dans arbo SQWareProduction custom
log => logs SQWareProduction

Quelques options des scripts :

-h => aide en ligne
-s => exemples en ligne
-Exec => lorsque elle est présente, si non settée ne sort que les commandes sans les exécuter

Exemples :

mssql@HOSTCENTRAL:$HOME/admin/WINMSQ_INST1/logs/StatisticsDatabase (WINMSQ_INST1) $ bin
total 112
drwxr-x---  2 dbsqware dba  4096 Sep 25 21:22 .
drwxr-x--- 15 dbsqware dba  4096 Sep 25 21:22 ..
-rwxr-x---  1 dbsqware dba 10858 Sep 25 21:22 sqwmsq_BackupAllDatabases.ksh
-rwxr-x---  1 dbsqware dba  6013 Sep 25 21:22 sqwmsq_BackupDatabase.ksh
-rwxr-x---  1 dbsqware dba  7663 Sep 25 21:22 sqwmsq_CheckdbAllDatabases.ksh
-rwxr-x---  1 dbsqware dba  4809 Sep 25 21:22 sqwmsq_CheckdbDatabase.ksh
...
mssql@HOSTCENTRAL:$HOME/SQWareProduction/mssql/bin (WINMSQ_INST1) $ 
./sqwmsq_StatisticsAllDatabases.ksh -h

Sourcing sqwmsq_Global.lib v2021.02 SQWareProduction for MsSql ...

Usage: sqwmsq_StatisticsAllDatabases.ksh [-h] -S|-I <FreeTdsAlias> [+ options]

DESCRIPTION
   sqwmsq_StatisticsAllDatabases.ksh update Statistics databases in //
SUPPORT
   MsSql supported versions: 2000 <= v <= 2019

PARAMETERS
     -S|-I  Instance    : Target instance (freeTds alias).
OPTIONS
     -h   help          : Display the full usage.
     -s                 : Display samples of usage.
     -P   Nb_threads    : Number of threads in parallel (by default 4).
     -ID  listdb        : Databases list to include.
     -ED  listdb        : Databases list to exclude.
     -IL  likeclause    : Like clause to generate databases list (example: 'db%').
     -EL  likeclause    : Like clause to exclude databases (example: 'nodb%').
     -WCD whereclause   : Where clause to generate databases list.
     -FRT return_code   : Force return code value on error.
     -AddMail email     : Email Address to add at 'xxx'.
     -SendReport        : Send execution log report.
     -PAR parfile       : Parfile file for databases list.
     -AGR Nb_sec        : Nb of seconds between two run (by default 5s).
     -AGE Nb_sec        : Nb of seconds between two check of end (by default 5s).
     -NoMail            : Desactivate sendmail on error xxx (by default, send on error).
     -Exec              : Execute commands (default, display generated commands)

Enjoy !