<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>William&#039;s Blog &#187; Sysadmin</title> <atom:link href="http://www.willdurand.fr/tag/sysadmin/feed/" rel="self" type="application/rss+xml" /><link>http://www.willdurand.fr</link> <description>Développeur web indépendant, étudiant et passionné ! #Symfony2 #Rails #Diem #Git #Nginx #WebPerfs #SoftwareQuality</description> <lastBuildDate>Thu, 20 Oct 2011 14:59:05 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Sauvegarde incrémentale avec rsync : fichiers et base de données MySQL</title><link>http://www.willdurand.fr/sauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql</link> <comments>http://www.willdurand.fr/sauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql/#comments</comments> <pubDate>Wed, 07 Jul 2010 12:24:14 +0000</pubDate> <dc:creator>Will</dc:creator> <category><![CDATA[Serveur]]></category> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[Dedibox]]></category> <category><![CDATA[Rsync]]></category> <category><![CDATA[Script]]></category><guid
isPermaLink="false">http://www.willdurand.fr/?p=487</guid> <description><![CDATA[Bonjour, suite à mon passage en dédié (Dédibox v3) et à sa configuration aujourd&#8217;hui terminée, j&#8217;ai trouvé nécessaire de m&#8217;occuper de la sauvegarde des données. Pour cela, je me suis aidé de plusieurs sources : http://www.ruas-blog.com/index.php/2006/03/06/33-script-de-sauvegarde-des-bases-mysql (pour backuper MySQL) http://www.casafire.com/fr/content/sauvegarde-incrémentale-de-fichiers-avec-rsync-et-ssh (pour backuper les fichiers) http://blog.mazenod.fr/2007/10/sauvegarde-cryptee-de-serveur-a-serveur/ (pour me rappeler les commandes d&#8217;usage) Sauvegarde des bases MySQL [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">Bonjour, suite à mon passage en dédié (Dédibox v3) et à sa configuration aujourd&#8217;hui terminée, j&#8217;ai trouvé nécessaire de m&#8217;occuper de la sauvegarde des données. Pour cela, je me suis aidé de plusieurs sources :</p><ul><li><a
href="http://www.ruas-blog.com/index.php/2006/03/06/33-script-de-sauvegarde-des-bases-mysql">http://www.ruas-blog.com/index.php/2006/03/06/33-script-de-sauvegarde-des-bases-mysql</a> (pour backuper MySQL)</li><li><a
href="http://www.casafire.com/fr/content/sauvegarde-incr%C3%A9mentale-de-fichiers-avec-rsync-et-ssh">http://www.casafire.com/fr/content/sauvegarde-incrémentale-de-fichiers-avec-rsync-et-ssh</a> (pour backuper les fichiers)</li><li><a
href="http://blog.mazenod.fr/2007/10/sauvegarde-cryptee-de-serveur-a-serveur/">http://blog.mazenod.fr/2007/10/sauvegarde-cryptee-de-serveur-a-serveur/</a> (pour me rappeler les commandes d&#8217;usage)</li></ul><h2>Sauvegarde des bases MySQL</h2><p
style="text-align: justify;">Je sauvegarde toutes les bases de données sur une <strong>durée d&#8217;une semaine</strong>. Voici le script, il est possible de le coupler à un envoi de la sauvegarde via FTP. Je conserve ainsi toutes mes sauvegardes sur un serveur distant et complètement déconnecté de ce dont je vais vous parler ensuite.</p><div
class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;">#!/bin/bash</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;">#---------------------------------------------------------------#</span><br
/> <span
style="color: #666666; font-style: italic;"># Paramétrage de la connection MySQL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span><br
/> <span
style="color: #666666; font-style: italic;">#---------------------------------------------------------------#</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;">#Nom de l'utilisateur qui lance le backup</span><br
/> <span
style="color: #007800;">user</span>=<span
style="color: #000000; font-weight: bold;">&lt;</span>user<span
style="color: #000000; font-weight: bold;">&gt;</span><br
/> <span
style="color: #666666; font-style: italic;">#Machine sur laquelle on se connecte</span><br
/> <span
style="color: #007800;">host</span>=<span
style="color: #000000; font-weight: bold;">&lt;</span>host<span
style="color: #000000; font-weight: bold;">&gt;</span><br
/> <span
style="color: #666666; font-style: italic;">#Mot de passe de l'utilisateur de backup</span><br
/> <span
style="color: #007800;">pass</span>=<span
style="color: #000000; font-weight: bold;">&lt;</span>password<span
style="color: #000000; font-weight: bold;">&gt;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Outil de dump</span><br
/> <span
style="color: #007800;">MYSQLDUMP</span>=mysqldump<br
/> <span
style="color: #666666; font-style: italic;">#Outil de check</span><br
/> <span
style="color: #007800;">MYSQLCHECK</span>=mysqlcheck<br
/> <span
style="color: #666666; font-style: italic;"># Options passées à MYSQLDUMP</span><br
/> <span
style="color: #007800;">OPTIONS</span>=<span
style="color: #ff0000;">&quot;--add-drop-database &nbsp;--add-drop-table --complete-insert --routines --triggers --max_allowed_packet=250M --force&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;">#---------------------------------------------------------------#</span><br
/> <span
style="color: #666666; font-style: italic;"># Paramétrage de la sauvegarde &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span><br
/> <span
style="color: #666666; font-style: italic;">#---------------------------------------------------------------#</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Répertoire temporaire pour stocker les backups</span><br
/> <span
style="color: #007800;">TEMPORAIRE</span>=<span
style="color: #ff0000;">&quot;/tmp/bkp_mysql&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Nom du serveur</span><br
/> <span
style="color: #007800;">MACHINE</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(hostname)</span>&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Date courante</span><br
/> <span
style="color: #007800;">DATE</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(date +&quot;%d-%m-%Y&quot;)</span>&quot;</span><br
/> <span
style="color: #666666; font-style: italic;"># Date de conservation maximum</span><br
/> <span
style="color: #007800;">DATE2</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">date</span> <span
style="color: #660033;">--date</span> <span
style="color: #ff0000;">'1 week ago'</span> <span
style="color: #ff0000;">&quot;+%d-%m-%Y&quot;</span><span
style="color: #000000; font-weight: bold;">`</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Nom des fichiers de backup</span><br
/> <span
style="color: #666666; font-style: italic;"># Répertoire de destination du backup</span><br
/> <span
style="color: #007800;">DESTINATION</span>=<span
style="color: #ff0000;">&quot;/home/backuper/mysql&quot;</span><br
/> <span
style="color: #007800;">FICHIER_BACKUP</span>=<span
style="color: #007800;">$MACHINE</span><span
style="color: #ff0000;">&quot;_BACKUP_MYSQL_&quot;</span><span
style="color: #007800;">$DATE</span><span
style="color: #ff0000;">&quot;.tar.gz&quot;</span><br
/> <span
style="color: #007800;">FICHIER_EFFACER</span>=<span
style="color: #007800;">$MACHINE</span><span
style="color: #ff0000;">&quot;_BACKUP_MYSQL_&quot;</span><span
style="color: #007800;">$DATE2</span><span
style="color: #ff0000;">&quot;.tar.gz&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;">#Informations FTP</span><br
/> <span
style="color: #007800;">LOGIN_FTP</span>=<span
style="color: #000000; font-weight: bold;">&lt;</span>user_ftp<span
style="color: #000000; font-weight: bold;">&gt;</span><br
/> <span
style="color: #007800;">PASS_FTP</span>=<span
style="color: #000000; font-weight: bold;">&lt;</span>pass_ftp<span
style="color: #000000; font-weight: bold;">&gt;</span><br
/> <span
style="color: #007800;">HOST_FTP</span>=<span
style="color: #000000; font-weight: bold;">&lt;</span>host_ftp<span
style="color: #000000; font-weight: bold;">&gt;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;">#---------------------------------------------------------------#</span><br
/> <span
style="color: #666666; font-style: italic;"># Process de sauvegarde &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br
/> <span
style="color: #666666; font-style: italic;">#---------------------------------------------------------------#</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Création du répertoire temporaire</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-d</span> <span
style="color: #007800;">$TEMPORAIRE</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span>;<br
/> <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Le repertoire temporaire existe.&quot;</span>;<br
/> <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; <span
style="color: #c20cb9; font-weight: bold;">mkdir</span> <span
style="color: #007800;">$TEMPORAIRE</span>;<br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># On construit la liste des bases de données</span><br
/> <span
style="color: #007800;">BASES</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(mysql -u $user -h $host -p$pass -Bse 'show databases')</span>&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># On lance le dump des bases</span><br
/> <span
style="color: #000000; font-weight: bold;">for</span> db <span
style="color: #000000; font-weight: bold;">in</span> <span
style="color: #007800;">$BASES</span><br
/> <span
style="color: #000000; font-weight: bold;">do</span><br
/> &nbsp; <span
style="color: #666666; font-style: italic;">#On lance un check et une analyse pour chaque base de données</span><br
/> &nbsp; <span
style="color: #007800;">$MYSQLCHECK</span> <span
style="color: #660033;">-u</span> <span
style="color: #007800;">$user</span> <span
style="color: #660033;">-h</span> <span
style="color: #007800;">$host</span> -p<span
style="color: #007800;">$pass</span> <span
style="color: #660033;">-c</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$db</span><br
/> &nbsp; <span
style="color: #666666; font-style: italic;"># On lance un mysqldump pour chaque base de données</span><br
/> &nbsp; <span
style="color: #007800;">$MYSQLDUMP</span> <span
style="color: #660033;">-u</span> <span
style="color: #007800;">$user</span> <span
style="color: #660033;">-h</span> <span
style="color: #007800;">$host</span> -p<span
style="color: #007800;">$pass</span> <span
style="color: #007800;">$OPTIONS</span> <span
style="color: #007800;">$db</span> <span
style="color: #660033;">-R</span> <span
style="color: #000000; font-weight: bold;">&gt;</span> <span
style="color: #007800;">$TEMPORAIRE</span><span
style="color: #ff0000;">&quot;/&quot;</span><span
style="color: #007800;">$MACHINE</span><span
style="color: #ff0000;">&quot;-&quot;</span><span
style="color: #007800;">$db</span><span
style="color: #ff0000;">&quot;-&quot;</span><span
style="color: #007800;">$DATE</span><span
style="color: #ff0000;">&quot;.sql&quot;</span>;<br
/> <span
style="color: #000000; font-weight: bold;">done</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Création de l'archive contenant tout les dump</span><br
/> <span
style="color: #666666; font-style: italic;">#Cette archive est stockée dans le dossier défini pour la sauvegarde</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-d</span> <span
style="color: #007800;">$DESTINATION</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <br
/> <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">cd</span> <span
style="color: #007800;">$TEMPORAIRE</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">tar</span> <span
style="color: #660033;">-cvzf</span> <span
style="color: #007800;">$DESTINATION</span><span
style="color: #ff0000;">&quot;/&quot;</span><span
style="color: #007800;">$FICHIER_BACKUP</span> <span
style="color: #000000; font-weight: bold;">*</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># On transfere l'archive par FTP</span><br
/> <span
style="color: #7a0874; font-weight: bold;">cd</span> <span
style="color: #007800;">$DESTINATION</span><br
/> <span
style="color: #c20cb9; font-weight: bold;">ftp</span> <span
style="color: #660033;">-v</span> <span
style="color: #660033;">-n</span> <span
style="color: #007800;">$HOST_FTP</span> <span
style="color: #000000; font-weight: bold;">&lt;</span> <span
style="color: #000000; font-weight: bold;">&lt;</span>SCRIPT<br
/> user <span
style="color: #007800;">$LOGIN_FTP</span> <span
style="color: #007800;">$PASS_FTP</span> <br
/> bin <br
/> put <span
style="color: #007800;">$FICHIER_BACKUP</span> <br
/> bye<br
/> SCRIPT<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># On supprime le fichier de plus de x jours</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-f</span> <span
style="color: #007800;">$DESTINATION</span><span
style="color: #ff0000;">&quot;/&quot;</span><span
style="color: #007800;">$FICHIER_EFFACER</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">rm</span> <span
style="color: #007800;">$DESTINATION</span><span
style="color: #ff0000;">&quot;/&quot;</span><span
style="color: #007800;">$FICHIER_EFFACER</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># On suprime le répertoire temporaire</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-d</span> fichier <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; <span
style="color: #c20cb9; font-weight: bold;">rm</span> <span
style="color: #660033;">-Rf</span> <span
style="color: #007800;">$TEMPORAIRE</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span></div></div><h2></h2><h2>Sauvegarde incrémentale des fichiers avec rsync</h2><p
style="text-align: justify;">Je sauvegarde mes fichiers à la semaine de la façon suivante :</p><ul
style="text-align: justify;"><li>sauvegarde dans un répertoire nommé : <em>&lt;Année&gt;-&lt;Numéro de semaine&gt;</em></li><li>dans ce répertoire j&#8217;ai un dossier main qui contient l&#8217;intégralité des fichiers. Cette sauvegarde est faite le lundi.</li><li>j&#8217;ai 6 répertoires nommés : <em>&lt;jour&gt;_&lt;date au format jj-mm-aaaa&gt;</em> contenant les sauvegardes incrémentales de la semaine.</li></ul><p
style="text-align: justify;">J&#8217;ai modifié le script pour ajouter une conservation des <strong>sauvegardes de 4 semaines</strong>.</p><div
class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;">#!/bin/bash</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># - By default, the full backup is made monday, you can specify another day</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp; by entering a number from 1 to 7 (1 is monday, 2 is tuesday ...) </span><br
/> <span
style="color: #666666; font-style: italic;">#FULL_DAY=1</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># - BACKUP_LIST is a text file where you specify files/directories you </span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp; want to backup (one per line), the paths on this file must be relative </span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp; to the path set in BACKUP_ROOT</span><br
/> <span
style="color: #007800;">BACKUP_ROOT</span>=<span
style="color: #000000; font-weight: bold;">/</span><br
/> <span
style="color: #007800;">BACKUP_LIST</span>=<span
style="color: #ff0000;">&quot;/home/backuper/scripts/backup_list_files&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Excludes file</span><br
/> <span
style="color: #666666; font-style: italic;"># - Contains one wildcard pattern per line of files to exclude</span><br
/> <span
style="color: #666666; font-style: italic;"># - This is a rsync exclude file. See the rsync man page. &nbsp;</span><br
/> <span
style="color: #007800;">EXCLUDES_LIST</span>=<span
style="color: #ff0000;">&quot;/home/backuper/scripts/backup_exclude_files&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Hostname or IP adress of the remote backup server</span><br
/> <span
style="color: #007800;">BACKUP_SRV</span>=<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Port SSH</span><br
/> <span
style="color: #007800;">SSH_PORT</span>=<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Root directory that stores backups on the remote server</span><br
/> <span
style="color: #007800;">ARCHIVE_ROOT</span>=~<span
style="color: #000000; font-weight: bold;">/</span>files<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Remote user. Used by ssh. This is the user who connects to the remote backup server </span><br
/> <span
style="color: #666666; font-style: italic;"># Must have write access on $ARCHIVE_ROOT</span><br
/> <span
style="color: #007800;">REMOTE_USER</span>=<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Mail address for status updates</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;- This is used to email you a status report</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;- Comment it if you don't want to mail the report</span><br
/> <span
style="color: #007800;">MAILADDR</span>=<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Log file</span><br
/> <span
style="color: #007800;">LOGFILE</span>=<span
style="color: #ff0000;">&quot;/home/backuper/backup-files.log&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># HOSTNAME</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;This is used for creating a directory specific to this host on the remote host</span><br
/> <span
style="color: #007800;">HOSTNAME</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(hostname)</span>&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;">#########################################</span><br
/> <span
style="color: #666666; font-style: italic;"># From here on out, you probably don't &nbsp;#</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp; want to change anything unless you &nbsp;#</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp; know what you're doing. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br
/> <span
style="color: #666666; font-style: italic;">#########################################</span><br
/> <br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-f</span> <span
style="color: #007800;">$LOGFILE</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span><br
/> <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; <span
style="color: #c20cb9; font-weight: bold;">rm</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; <span
style="color: #c20cb9; font-weight: bold;">touch</span> <span
style="color: #007800;">$LOGFILE</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Calculate WEEK_NUM</span><br
/> <span
style="color: #666666; font-style: italic;"># - This is the week number of year, it depends on the variable FULL_DAY</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;the value of FULL_DAY is considered as the first day of week</span><br
/> <span
style="color: #666666; font-style: italic;"># - By default the command `date +%W` considers monday as first day of week, so if the day of</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;the full backup is different from monday then we must make additional operations</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$FULL_DAY</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> <span
style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$FULL_DAY</span> <span
style="color: #660033;">-le</span> <span
style="color: #000000;">7</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> <span
style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">date</span> +<span
style="color: #000000; font-weight: bold;">%</span>u<span
style="color: #000000; font-weight: bold;">`</span> <span
style="color: #660033;">-ge</span> <span
style="color: #007800;">$FULL_DAY</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span> <br
/> &nbsp; <span
style="color: #007800;">WEEK_NUM</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">expr</span> $<span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #c20cb9; font-weight: bold;">date</span> +<span
style="color: #000000; font-weight: bold;">%</span>W<span
style="color: #7a0874; font-weight: bold;">&#41;</span> + <span
style="color: #000000;">1</span><span
style="color: #000000; font-weight: bold;">`</span><br
/> <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; <span
style="color: #007800;">WEEK_NUM</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">date</span> +<span
style="color: #000000; font-weight: bold;">%</span>W<span
style="color: #000000; font-weight: bold;">`</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># ARCHIVE_DIR</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;This is the directory (full path) of the current week backups (on the remote host)</span><br
/> <span
style="color: #666666; font-style: italic;"># &nbsp;The name of directory indicates the number of the week in the year (e.g 2007-32)</span><br
/> <span
style="color: #007800;">ARCHIVE_DIR</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$ARCHIVE_ROOT</span>/<span
style="color: #007800;">$HOSTNAME</span>/<span
style="color: #780078;">`date +%Y`</span>-<span
style="color: #007800;">$WEEK_NUM</span>&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Directory which holds our current datastore</span><br
/> <span
style="color: #007800;">CURRENT</span>=main<br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Directory which we save incremental changes to (e.g monday_06-08-2007)</span><br
/> <span
style="color: #007800;">INCREMENTDIR</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">date</span> +<span
style="color: #000000; font-weight: bold;">%</span>A_<span
style="color: #000000; font-weight: bold;">%</span>d-<span
style="color: #000000; font-weight: bold;">%</span>m-<span
style="color: #000000; font-weight: bold;">%</span>Y<span
style="color: #000000; font-weight: bold;">`</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Options to pass to rsync</span><br
/> <span
style="color: #666666; font-style: italic;"># -r for recursivity must be explicite in spite of -a because --files-from (see man rsync)</span><br
/> <span
style="color: #007800;">OPTIONS</span>=<span
style="color: #ff0000;">&quot;--force --ignore-errors --delete --delete-excluded <span
style="color: #000099; font-weight: bold;">\<br
/> </span> --exclude-from=<span
style="color: #007800;">$EXCLUDES_LIST</span> --backup --backup-dir=<span
style="color: #007800;">$ARCHIVE_DIR</span>/<span
style="color: #007800;">$INCREMENTDIR</span> <span
style="color: #000099; font-weight: bold;">\<br
/> </span> -arhv --files-from=<span
style="color: #007800;">$BACKUP_LIST</span>&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Our actual rsyncing function</span><br
/> do_rsync<span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span><br
/> <span
style="color: #7a0874; font-weight: bold;">&#123;</span><br
/> &nbsp; &nbsp;<span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$SSH_PORT</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; rsync <span
style="color: #660033;">-e</span> <span
style="color: #ff0000;">&quot;ssh -p <span
style="color: #007800;">$SSH_PORT</span>&quot;</span> <span
style="color: #007800;">$OPTIONS</span> <span
style="color: #007800;">$BACKUP_ROOT</span> <span
style="color: #007800;">$REMOTE_USER</span><span
style="color: #000000; font-weight: bold;">@</span><span
style="color: #007800;">$BACKUP_SRV</span>:<span
style="color: #007800;">$ARCHIVE_DIR</span><span
style="color: #000000; font-weight: bold;">/</span><span
style="color: #007800;">$CURRENT</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #007800;">$LOGFILE</span> <span
style="color: #000000;">2</span><span
style="color: #000000; font-weight: bold;">&gt;&amp;</span><span
style="color: #000000;">1</span><br
/> &nbsp; &nbsp;<span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; rsync <span
style="color: #007800;">$OPTIONS</span> <span
style="color: #007800;">$BACKUP_ROOT</span> <span
style="color: #007800;">$REMOTE_USER</span><span
style="color: #000000; font-weight: bold;">@</span><span
style="color: #007800;">$BACKUP_SRV</span>:<span
style="color: #007800;">$ARCHIVE_DIR</span><span
style="color: #000000; font-weight: bold;">/</span><span
style="color: #007800;">$CURRENT</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #007800;">$LOGFILE</span> <span
style="color: #000000;">2</span><span
style="color: #000000; font-weight: bold;">&gt;&amp;</span><span
style="color: #000000;">1</span><br
/> &nbsp; &nbsp;<span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; &nbsp;<span
style="color: #7a0874; font-weight: bold;">return</span> <br
/> <span
style="color: #7a0874; font-weight: bold;">&#125;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Our post rsync accounting function</span><br
/> do_accounting<span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span><br
/> <span
style="color: #7a0874; font-weight: bold;">&#123;</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$1</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Backup accounting for day <span
style="color: #007800;">$INCREMENTDIR</span> on <span
style="color: #007800;">$HOSTNAME</span>:&quot;</span> <span
style="color: #000000; font-weight: bold;">&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> <br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$SSH_PORT</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">ssh</span> <span
style="color: #660033;">-p</span> <span
style="color: #007800;">$SSH_PORT</span> <span
style="color: #007800;">$REMOTE_USER</span><span
style="color: #000000; font-weight: bold;">@</span><span
style="color: #007800;">$BACKUP_SRV</span> <span
style="color: #c20cb9; font-weight: bold;">du</span> <span
style="color: #660033;">-s</span> <span
style="color: #007800;">$ARCHIVE_DIR</span><span
style="color: #000000; font-weight: bold;">/*</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">ssh</span> <span
style="color: #007800;">$REMOTE_USER</span><span
style="color: #000000; font-weight: bold;">@</span><span
style="color: #007800;">$BACKUP_SRV</span> <span
style="color: #c20cb9; font-weight: bold;">du</span> <span
style="color: #660033;">-s</span> <span
style="color: #007800;">$ARCHIVE_DIR</span><span
style="color: #000000; font-weight: bold;">/*</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">cat</span> <span
style="color: #007800;">$LOGFILE</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">grep</span> <span
style="color: #ff0000;">&quot;rsync: &quot;</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> <br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Mail $1 -s &quot;</span><span
style="color: #007800;">$HOSTNAME</span> Backup Report<span
style="color: #ff0000;">&quot; &lt; /tmp/rsync_script_tmpfile&quot;</span><br
/> &nbsp; &nbsp; mail <span
style="color: #007800;">$1</span> <span
style="color: #660033;">-s</span> <span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$HOSTNAME</span> Backup Report&quot;</span> <span
style="color: #000000; font-weight: bold;">&lt;</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> <br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;rm /tmp/rsync_script_tmpfile&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">rm</span> <span
style="color: #000000; font-weight: bold;">/</span>tmp<span
style="color: #000000; font-weight: bold;">/</span>rsync_script_tmpfile<br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <span
style="color: #7a0874; font-weight: bold;">&#125;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Clean old backups</span><br
/> do_clean<span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span><br
/> <span
style="color: #7a0874; font-weight: bold;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Nb weeks</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">NB_WEEKS_MAX</span>=<span
style="color: #000000;">4</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">LIMIT</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">expr</span> <span
style="color: #007800;">$WEEK_NUM</span> - <span
style="color: #007800;">$NB_WEEKS_MAX</span><span
style="color: #000000; font-weight: bold;">`</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$LIMIT</span> <span
style="color: #660033;">-le</span> <span
style="color: #000000;">0</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #007800;">NB</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">expr</span> <span
style="color: #007800;">$NB_WEEKS_MAX</span> - <span
style="color: #007800;">$WEEK_NUM</span><span
style="color: #000000; font-weight: bold;">`</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #007800;">NB</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">expr</span> <span
style="color: #000000;">52</span> - <span
style="color: #007800;">$NB</span><span
style="color: #000000; font-weight: bold;">`</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #007800;">LAST_YEAR</span>=<span
style="color: #000000; font-weight: bold;">`</span><span
style="color: #c20cb9; font-weight: bold;">expr</span> $<span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #c20cb9; font-weight: bold;">date</span> +<span
style="color: #000000; font-weight: bold;">%</span>Y<span
style="color: #7a0874; font-weight: bold;">&#41;</span> - <span
style="color: #000000;">1</span><span
style="color: #000000; font-weight: bold;">`</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #007800;">TO_DELETE_DIR</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$ARCHIVE_ROOT</span>/<span
style="color: #007800;">$HOSTNAME</span>/<span
style="color: #007800;">$LAST_YEAR</span>-<span
style="color: #007800;">$NB</span>&quot;</span><br
/> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-d</span> <span
style="color: #007800;">$TO_DELETE_DIR</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;rm -rf <span
style="color: #007800;">$TO_DELETE_DIR</span>&quot;</span> &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">rm</span> <span
style="color: #660033;">-rf</span> <span
style="color: #007800;">$TO_DELETE_DIR</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #007800;">TO_DELETE_DIR</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$ARCHIVE_ROOT</span>/<span
style="color: #007800;">$HOSTNAME</span>/<span
style="color: #780078;">`date +%Y`</span>-<span
style="color: #007800;">$LIMIT</span>&quot;</span><br
/> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-d</span> <span
style="color: #007800;">$TO_DELETE_DIR</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;rm -rf <span
style="color: #007800;">$TO_DELETE_DIR</span>&quot;</span> &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">rm</span> <span
style="color: #660033;">-rf</span> <span
style="color: #007800;">$TO_DELETE_DIR</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <span
style="color: #7a0874; font-weight: bold;">&#125;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Some error handling and/or run our backup and accounting</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$BACKUP_LIST</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$EXCLUDES_LIST</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-f</span> <span
style="color: #007800;">$BACKUP_LIST</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-f</span> <span
style="color: #007800;">$EXCLUDES_LIST</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># make sure our backup tree exists</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$SSH_PORT</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">ssh</span> <span
style="color: #660033;">-p</span> <span
style="color: #007800;">$SSH_PORT</span> <span
style="color: #007800;">$REMOTE_USER</span><span
style="color: #000000; font-weight: bold;">@</span><span
style="color: #007800;">$BACKUP_SRV</span> <span
style="color: #c20cb9; font-weight: bold;">install</span> <span
style="color: #660033;">-d</span> <span
style="color: #007800;">$ARCHIVE_DIR</span><span
style="color: #000000; font-weight: bold;">/</span><span
style="color: #007800;">$CURRENT</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">ssh</span> <span
style="color: #007800;">$REMOTE_USER</span><span
style="color: #000000; font-weight: bold;">@</span><span
style="color: #007800;">$BACKUP_SRV</span> <span
style="color: #c20cb9; font-weight: bold;">install</span> <span
style="color: #660033;">-d</span> <span
style="color: #007800;">$ARCHIVE_DIR</span><span
style="color: #000000; font-weight: bold;">/</span><span
style="color: #007800;">$CURRENT</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;=========================================================&quot;</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;<span
style="color: #780078;">`date`</span> : Backup started.&quot;</span> <span
style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; do_rsync <br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #007800;">$?</span> <span
style="color: #660033;">-eq</span> <span
style="color: #000000;">0</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;OK. Backup succeeded&quot;</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">tee</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do_clean<br
/> &nbsp; &nbsp; do_accounting <span
style="color: #007800;">$MAILADDR</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">0</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Backup failed. See <span
style="color: #007800;">$LOGFILE</span> for debug info.&quot;</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">tee</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; &nbsp; do_accounting <span
style="color: #007800;">$MAILADDR</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">1</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$EXCLUDES_LIST</span>: File not found or not a regular file. Backup aborted&quot;</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">tee</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$LOGFILE</span>; <br
/> &nbsp; <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">1</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$BACKUP_LIST</span>: File not found or not a regular file. Backup aborted&quot;</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">tee</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">1</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;You must edit the script file and set the variable EXCLUDES_LIST&quot;</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">tee</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">1</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;You must edit the script file and set the variable BACKUP_LIST&quot;</span> <span
style="color: #000000; font-weight: bold;">|</span> <span
style="color: #c20cb9; font-weight: bold;">tee</span> <span
style="color: #660033;">-a</span> <span
style="color: #007800;">$LOGFILE</span><br
/> &nbsp; <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">1</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #7a0874; font-weight: bold;">exit</span> <span
style="color: #000000;">2</span></div></div><p
style="text-align: justify;">Je sauvegarde ces fichiers :</p><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var/www<br
/> var/log<br
/> etc/apache2<br
/> etc/apt/sources.list<br
/> etc/fstab<br
/> etc/crontab<br
/> etc/hostname<br
/> etc/hosts<br
/> etc/group<br
/> etc/memcached.conf<br
/> etc/mysql<br
/> etc/nginx<br
/> etc/php5<br
/> etc/phpmyadmin<br
/> etc/postfix<br
/> etc/ssh<br
/> etc/fail2ban<br
/> home</div></div><p
style="text-align: justify;">Et j&#8217;exclue ceux-là :</p><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">home/backuper/backup-files.log<br
/> home/backuper/files<br
/> etc/mysql/debian.cnf<br
/> etc/ssh/ssh_host*<br
/> etc/phpmyadmin/htpasswd.setup<br
/> .*_history<br
/> .Xauthority<br
/> .lesshst<br
/> .ssh</div></div><p
style="text-align: justify;"></p><h2>Automatisation</h2><p
style="text-align: justify;">J&#8217;ai rajouté dans mon <em>crontab</em>, deux lignes pour lancer les sauvegardes différées de 2h :</p><p
style="text-align: justify;"></p><div
class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #000000;">0</span> <span
style="color: #000000;">1</span> <span
style="color: #000000; font-weight: bold;">*</span> <span
style="color: #000000; font-weight: bold;">*</span> <span
style="color: #000000; font-weight: bold;">*</span> <span
style="color: #000000; font-weight: bold;">/</span>home<span
style="color: #000000; font-weight: bold;">/</span>backuper<span
style="color: #000000; font-weight: bold;">/</span>scripts<span
style="color: #000000; font-weight: bold;">/</span>backup_mysql.sh<br
/> <span
style="color: #000000;">0</span> <span
style="color: #000000;">3</span> <span
style="color: #000000; font-weight: bold;">*</span> <span
style="color: #000000; font-weight: bold;">*</span> <span
style="color: #000000; font-weight: bold;">*</span> <span
style="color: #000000; font-weight: bold;">/</span>home<span
style="color: #000000; font-weight: bold;">/</span>backuper<span
style="color: #000000; font-weight: bold;">/</span>scripts<span
style="color: #000000; font-weight: bold;">/</span>backup_files.sh</div></div><p></p><h3 class='related_post_title'>Related Posts</h3><ul
class='related_post'><li><a
href='http://www.willdurand.fr/dedibox-v3-nginx-php-fpm-apache2-apc-memcached-mysql/' title='Dédibox v3 : Nginx + PHP-FPM + Apache2 + APC + Memcached + MySQL'>Dédibox v3 : Nginx + PHP-FPM + Apache2 + APC + Memcached + MySQL</a></li><li><a
href='http://www.willdurand.fr/gravatar-de-beaux-avatars-dans-les-commentaires/' title='Gravatar : De beaux avatars dans les commentaires'>Gravatar : De beaux avatars dans les commentaires</a></li><li><a
href='http://www.willdurand.fr/api-google-analytics-une-classe-php5-et-des-resultats-d-integration/' title='API Google Analytics – Une classe PHP5 et des résultats d’intégration'>API Google Analytics – Une classe PHP5 et des résultats d’intégration</a></li><li><a
href='http://www.willdurand.fr/api-google-analytics-round-2-graphiques-et-statistiques-par-page/' title='API Google Analytics Round 2 – Graphiques et statistiques par page'>API Google Analytics Round 2 – Graphiques et statistiques par page</a></li><li><a
href='http://www.willdurand.fr/api-google-analytics-decouverte-par-lexemple/' title='API Google Analytics, découverte par l’exemple'>API Google Analytics, découverte par l’exemple</a></li></ul> <a
rel="nofollow" target="_blank"  href="http://www.printfriendly.com/print/new?url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/printfriendly.png" class="sociable-img sociable-hovers" title="Print" alt="Print" /></a><a
rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;bodytext=Bonjour%2C%20suite%20%C3%A0%20mon%20passage%20en%20d%C3%A9di%C3%A9%20%28D%C3%A9dibox%20v3%29%20et%20%C3%A0%20sa%20configuration%20aujourd%27hui%20termin%C3%A9e%2C%20j%27ai%20trouv%C3%A9%20n%C3%A9cessaire%20de%20m%27occuper%20de%20la%20sauvegarde%20des%20donn%C3%A9es.%20Pour%20cela%2C%20je%20me%20suis%20aid%C3%A9%20de%20plusieurs%20sources%20%3A%0D%0A%0D%0A%09http%3A%2F%2Fwww.ruas-blog.com%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a><a
rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a><a
rel="nofollow" target="_blank"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;notes=Bonjour%2C%20suite%20%C3%A0%20mon%20passage%20en%20d%C3%A9di%C3%A9%20%28D%C3%A9dibox%20v3%29%20et%20%C3%A0%20sa%20configuration%20aujourd%27hui%20termin%C3%A9e%2C%20j%27ai%20trouv%C3%A9%20n%C3%A9cessaire%20de%20m%27occuper%20de%20la%20sauvegarde%20des%20donn%C3%A9es.%20Pour%20cela%2C%20je%20me%20suis%20aid%C3%A9%20de%20plusieurs%20sources%20%3A%0D%0A%0D%0A%09http%3A%2F%2Fwww.ruas-blog.com%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a><a
rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;t=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a><a
rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL%20-%20http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a><a
rel="nofollow" target="_blank"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;annotation=Bonjour%2C%20suite%20%C3%A0%20mon%20passage%20en%20d%C3%A9di%C3%A9%20%28D%C3%A9dibox%20v3%29%20et%20%C3%A0%20sa%20configuration%20aujourd%27hui%20termin%C3%A9e%2C%20j%27ai%20trouv%C3%A9%20n%C3%A9cessaire%20de%20m%27occuper%20de%20la%20sauvegarde%20des%20donn%C3%A9es.%20Pour%20cela%2C%20je%20me%20suis%20aid%C3%A9%20de%20plusieurs%20sources%20%3A%0D%0A%0D%0A%09http%3A%2F%2Fwww.ruas-blog.com%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a><a
rel="nofollow" target="_blank"  href="http://www.friendfeed.com/share?title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;link=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a><a
rel="nofollow" target="_blank"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;source=William%26%23039%3Bs+Blog+D%C3%A9veloppeur+web+ind%C3%A9pendant%2C+%C3%A9tudiant+et+passionn%C3%A9+%21+%23Symfony2+%23Rails+%23Diem+%23Git+%23Nginx+%23WebPerfs+%23SoftwareQuality&amp;summary=Bonjour%2C%20suite%20%C3%A0%20mon%20passage%20en%20d%C3%A9di%C3%A9%20%28D%C3%A9dibox%20v3%29%20et%20%C3%A0%20sa%20configuration%20aujourd%27hui%20termin%C3%A9e%2C%20j%27ai%20trouv%C3%A9%20n%C3%A9cessaire%20de%20m%27occuper%20de%20la%20sauvegarde%20des%20donn%C3%A9es.%20Pour%20cela%2C%20je%20me%20suis%20aid%C3%A9%20de%20plusieurs%20sources%20%3A%0D%0A%0D%0A%09http%3A%2F%2Fwww.ruas-blog.com%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a><a
rel="nofollow" target="_blank"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;t=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/myspace.png" class="sociable-img sociable-hovers" title="MySpace" alt="MySpace" /></a><a
rel="nofollow" target="_blank"  href="http://www.netvibes.com/share?title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/netvibes.png" class="sociable-img sociable-hovers" title="Netvibes" alt="Netvibes" /></a><a
rel="nofollow" target="_blank"  href="http://www.printfriendly.com/print/new?url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/pdf.png" class="sociable-img sociable-hovers" title="PDF" alt="PDF" /></a><a
rel="nofollow" target="_blank"  href="http://ping.fm/ref/?link=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;body=Bonjour%2C%20suite%20%C3%A0%20mon%20passage%20en%20d%C3%A9di%C3%A9%20%28D%C3%A9dibox%20v3%29%20et%20%C3%A0%20sa%20configuration%20aujourd%27hui%20termin%C3%A9e%2C%20j%27ai%20trouv%C3%A9%20n%C3%A9cessaire%20de%20m%27occuper%20de%20la%20sauvegarde%20des%20donn%C3%A9es.%20Pour%20cela%2C%20je%20me%20suis%20aid%C3%A9%20de%20plusieurs%20sources%20%3A%0D%0A%0D%0A%09http%3A%2F%2Fwww.ruas-blog.com%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/ping.png" class="sociable-img sociable-hovers" title="Ping.fm" alt="Ping.fm" /></a><a
rel="nofollow" target="_blank"  href="http://www.willdurand.fr/feed/" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/rss.png" class="sociable-img sociable-hovers" title="RSS" alt="RSS" /></a><a
rel="nofollow" target="_blank"  href="http://technorati.com/faves?add=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a><a
rel="nofollow" target="_blank"  href="http://www.viadeo.com/shareit/share/?url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&title=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&urllanguage=fr" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/viadeo.png" class="sociable-img sociable-hovers" title="viadeo FR" alt="viadeo FR" /></a><a
rel="nofollow" target="_blank"  href="http://www.wikio.com/vote?url=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/wikio.png" class="sociable-img sociable-hovers" title="Wikio" alt="Wikio" /></a><a
rel="nofollow" target="_blank"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.willdurand.fr%2Fsauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql%2F&amp;submitHeadline=Sauvegarde%20incr%C3%A9mentale%20avec%20rsync%20%3A%20fichiers%20et%20base%20de%20donn%C3%A9es%20MySQL&amp;submitSummary=Bonjour%2C%20suite%20%C3%A0%20mon%20passage%20en%20d%C3%A9di%C3%A9%20%28D%C3%A9dibox%20v3%29%20et%20%C3%A0%20sa%20configuration%20aujourd%27hui%20termin%C3%A9e%2C%20j%27ai%20trouv%C3%A9%20n%C3%A9cessaire%20de%20m%27occuper%20de%20la%20sauvegarde%20des%20donn%C3%A9es.%20Pour%20cela%2C%20je%20me%20suis%20aid%C3%A9%20de%20plusieurs%20sources%20%3A%0D%0A%0D%0A%09http%3A%2F%2Fwww.ruas-blog.com%2F&amp;submitCategory=science&amp;submitAssetType=text" ><img
src="http://www.willdurand.fr/wp-content/plugins/sociable-30/images/default/16/yahoobuzz.png" class="sociable-img sociable-hovers" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a><br
/><br
/>]]></content:encoded> <wfw:commentRss>http://www.willdurand.fr/sauvegarde-incrementale-avec-rsync-fichiers-et-base-de-donnees-mysql/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 2/13 queries in 0.007 seconds using memcached
Object Caching 639/651 objects using memcached

Served from: www.willdurand.fr @ 2012-02-06 09:15:40 -->
