http://www.jouvinio.net/wiki/index.php?title=ViewVC_Strat%C3%A9gie_Backup&feed=atom&action=historyViewVC Stratégie Backup - Historique des versions2024-03-29T14:13:09ZHistorique pour cette page sur le wikiMediaWiki 1.26.4http://www.jouvinio.net/wiki/index.php?title=ViewVC_Strat%C3%A9gie_Backup&diff=15741&oldid=prevEtienne le 15 mai 2018 à 10:382018-05-15T10:38:12Z<p></p>
<p><b>Nouvelle page</b></p><div>L'application [[ViewVC]] utilise une base de données et des espaces de stockage, dont une sauvegarde est nécessaire. Cet article présente la mise en place d'une stratégie de backup, sous [[Ubuntu]], permettant de réaliser:<br />
* 1 sauvegarde quotidienne de la base de données.<br />
* Export des sauvegardes vers un serveur "externe" via FTP.<br />
* Conservation des trois dernières sauvegardes complètes, et des incrémentales.<br />
<br />
La synchronisation des sauvegardes s'effectue à l'aide de l'outil de backup [[Duplicity]]. Le fait d'externaliser les sauvegardes apporte une garantie supplémentaire. En effet, si le serveur venait à être en panne, les sauvegardes de [[ViewVC]] resteront disponibles.<br />
<br />
La base de données MySQL est sauvegardée à l'aide de l'outil [[AutoMySQLBackup]]. Pour cela, un compte de sauvegarde est utilisé pour accéder à la base de données en lecture seule.<br />
<br />
<br />
== [[File:Hand-icon.png|link=]] Votre avis ==<br />
{|<br />
|{{#w4grb_rate:}}<br />
|style="padding: 0 0 1em 30px;"|{{#TwitterFBLike:|}}<br />
|}<br />
<br />
<br />
== [[File:Viewer icon.png|link=]] Objectif ==<br />
L'[[ViewVC Installation|installation]] faite sous [[Ubuntu]] met en place différents répertoires / fichiers:<br />
* Répertoire <code>/var/opt/viewvc-*</code>: Contient les instances installées, ainsi que les extensions mises en place.<br />
* Lien <code>/var/opt/viewvc</code>: Lien vers l'instance utilisée.<br />
* Fichier <code>/etc/apache2/sites-available/default.conf</code>: Contient la déclaration de la [[ViewVC sous Apache|publication sous Apache]].<br />
* Lien <code>/etc/apache2/sites-enabled/000-default.conf</code>: Lien pour la prise en compte des configurations Apache.<br />
<br />
<br />
Sous [[Ubuntu]], il existe le répertoire <code>/var/backups</code>, utilisé par aptitude, dpkg, OpenLDAP ... Cependant, il ne sera pas utilisé dans le cadre de cet article, pour ne pas engendrer d'éventuels effets de bord.<br />
Tous les scripts et données seront stockés dans un nouveau répertoire <code>/var/opt/backups</code> (pour l'ensemble des stratégies) et plus particulièrement dans le répertoire <code>/var/opt/backups/viewvc</code> pour ViewVC.<br />
Concernant les logs, elles seront toutes placées dans le répertoire <code>/var/log/backups</code>.<br />
<div class="console"><br />
#sudo mkdir -p /var/opt/backups/viewvc<br />
#sudo chmod 740 /var/opt/backups/viewvc<br />
#sudo chown root:root /var/opt/backups/viewvc<br />
#sudo mkdir /var/log/backups<br />
</div><br />
<br />
<br />
== [[File:Icon-database-process.png|link=]] Sauvegardes ==<br />
La base de données est sauvegardées à l'aide de [[AutoMySQLBackup]]. Cette dernière application permet d'exécuter des exécutions après export, ce qui est utilisé pour déclencher la sauvegarde des exports, des installations, à l'aide de l'outil [[Duplicity]].<br />
=== [[File:Command-icon.png|link=]] Source ===<br />
La configuration <code>viewvc_automysqlbackup.conf</code> est mise en place, avec des sécurités autorisant uniquement le compte <code>root</code> à le modifier, dans le répertoire <code>/var/opt/backups/viewvc</code> avec le code suivant:<br />
{{Hidden begin|title=Source viewvc_automysqlbackup.conf|titlestyle = background:lightgrey;text-align:center;}}<br />
<syntaxhighlight lang="properties"><br />
#version=3.0_rc2<br />
# DONT'T REMOVE THE PREVIOUS VERSION LINE!<br />
#<br />
# Uncomment to change the default values (shown after =)<br />
# WARNING:<br />
# This is not true for UMASK, CONFIG_prebackup and CONFIG_postbackup!!!<br />
#<br />
# Default values are stored in the script itself. Declarations in<br />
# /etc/automysqlbackup/automysqlbackup.conf will overwrite them. The<br />
# declarations in here will supersede all other.<br />
<br />
# Edit $PATH if mysql and mysqldump are not located in /usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin<br />
#PATH=${PATH}:FULL_PATH_TO_YOUR_DIR_CONTAINING_MYSQL:FULL_PATH_TO_YOUR_DIR_CONTAINING_MYSQLDUMP<br />
<br />
# Basic Settings<br />
<br />
# Username to access the MySQL server e.g. dbuser<br />
CONFIG_mysql_dump_username='backup'<br />
<br />
# Password to access the MySQL server e.g. password<br />
CONFIG_mysql_dump_password='<BACKUP_PASSWORD>'<br />
<br />
# Host name (or IP address) of MySQL server e.g localhost<br />
CONFIG_mysql_dump_host='localhost'<br />
<br />
# "Friendly" host name of MySQL server to be used in email log<br />
# if unset or empty (default) will use CONFIG_mysql_dump_host instead<br />
#CONFIG_mysql_dump_host_friendly=''<br />
<br />
# Backup directory location e.g /backups<br />
CONFIG_backup_dir='/var/opt/backups/viewvc/db'<br />
<br />
# This is practically a moot point, since there is a fallback to the compression<br />
# functions without multicore support in the case that the multicore versions aren't<br />
# present in the system. Of course, if you have the latter installed, but don't want<br />
# to use them, just choose no here.<br />
# pigz -> gzip<br />
# pbzip2 -> bzip2<br />
CONFIG_multicore='yes'<br />
<br />
# Number of threads (= occupied cores) you want to use. You should - for the sake<br />
# of the stability of your system - not choose more than (#number of cores - 1).<br />
# Especially if the script is run in background by cron and the rest of your system<br />
# has already heavy load, setting this too high, might crash your system. Assuming<br />
# all systems have at least some sort of HyperThreading, the default is 2 threads.<br />
# If you wish to let pigz and pbzip2 autodetect or use their standards, set it to<br />
# 'auto'.<br />
CONFIG_multicore_threads=2<br />
<br />
# Databases to backup<br />
<br />
# List of databases for Daily/Weekly Backup e.g. ( 'DB1' 'DB2' 'DB3' ... )<br />
# set to (), i.e. empty, if you want to backup all databases<br />
CONFIG_db_names=( 'ViewVC' )<br />
# You can use<br />
#declare -a MDBNAMES=( "${DBNAMES[@]}" 'added entry1' 'added entry2' ... )<br />
# INSTEAD to copy the contents of $DBNAMES and add further entries (optional).<br />
<br />
# List of databases for Monthly Backups.<br />
# set to (), i.e. empty, if you want to backup all databases<br />
CONFIG_db_month_names=( 'ViewVC' )<br />
<br />
# List of DBNAMES to EXLUCDE if DBNAMES is empty, i.e. ().<br />
#CONFIG_db_exclude=( 'information_schema' )<br />
<br />
# List of tables to exclude, in the form db_name.table_name<br />
# You may use wildcards for the table names, i.e. 'mydb.a*' selects all tables starting with an 'a'.<br />
# However we only offer the wildcard '*', matching everything that could appear, which translates to the<br />
# '%' wildcard in mysql.<br />
#CONFIG_table_exclude=()<br />
<br />
<br />
# Advanced Settings<br />
<br />
# Rotation Settings<br />
<br />
# Which day do you want monthly backups? (01 to 31)<br />
# If the chosen day is greater than the last day of the month, it will be done<br />
# on the last day of the month.<br />
# Set to 0 to disable monthly backups.<br />
CONFIG_do_monthly="0"<br />
<br />
# Which day do you want weekly backups? (1 to 7 where 1 is Monday)<br />
# Set to 0 to disable weekly backups.<br />
CONFIG_do_weekly="0"<br />
<br />
# Set rotation of daily backups. VALUE*24hours<br />
# If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.<br />
CONFIG_rotation_daily=1<br />
<br />
# Set rotation for weekly backups. VALUE*24hours<br />
#CONFIG_rotation_weekly=35<br />
<br />
# Set rotation for monthly backups. VALUE*24hours<br />
#CONFIG_rotation_monthly=150<br />
<br />
<br />
# Server Connection Settings<br />
<br />
# Set the port for the mysql connection<br />
CONFIG_mysql_dump_port=3306<br />
<br />
# Compress communications between backup server and MySQL server?<br />
#CONFIG_mysql_dump_commcomp='no'<br />
<br />
# Use ssl encryption with mysqldump?<br />
#CONFIG_mysql_dump_usessl='yes'<br />
CONFIG_mysql_dump_usessl='no'<br />
<br />
# For connections to localhost. Sometimes the Unix socket file must be specified.<br />
#CONFIG_mysql_dump_socket=''<br />
<br />
# The maximum size of the buffer for client/server communication. e.g. 16MB (maximum is 1GB)<br />
#CONFIG_mysql_dump_max_allowed_packet=''<br />
<br />
# This option sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with<br />
# transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time<br />
# when BEGIN was issued without blocking any applications.<br />
#<br />
# When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For<br />
# example, any MyISAM or MEMORY tables dumped while using this option may still change state.<br />
#<br />
# While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and<br />
# binary log coordinates), no other connection should use the following statements: ALTER TABLE, CREATE TABLE,<br />
# DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of<br />
# them on a table to be dumped can cause the SELECT that is performed by mysqldump to retrieve the table<br />
# contents to obtain incorrect contents or fail.<br />
#CONFIG_mysql_dump_single_transaction='no'<br />
<br />
# http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html#option_mysqldump_master-data<br />
# --master-data[=value]<br />
# Use this option to dump a master replication server to produce a dump file that can be used to set up another<br />
# server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates<br />
# the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates<br />
# from which the slave should start replicating after you load the dump file into the slave.<br />
#<br />
# If the option value is 2, the CHANGE MASTER TO statement is written as an SQL comment, and thus is informative only;<br />
# it has no effect when the dump file is reloaded. If the option value is 1, the statement is not written as a comment<br />
# and takes effect when the dump file is reloaded. If no option value is specified, the default value is 1.<br />
#<br />
# This option requires the RELOAD privilege and the binary log must be enabled.<br />
#<br />
# The --master-data option automatically turns off --lock-tables. It also turns on --lock-all-tables, unless<br />
# --single-transaction also is specified, in which case, a global read lock is acquired only for a short time at the<br />
# beginning of the dump (see the description for --single-transaction). In all cases, any action on logs happens at<br />
# the exact moment of the dump.<br />
# ==================================================================================================================<br />
# possible values are 1 and 2, which correspond with the values from mysqldump<br />
# VARIABLE= , i.e. no value, turns it off (default)<br />
#<br />
#CONFIG_mysql_dump_master_data=<br />
<br />
# Included stored routines (procedures and functions) for the dumped databases in the output. Use of this option<br />
# requires the SELECT privilege for the mysql.proc table. The output generated by using --routines contains<br />
# CREATE PROCEDURE and CREATE FUNCTION statements to re-create the routines. However, these statements do not<br />
# include attributes such as the routine creation and modification timestamps. This means that when the routines<br />
# are reloaded, they will be created with the timestamps equal to the reload time.<br />
#<br />
# If you require routines to be re-created with their original timestamp attributes, do not use --routines. Instead,<br />
# dump and reload the contents of the mysql.proc table directly, using a MySQL account that has appropriate privileges<br />
# for the mysql database.<br />
#<br />
# This option was added in MySQL 5.0.13. Before that, stored routines are not dumped. Routine DEFINER values are not<br />
# dumped until MySQL 5.0.20. This means that before 5.0.20, when routines are reloaded, they will be created with the<br />
# definer set to the reloading user. If you require routines to be re-created with their original definer, dump and<br />
# load the contents of the mysql.proc table directly as described earlier.<br />
#<br />
CONFIG_mysql_dump_full_schema='no'<br />
<br />
# Backup status of table(s) in textfile. This is very helpful when restoring backups, since it gives an idea, what changed<br />
# in the meantime.<br />
CONFIG_mysql_dump_dbstatus='yes'<br />
<br />
# Backup dump settings<br />
<br />
# Include CREATE DATABASE in backup?<br />
CONFIG_mysql_dump_create_database='yes'<br />
<br />
# Separate backup directory and file for each DB? (yes or no)<br />
CONFIG_mysql_dump_use_separate_dirs='yes'<br />
<br />
# Choose Compression type. (gzip or bzip2)<br />
CONFIG_mysql_dump_compression='gzip'<br />
<br />
# Store an additional copy of the latest backup to a standard<br />
# location so it can be downloaded by third party scripts.<br />
#CONFIG_mysql_dump_latest='no'<br />
<br />
# Remove all date and time information from the filenames in the latest folder.<br />
# Runs, if activated, once after the backups are completed. Practically it just finds all files in the latest folder<br />
# and removes the date and time information from the filenames (if present).<br />
#CONFIG_mysql_dump_latest_clean_filenames='no'<br />
<br />
# Create differential backups. Master backups are created weekly at #$CONFIG_do_weekly weekday. Between master backups,<br />
# diff is used to create differential backups relative to the latest master backup. In the Manifest file, you find the<br />
# following structure<br />
# $filename md5sum $md5sum diff_id $diff_id rel_id $rel_id<br />
# where each field is separated by the tabular character '\t'. The entries with $ at the beginning mean the actual values,<br />
# while the others are just for readability. The diff_id is the id of the differential or master backup which is also in<br />
# the filename after the last _ and before the suffixes begin, i.e. .diff, .sql and extensions. It is used to relate<br />
# differential backups to master backups. The master backups have 0 as $rel_id and are thereby identifiable. Differential<br />
# backups have the id of the corresponding master backup as $rel_id.<br />
#<br />
# To ensure that master backups are kept long enough, the value of $CONFIG_rotation_daily is set to a minimum of 21 days.<br />
#<br />
CONFIG_mysql_dump_differential='no'<br />
<br />
<br />
# Notification setup<br />
<br />
# What would you like to be mailed to you?<br />
# - log : send only log file<br />
# - files : send log file and sql files as attachments (see docs)<br />
# - stdout : will simply output the log to the screen if run manually.<br />
# - quiet : Only send logs if an error occurs to the MAILADDR.<br />
#CONFIG_mailcontent='stdout'<br />
<br />
# Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])<br />
#CONFIG_mail_maxattsize=4000<br />
<br />
# Allow packing of files with tar and splitting it in pieces of CONFIG_mail_maxattsize.<br />
#CONFIG_mail_splitandtar='yes'<br />
<br />
# Use uuencode instead of mutt. WARNING: Not all email clients work well with uuencoded attachments.<br />
#CONFIG_mail_use_uuencoded_attachments='no'<br />
<br />
# Email Address to send mail to? (user@domain.com)<br />
#CONFIG_mail_address='root'<br />
<br />
<br />
# Encryption<br />
<br />
# Do you wish to encrypt your backups using openssl?<br />
CONFIG_encrypt='no'<br />
<br />
# Choose a password to encrypt the backups.<br />
#CONFIG_encrypt_password='password0123'<br />
<br />
# Other<br />
<br />
# Backup local files, i.e. maybe you would like to backup your my.cnf (mysql server configuration), etc.<br />
# These files will be tar'ed, depending on your compression option CONFIG_mysql_dump_compression compressed and<br />
# depending on the option CONFIG_encrypt encrypted.<br />
#<br />
# Note: This could also have been accomplished with CONFIG_prebackup or CONFIG_postbackup.<br />
#CONFIG_backup_local_files=()<br />
<br />
# Command to run before backups (uncomment to use)<br />
#CONFIG_prebackup="/etc/mysql-backup-pre"<br />
<br />
# Command run after backups (uncomment to use)<br />
CONFIG_postbackup="/var/opt/backups/viewvc/viewvc_backup.sh"<br />
<br />
# Uncomment to activate! This will give folders rwx------<br />
# and files rw------- permissions.<br />
umask 0077<br />
<br />
# dry-run, i.e. show what you are gonna do without actually doing it<br />
# inactive: =0 or commented out<br />
# active: uncommented AND =1<br />
#CONFIG_dryrun=1<br />
</syntaxhighlight><br />
{{Hidden end}}<br />
<br />
Le fichier est créé avec un droit de modification et exécution uniquement pour le compte <code>root</code>:<br />
<div class="console"><br />
#sudo chmod 640 /var/opt/backups/viewvc/viewvc_automysqlbackup.conf<br />
#sudo chown root:root /var/opt/backups/viewvc/viewvc_automysqlbackup.conf<br />
</div><br />
<br />
Les paramètres mis en place sont:<br />
{| class="wikitable"<br />
! Paramètre !! Valeur<br />
|- <br />
|CONFIG_mysql_dump_username<br />
|backup<br />
|- <br />
|CONFIG_mysql_dump_password<br />
|Mot de passe du compte backup.<br />
|- <br />
|CONFIG_mysql_dump_host<br />
|localhost<br />
L'utilitaire est installé sur la même machine que MySQL.<br />
|- <br />
|CONFIG_backup_dir<br />
|/var/opt/backups/viewvc/db<br />
Ce répertoire est à créer.<br />
|- <br />
|CONFIG_multicore<br />
|yes<br />
|- <br />
|CONFIG_multicore_threads<br />
|2<br />
La machine est un bi-processeur avec deux coeurs.<br />
|- <br />
|CONFIG_db_names<br />
|( 'ViewVC' )<br />
Seule la base ViewVC est gérée dans cette configuration.<br />
|- <br />
|CONFIG_do_monthly<br />
|0<br />
Les sauvegardes mensuelles ne sont pas souhaitées dans le cadre de cette utilisation.<br />
|- <br />
|CONFIG_do_weekly<br />
|0<br />
Les sauvegardes hebdomadaires ne sont pas souhaitées dans le cadre de cette utilisation.<br />
|- <br />
|CONFIG_rotation_daily<br />
|1<br />
Seule la sauvegarde du jour est conservée.<br />
En effet, l'installation faite n'est pas critique et comme les différentiels peuvent être gérés par Duplicity, il sera possible de restaurer des anciennes sauvegardes.<br />
|- <br />
|CONFIG_mysql_dump_port<br />
|3306<br />
|- <br />
|CONFIG_mysql_dump_usessl<br />
|no<br />
Par défaut la valeur est <code>yes</code>, mais cela entraîne une erreur suite à une [[#Update|mise à jour]].<br />
|- <br />
|CONFIG_mysql_dump_full_schema<br />
|no<br />
|- <br />
|CONFIG_mysql_dump_dbstatus<br />
|yes<br />
|- <br />
|CONFIG_mysql_dump_create_database<br />
|yes<br />
Ce qui permet d'avoir les scripts de création de la abse.<br />
|- <br />
|CONFIG_mysql_dump_use_separate_dirs<br />
|yes<br />
|- <br />
|CONFIG_mysql_dump_compression<br />
|gzip<br />
Les sauvegardes seront compressées ainsi.<br />
|- <br />
|CONFIG_mysql_dump_differential<br />
|no<br />
Les sauvegardes sont complêtes à chaque fois.<br />
|- <br />
|CONFIG_postbackup<br />
|/var/opt/backups/viewvc/viewvc_backup.sh<br />
Ce script sera déclenché à la fin de la sauvegarde, permettant de planifier la synchronisation à partir de Duplicity.<br />
|- <br />
|umask<br />
|0077<br />
Seul le compte root aura accès aux sauvegardes.<br />
|}<br />
<br />
Le répertoire <code>/var/opt/backups/viewvc/db</code> doit être créé.<br />
<div class="console"><br />
#sudo mkdir /var/opt/backups/viewvc/db<br />
#sudo chown root:root /var/opt/backups/viewvc/db<br />
#sudo chmod 750 /var/opt/backups/viewvc/db<br />
</div><br />
<br />
Le script <code>viewvc_backup.sh</code> est mis en place, avec des sécurités autorisant uniquement le compte <code>root</code> à le modifier, dans le répertoire <code>/var/opt/backups/viewvc</code> avec le code suivant:<br />
{{Hidden begin|title=Source viewvc_backup.sh|titlestyle = background:lightgrey;text-align:center;}}<br />
<syntaxhighlight lang="bash"><br />
#!/bin/bash<br />
dateLogFormat="+%Y-%m-%d %H:%M";<br />
# Backup log<br />
pathLog="/var/log/backups/view_backup.log";<br />
<br />
echo "[$(date "$dateLogFormat")] Start backup" >> $pathLog;<br />
echo "[$(date "$dateLogFormat")] Start upload with duplicity" >> $pathLog;<br />
<br />
export PASSPHRASE="DUPLICITY PASSPHRASE"<br />
export FTP_PASSWORD=USER_PASSWORD<br />
<br />
duplicity remove-all-but-n-full 3 --force ftp://FTP_LOGIN@HOST/backup/viewvc >> $pathLog;<br />
duplicity --include '/var/opt/viewvc-*' --include '/var/opt/viewvc' --include '/var/opt/backups/viewvc/db'<br />
--include '/etc/apache2/sites-available/default.conf' --include '/etc/apache2/sites-enabled/000-default.conf' --exclude '**'<br />
--full-if-older-than 7D / ftp://FTP_LOGIN@HOST/backup/viewvc >> $pathLog;<br />
<br />
unset PASSPHRASE<br />
unset FTP_PASSWORD<br />
<br />
echo "[$(date "$dateLogFormat")] End upload with duplicity" >> $pathLog;<br />
echo "[$(date "$dateLogFormat")] End backup" >> $pathLog;<br />
</syntaxhighlight><br />
{{Hidden end}}<br />
<br />
'''Attention''' à l'utilisation de l'instruction <code>export</code>, surtout pour la PASSPHRASE. En effet, si celle-ci contient des espaces, il est impératif de la placer entre le caractère <code>"</code>.<br />
<br />
Il n'est pas nécessaire de positionne le droit d'exécution sur ce fichier.<br />
<div class="console"><br />
#sudo chmod 640 /var/opt/backups/viewvc/viewvc_backup.sh<br />
#sudo chown root:root /var/opt/backups/viewvc/viewvc_backup.sh<br />
</div><br />
<br />
Le fonctionnement de ce script est assez simple. Puis deux variables d'environnement sont mises en place:<br />
* PASSPHRASE: Phrase pour le cryptage des données par duplicity.<br />
* FTP_PASSWORD: Le mot de passe FTP utilisé pour se connecté via duplicity.<br />
<br />
La première instruction, avec l'argument <code>remove-all-but-n-full 3</code>, va conserver les trois dernières sauvegardes complètes. Puis la seconde instruction, avec l'argument <code>--full-if-older-than 7D</code> effectue une sauvegarde incrémentale uniquement si la précédente complète est plus ancienne de sept jours.<br />
<br />
Le résultat de l'export est ensuite envoyé sur un serveur FTP, configuré par la value <code>HOST</code>, en utilisant le login <code>FTP_LOGIN</code> et le mot de passe <code>USER_PASSWORD</code> placé dans la variable <code>FTP_PASSWORD</code>. Les sauvegardes sont stockées à l'emplacement <code>backup/viewvc</code> à la racine du compte après connexion sur FTP.<br />
<br />
Enfin, les exécutions sont tracées dans la log <code>/var/log/backups/viewvc_backup.log</code>.<br />
<br />
Afin de faciliter le déploiement de cette exécution sous crontab, un deuxième script est mis en place afin d'exécuter [[AutoMySQLBackup]] avec le fichier de configuration. Le script <code>viewvc_automysqlbackup.sh</code> est mis en place, avec des sécurités autorisant uniquement le compte <code>root</code> à le modifier, dans le répertoire <code>/var/opt/backups/viewvc</code> avec le code suivant:<br />
{{Hidden begin|title=Source viewvc_automysqlbackup.sh|titlestyle = background:lightgrey;text-align:center;}}<br />
<syntaxhighlight lang="bash"><br />
#!/bin/bash<br />
/var/opt/automysqlbackup/automysqlbackup /var/opt/backups/viewvc/viewvc_automysqlbackup.conf >> /var/log/backup/viewvc_backup_db.log<br />
</syntaxhighlight><br />
{{Hidden end}}<br />
<br />
Le script est créé avec un droit de modification et exécution uniquement pour le compte <code>root</code>:<br />
<div class="console"><br />
#sudo chmod 750 /var/opt/backups/viewvc/viewvc_automysqlbackup.sh<br />
#sudo chown root:root /var/opt/backups/viewvc/viewvc_automysqlbackup.sh<br />
</div><br />
<br />
Les messages d'exécution de [[AutoMySQLBackup]] sont redirigés vers la log <code>/var/log/viewvc_backup_db.log</code>.<br />
<br />
=== [[File:Examples-icon.png|link=]] Exemples ===<br />
Le script n'accepte aucun argument. L'exécution s'effectue simplement par la ligne suivante:<br />
<div class="console"><br />
#./viewvc_automysqlbackup.sh<br />
</div><br />
<br />
<br />
== [[File:Scheduled-Tasks-icon.png|link=]] Planification ==<br />
Une fois que le script de sauvegarde est mis en place, il est possible de l'exécuter manuellement. Mais l'objectif est de l'exécuter automatiquement et régulièrement sans s'en préoccuper. Dans le cadre de cette implémentation, la planification est réalisée à l'aide de l'outil [[Crontab]] disponible sur les systèmes Linux. L'outil [[Anacron]] n'a pas été utilisé car les planifications souhaitées doivent se faire à des heures et des jours particuliers.<br />
<br />
La mise en place s'effectue en modifiant le fichier <code>/etc/crontab</code> pour y ajouter une ligne.<br />
<syntaxhighlight lang="text" highlight="15"><br />
# /etc/crontab: system-wide crontab<br />
# Unlike any other crontab you don't have to run the `crontab'<br />
# command to install the new version when you edit this file<br />
# and files in /etc/cron.d. These files also have username fields,<br />
# that none of the other crontabs do.<br />
<br />
SHELL=/bin/sh<br />
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br />
<br />
# m h dom mon dow user command<br />
17 * * * * root cd / && run-parts --report /etc/cron.hourly<br />
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )<br />
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )<br />
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )<br />
50 5 * * * root cd / && /var/opt/backups/viewvc/viewvc_automysqlbackup.sh<br />
#<br />
</syntaxhighlight><br />
<br />
Les sauvegardes sont planifiées à 5h50 AM, tous les jours de la semaine, par l'exécution de la commande <code>cd / && /var/opt/backups/viewvc/viewvc_automysqlbackup.sh</code>.<br />
<br />
<br />
== [[File:Icon-log.png|link=]] Gestions des logs ==<br />
Des fichiers de log sont créés par le script mis en place. Comme pour l'ensemble des produits, une rotation de ces logs est mise en place, à l'aide de l'outil [[Logrotate]]. <br />
L'ensemble des logs se trouvent donc dans le répertoire <code>/var/log/backups</code> avec les noms <code>viewvc_backup_db.log</code> et <code>viewvc_backup.log</code>. La configuration permet une rotation hebdomadaire, en conservant 3 rotations. Les rotations sont compressées, en asynchrone, et créées avec un accès en modification au compte root.<br />
<br />
Cette configuration est mise en place dans le fichier <code>viewvc_backup</code>, sous le répertoire <code>/etc/logrotate.d</code><br />
<syntaxhighlight lang="text"><br />
/var/log/backups/viewvc*.log {<br />
weekly<br />
missingok<br />
rotate 3<br />
compress<br />
delaycompress<br />
notifempty<br />
create 640 root root<br />
}<br />
</syntaxhighlight><br />
<br />
<br />
== [[File:Update icon.png|link=]] Update ==<br />
Suite à la montée de version de [[Ubuntu Update Version 16.04 LTS|Ubuntu 16.04]], le serveur [[MySql]] a été mis à jour. La configuration de [[AutoMySQLBackup]] mise en place provoquait alors une erreur, mentionnée dans la trace d'exécution.<br />
<div class="console"><br />
mysqldump: Got error: 2026: SSL connection error: SSL is required but the server doesn't support it when trying to connect<br />
</div><br />
<br />
Et la base de données n'était pas exportée par la commande <code>mysqldump</code>.<br />
<br />
Par défaut, [[AutoMySQLBackup]] est configuré pour exécuter la commande <code>mysqldup</code> en SSL, paramètre <code>CONFIG_mysql_dump_usessl</code>. Jusqu'à cette mise à jour, cela ne semblait pas être problématique. Dans le cadre de cette installation, il est donc nécessaire de désactiver l'utilisation de SSL en spécifiant la valeur <code>no</code> pour le paramètre.<br />
<syntaxhighlight lang="text" highlight="2-3"><br />
# Use ssl encryption with mysqldump?<br />
#CONFIG_mysql_dump_usessl='yes'<br />
CONFIG_mysql_dump_usessl='no'<br />
</syntaxhighlight><br />
<br />
<br />
[[Category:AutoMySQLBackup]] [[Category:Backup]] [[Category:Duplicity]] [[Category:ViewVC Administration]]</div>Etienne