Ceci est une ancienne révision du document !
rsnapshot
rsnapshot est une application en ligne de commande de sauvegarde écrite en PERL, et basée sur rsync qui est lui-même un outil standard, puissant et fiable.
rsnapshot gère les sauvegardes de manière incrémentielle, et permet à la fois de conserver différentes versions d'un fichier (il n'écrase pas les anciennes versions), et d'éviter la duplication physique des fichiers inchangés.
Ceci est rendu possible par un emploi intelligent des liens physiques : même si on trouve l'intégralité des fichiers dans chaque répertoire de sauvegarde (un nouveau répertoire est créé à chaque sauvegarde) ils ne prennent qu'une seule fois leur place sur le disque tant qu'ils restent inchangés (et ne sont "réellement" effacés que si on supprime absolument tous les liens physiques).
rsnapshot permet de faire des sauvegardes locales (une copie régulière d’un disque sur un autre) ou distantes (via une connexion SSH) ; rsnapshot tourne alors sur le serveur de backup, et la machine qui se voit ainsi sauvegardée est totalement passive, il faut juste qu’elle ait un serveur SSH activé.
Quelques scripts rsync/ssh pourraient évidemment faire la même chose que rsnapshot, mais rsnapshot est fiable et sa configuration triviale, alors pourquoi s’en passer ?1)
Par rapport à d'autres outils de sauvegarde incrémentielle ou de versioning, rsnapshot exploite les fonctionnalités ordinaires de l'environnement et du système de fichier (son fonctionnement est limpide, pas besoin d'outils spécifiques pour gérer ses sauvegardes après coup ou restaurer quoi que ce soit).
C’est un logiciel libre sous licence GNU GPL.
Pré-requis
- Disposer des droits d'administration.
- Disposer d'une connexion à Internet configurée et activée.
- rsnapshot n'est malheureusement pas traduit en français. Les indications concernant la configuration et les messages d'erreur ou de succès sont rédigés en anglais.
Installation
Configuration
rsnapshot se configure en éditant le fichier /etc/rsnapshot.conf
avec les droits d'administration.
Commençons par créer une sauvegarde du fichier de configuration original :
sudo cp /etc/rsnapshot.conf /etc/rsnapshot.conf.backup
On peut ensuite ouvrir le fichier /etc/rsnapshot.conf
pour le modifier.
rsnapshot configtest
Le fichier de configuration original est là.
Les paramètres principaux sont :
snapshot_root
: c'est le chemin où seront stockées les sauvegardes. Si vous choisissez un appareil externe, qui peut éventuellement être débranché, pensez à empêcher la création automatique de ce répertoire en dé-commentant la ligne suivante :no_create_root 1
(il suffit de retirer le caractère#
au début de la ligne).backup points
: ce sont la configuration des éléments à sauvegarder. De nombreux exemples sont proposés à la fin du fichier.
Pour sauvegarder le répertoire /home
:
backup /home/ localhost/
Depuis un serveur de sauvegarde, pour sauvegarder depuis un accès SSH :
backup root@example.com:/home/ example.com/
- Les paramètres
include
etexclude
permettent de définir des types de fichiers ou des éléments à inclure ou exclure. Ces paramètres sont passés directement à rsync via les options--include-from
et--exclude-from
de rsync. retain
sert à définir le nombre de versions à conserver pour chaque période de sauvegarde (voir alpha, beta ci-dessous).
Par défaut :- 6
alpha
(la sauvegarde alpha est effectuée toutes les 4 heures, en conserver 6 permet de couvrir une journée) - 7
beta
(tous les jours, 7 permet de couvrir une semaine) - 4
gamma
(chaque semaine, 4 permet de couvrir un mois). - Évitez donc de modifier ces paramètres, en dehors de
delta
, que vous pouvez dé-commenter afin de définir le nombre de mois pendant lesquels vous souhaitez conserver les anciennes versions de vos fichiers.
Utilisation
Aide au lancement
rsnapshot help rsnapshot 1.4.5-2 Usage: rsnapshot [-vtxqVD] [-c cfgfile] [command] [args] Type "man rsnapshot" for more information. rsnapshot is a filesystem snapshot utility. It can take incremental snapshots of local and remote filesystems for any number of machines. rsnapshot comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public License for details. Options: -v verbose - Show equivalent shell commands being executed. -t test - Show verbose output, but don't touch anything. This will be similar, but not always exactly the same as the real output from a live run. -c [file] - Specify alternate config file (-c /path/to/file) -q quiet - Suppress non-fatal warnings. -V extra verbose - The same as -v, but with more detail. -D debug - A firehose of diagnostic information. -x one_fs - Don't cross filesystems (same as -x option to rsync). Commands:
Le test
Pour tester votre configuration utiliser l'option -t suivi de l'intervalle choisi :
rsnapshot -t alpha
Pour exécuter manuellement logrotate pour un intervalle donné (rien de plus simple )
rsnapshot alpha
sudo rsnapshot delta /var/cache/rsnapshot/gamma.4 not present (yet), nothing to copy sudo rsnapshot gamma /var/cache/rsnapshot/beta.6 not present (yet), nothing to copy sudo rsnapshot beta /var/cache/rsnapshot/alpha.23 not present (yet), nothing to copy
L'automaticité.
Par technique crontable
Pour automatiser, il faut alors décommenter les lignes du fichier /etc/cron.d/rsnapshot
als -ls /etc/cron.d/rsnapshot 5 -rw-r--r-- 1 root root 472 Aug 22 18:49 /etc/cron.d/rsnapshot a@a:~$ cat /etc/cron.d/rsnapshot # This is a sample cron file for rsnapshot. # The values used correspond to the examples in /etc/rsnapshot.conf. # There you can also set the backup points and many other things. # # To activate this cron file you have to uncomment the lines below. # Feel free to adapt it to your needs. # 0 */4 * * * root /usr/bin/rsnapshot alpha # 30 3 * * * root /usr/bin/rsnapshot beta # 0 3 * * 1 root /usr/bin/rsnapshot gamma # 30 2 1 * * root /usr/bin/rsnapshot delta
Consulter la signification des champs ici pour une adaptation.
En résumé:
- alpha se lance toutes les quatre heures tout le temps au heures exactes à partir de 0 heure.
- beta se lance tous les jours à 3 heures trente.
- gamma se lance tous les lundi à 0 heure 30.
- delta se lance tous les premiers du mois à 2 heures 30.
Par technique timer de systemd
Consulter ces sites
https://github.com/rsnapshot/rsnapshot/issues/147
https://gist.github.com/etskinner/a6d109838f3674360b5c73e6bbd9ca3b
https://wiki.archlinux.org/title/Rsnapshot#Automation
https://linux.claudeclerc.fr/linuxaddict:administrer:sauvegarder
Le changement de niveau sauvegarde
Le principe: Le N° le plus vieux ayant atteint la limite fixée est supprimé, puis les numéros sont incrémentés de 1 par la commande mv et le numéro le plus ancien du niveau inférieur devient le numéro zéro du niveau courant s'il a atteint la limite toujours par la commamde mv. Sinon rien ne se passe. C'est donc particulièrement rapide.
[2024-01-28T13:40:01] /usr/bin/rsnapshot beta: started [2024-01-28T13:40:01] Setting locale to POSIX "C" [2024-01-28T13:40:01] /var/cache/rsnapshot/beta.6 not present (yet), nothing to delete [2024-01-28T13:40:01] mv /var/cache/rsnapshot/beta.5/ /var/cache/rsnapshot/beta.6/ [2024-01-28T13:40:01] mv /var/cache/rsnapshot/beta.4/ /var/cache/rsnapshot/beta.5/ [2024-01-28T13:40:01] mv /var/cache/rsnapshot/beta.3/ /var/cache/rsnapshot/beta.4/ [2024-01-28T13:40:01] mv /var/cache/rsnapshot/beta.2/ /var/cache/rsnapshot/beta.3/ [2024-01-28T13:40:01] mv /var/cache/rsnapshot/beta.1/ /var/cache/rsnapshot/beta.2/ [2024-01-28T13:40:01] /var/cache/rsnapshot/beta.0 not present (yet), nothing to rotate [2024-01-28T13:40:01] mv /var/cache/rsnapshot/alpha.23/ /var/cache/rsnapshot/beta.0/ [2024-01-28T13:40:01] /usr/bin/rsnapshot beta: completed successfully [2024-01-28T13:45:01] /usr/bin/rsnapshot gamma: started [2024-01-28T13:45:01] Setting locale to POSIX "C" [2024-01-28T13:45:01] /var/cache/rsnapshot/gamma.4 not present (yet), nothing to delete [2024-01-28T13:45:01] mv /var/cache/rsnapshot/gamma.3/ /var/cache/rsnapshot/gamma.4/ [2024-01-28T13:45:01] mv /var/cache/rsnapshot/gamma.2/ /var/cache/rsnapshot/gamma.3/ [2024-01-28T13:45:01] mv /var/cache/rsnapshot/gamma.1/ /var/cache/rsnapshot/gamma.2/ [2024-01-28T13:45:01] mv /var/cache/rsnapshot/gamma.0/ /var/cache/rsnapshot/gamma.1/ [2024-01-28T13:45:01] mv /var/cache/rsnapshot/beta.6/ /var/cache/rsnapshot/gamma.0/ [2024-01-28T13:45:01] /usr/bin/rsnapshot gamma: completed successfully
Consultation des fichiers archivés
La sauvegarde la plus récente est disponible sous forme de duplication dans la structure /var/cache/rsnapshot/LettreGrecque.0/localhost
a@a:/var/cache/rsnapshot/alpha.0/localhost$ ls -ls total 11 9 drwxr-xr-x 142 root root 245 Jan 22 11:09 etc 1 drwxr-xr-x 3 root root 3 Jan 18 12:05 home 1 drwxr-xr-x 3 root root 3 Jan 16 06:26 usr
Les sauvegardes précédentes sont incrémentées de 1. La plus ancienne a le N° le plus élevé L'épuration est automatiquement faite en fonction de la périodicité.
ls -ls /var/cache/rsnapshot total 4 1 drwxr-xr-x 3 root root 3 Jan 22 14:30 alpha.0 1 drwxr-xr-x 3 root root 3 Jan 22 14:29 alpha.1 1 drwxr-xr-x 3 root root 3 Jan 22 14:28 alpha.2 1 drwxr-xr-x 3 root root 3 Jan 22 12:07 alpha.3
Chaque sauvegarde est complète.
a@a/var/cache/rsnapshot$ ls -als alpha.1/localhost/home/a/snap/firefox/common/.cache/font* total 52 9 drwxr-xr-x 2 a a 8 Jan 18 12:11 . 9 drwxrwxr-x 7 a a 9 Jan 18 12:13 .. 5 -rw-rw-r-- 4 a a 2824 Jan 18 12:11 1b0908a6d0585007d76bfaf2307693b2-le64.cache-7 5 -rw-rw-r-- 4 a a 2672 Jan 18 12:11 3903115fb2caeb09c6db85c436811fd1-le64.cache-7 9 -rw-rw-r-- 4 a a 15792 Jan 18 12:11 4e991300a593a3c6cd4a18593c77fc31-le64.cache-7 5 -rw-rw-r-- 4 a a 208 Jan 18 12:11 52a0e39f4fa191ab9b015d3c6ec469a6-le64.cache-7 5 -rw-rw-r-- 4 a a 296 Jan 18 12:11 73df973de968df34b353de65bc5493eb-le64.cache-7 5 -rw-r--r-- 4 a a 200 Jan 18 12:11 CACHEDIR.TAG a@a:/var/cache/rsnapshot$ ls -als alpha.0/localhost/home/a/snap/firefox/common/.cache/font* total 84 25 drwxr-xr-x 2 a a 8 Jan 18 12:11 . 25 drwxrwxr-x 7 a a 9 Jan 18 12:13 .. 5 -rw-rw-r-- 4 a a 2824 Jan 18 12:11 1b0908a6d0585007d76bfaf2307693b2-le64.cache-7 5 -rw-rw-r-- 4 a a 2672 Jan 18 12:11 3903115fb2caeb09c6db85c436811fd1-le64.cache-7 9 -rw-rw-r-- 4 a a 15792 Jan 18 12:11 4e991300a593a3c6cd4a18593c77fc31-le64.cache-7 5 -rw-rw-r-- 4 a a 208 Jan 18 12:11 52a0e39f4fa191ab9b015d3c6ec469a6-le64.cache-7 5 -rw-rw-r-- 4 a a 296 Jan 18 12:11 73df973de968df34b353de65bc5493eb-le64.cache-7 5 -rw-r--r-- 4 a a 200 Jan 18 12:11 CACHEDIR.TAG
Mais les fichiers ne sont pas dupliqués. Il est utilisé des liens durs et non symboliques. Exemple:
sudo find /var/cache/rsnapshot -type f -iname fichier -exec ls -il '{}' \; 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/beta.0/localhost/home/a/fichier 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/alpha.1/localhost/home/a/fichier 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/alpha.2/localhost/home/a/fichier 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/alpha.5/localhost/home/a/fichier 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/alpha.0/localhost/home/a/fichier 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/alpha.4/localhost/home/a/fichier 456198 -rw-rw-r-- 7 a a 22072524800 Jan 22 18:41 /var/cache/rsnapshot/alpha.3/localhost/home/a/fichier
La surveillance
Jan 28 12:00:01 a CRON[8704]: (root) CMD (/usr/bin/rsnapshot alpha ; echo Lancement horaire de rsnapshot) Jan 28 12:00:08 a rsnapshot[8717]: /usr/bin/rsnapshot alpha: completed successfully Jan 28 12:38:50 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN A. Jan 28 12:38:50 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN A Jan 28 12:38:50 a systemd-resolved[1676]: Firing regular transaction 10468 for <rsnapshot.org IN A> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:38:50 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN AAAA. Jan 28 12:38:50 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN AAAA Jan 28 12:38:50 a systemd-resolved[1676]: Firing regular transaction 1730 for <rsnapshot.org IN AAAA> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:38:50 a systemd-resolved[1676]: Added positive unauthenticated non-confidential cache entry for rsnapshot.org IN A 300s on wlx0002728d7f31/INET6/fd0f:ee:b0::1 Jan 28 12:38:50 a systemd-resolved[1676]: Regular transaction 10468 for <rsnapshot.org IN A> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:38:51 a systemd-resolved[1676]: Not caching negative entry for: rsnapshot.org IN AAAA, cache mode set to no-negative Jan 28 12:38:51 a systemd-resolved[1676]: Regular transaction 1730 for <rsnapshot.org IN AAAA> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:39:55 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN A. Jan 28 12:39:55 a systemd-resolved[1676]: Positive cache hit for rsnapshot.org IN A Jan 28 12:39:55 a systemd-resolved[1676]: Regular transaction 34154 for <rsnapshot.org IN A> on scope dns on wlx0002728d7f31/* now complete with <success> from cache (unsigned; non-confidential). Jan 28 12:39:55 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN AAAA. Jan 28 12:39:55 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN AAAA Jan 28 12:39:55 a systemd-resolved[1676]: Firing regular transaction 124 for <rsnapshot.org IN AAAA> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:39:55 a systemd-resolved[1676]: Not caching negative entry for: rsnapshot.org IN AAAA, cache mode set to no-negative Jan 28 12:39:55 a systemd-resolved[1676]: Regular transaction 124 for <rsnapshot.org IN AAAA> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:42:54 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN A. Jan 28 12:42:54 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN A Jan 28 12:42:54 a systemd-resolved[1676]: Firing regular transaction 37607 for <rsnapshot.org IN A> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:42:55 a systemd-resolved[1676]: Added positive unauthenticated non-confidential cache entry for rsnapshot.org IN A 56s on wlx0002728d7f31/INET6/fd0f:ee:b0::1 Jan 28 12:42:55 a systemd-resolved[1676]: Regular transaction 37607 for <rsnapshot.org IN A> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:42:55 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN AAAA. Jan 28 12:42:55 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN AAAA Jan 28 12:42:55 a systemd-resolved[1676]: Firing regular transaction 21514 for <rsnapshot.org IN AAAA> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:42:55 a systemd-resolved[1676]: Not caching negative entry for: rsnapshot.org IN AAAA, cache mode set to no-negative Jan 28 12:42:55 a systemd-resolved[1676]: Regular transaction 21514 for <rsnapshot.org IN AAAA> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:46:45 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN A. Jan 28 12:46:45 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN A Jan 28 12:46:45 a systemd-resolved[1676]: Firing regular transaction 19359 for <rsnapshot.org IN A> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:46:45 a systemd-resolved[1676]: Added positive unauthenticated non-confidential cache entry for rsnapshot.org IN A 300s on wlx0002728d7f31/INET/192.168.1.254 Jan 28 12:46:45 a systemd-resolved[1676]: Regular transaction 19359 for <rsnapshot.org IN A> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:46:45 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN AAAA. Jan 28 12:46:45 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN AAAA Jan 28 12:46:45 a systemd-resolved[1676]: Firing regular transaction 45169 for <rsnapshot.org IN AAAA> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:46:45 a systemd-resolved[1676]: Not caching negative entry for: rsnapshot.org IN AAAA, cache mode set to no-negative Jan 28 12:46:45 a systemd-resolved[1676]: Regular transaction 45169 for <rsnapshot.org IN AAAA> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:48:35 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN A. Jan 28 12:48:35 a systemd-resolved[1676]: Positive cache hit for rsnapshot.org IN A Jan 28 12:48:35 a systemd-resolved[1676]: Regular transaction 23523 for <rsnapshot.org IN A> on scope dns on wlx0002728d7f31/* now complete with <success> from cache (unsigned; non-confidential). Jan 28 12:48:35 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN AAAA. Jan 28 12:48:35 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN AAAA Jan 28 12:48:35 a systemd-resolved[1676]: Firing regular transaction 60336 for <rsnapshot.org IN AAAA> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:48:36 a systemd-resolved[1676]: Not caching negative entry for: rsnapshot.org IN AAAA, cache mode set to no-negative Jan 28 12:48:36 a systemd-resolved[1676]: Regular transaction 60336 for <rsnapshot.org IN AAAA> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:51:46 a systemd-resolved[1676]: Removing cache entry for rsnapshot.org IN A (expired 1s ago) Jan 28 12:58:37 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN A. Jan 28 12:58:37 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN A Jan 28 12:58:37 a systemd-resolved[1676]: Firing regular transaction 30985 for <rsnapshot.org IN A> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:58:37 a systemd-resolved[1676]: Looking up RR for rsnapshot.org IN AAAA. Jan 28 12:58:37 a systemd-resolved[1676]: Cache miss for rsnapshot.org IN AAAA Jan 28 12:58:37 a systemd-resolved[1676]: Firing regular transaction 12072 for <rsnapshot.org IN AAAA> scope dns on wlx0002728d7f31/* (validate=yes). Jan 28 12:58:37 a systemd-resolved[1676]: Added positive unauthenticated non-confidential cache entry for rsnapshot.org IN A 300s on wlx0002728d7f31/INET/192.168.1.254 Jan 28 12:58:37 a systemd-resolved[1676]: Regular transaction 30985 for <rsnapshot.org IN A> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential). Jan 28 12:58:37 a systemd-resolved[1676]: Not caching negative entry for: rsnapshot.org IN AAAA, cache mode set to no-negative Jan 28 12:58:37 a systemd-resolved[1676]: Regular transaction 12072 for <rsnapshot.org IN AAAA> on scope dns on wlx0002728d7f31/* now complete with <success> from network (unsigned; non-confidential).
Désinstallation
Pour supprimer cette application, il suffit de supprimer son paquet et de supprimer le fichier /etc/cron.d/rsnapshot. La configuration de l'application sera conservée ou supprimée selon la méthode de désinstallation que vous choisirez.