borg
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
borg [2019/07/29 12:54] – [Distant] simon | borg [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Borg ====== | ||
- | ===== Initialiser un repo de backup ===== | ||
- | ==== Local ==== | ||
- | <code bash> | ||
- | # borg init -e keyfile / | ||
- | Enter new passphrase: | ||
- | Enter same passphrase again: | ||
- | Do you want your passphrase to be displayed for verification? | ||
- | Your passphrase (between double-quotes): | ||
- | Make sure the passphrase displayed above is exactly what you wanted. | ||
- | By default repositories initialized with this version will produce security | ||
- | errors if written to with an older version (up to and including Borg 1.0.8). | ||
- | |||
- | If you want to use these older versions, you can disable the check by runnning: | ||
- | borg upgrade --disable-tam '/ | ||
- | |||
- | See https:// | ||
- | </ | ||
- | |||
- | <code bash> | ||
- | # ls -al / | ||
- | total 68 | ||
- | drwxr-xr-x 3 root root 4096 jun 29 15:45 . | ||
- | drwxr-xr-x 3 root root 4096 jun 29 15:43 .. | ||
- | -rw------- 1 root root 164 jun 29 15:44 config | ||
- | drwx------ 3 root root 4096 jun 29 15:45 data | ||
- | -rw------- 1 root root 31 jun 29 15:45 hints.0 | ||
- | -rw------- 1 root root 41258 jun 29 15:45 index.0 | ||
- | -rw------- 1 root root 26 jun 29 15:44 README | ||
- | </ | ||
- | |||
- | ==== Distant ==== | ||
- | Je veux sauvegarder un serveur A sur un serveur B. La première chose à faire est de créer une clé SSH sur le serveur A et les accès qui vont bien sur le serveur B. | ||
- | |||
- | Sur le serveur B, qui va accueillir le backup, je prépare le dossier : | ||
- | <code bash> | ||
- | $ sudo mkdir / | ||
- | $ sudo chown -R serveurA: | ||
- | </ | ||
- | |||
- | Sur le serveur A, qui envoie son backup sur B, j' | ||
- | <code bash> | ||
- | root@debian:/ | ||
- | Enter new passphrase: | ||
- | Enter same passphrase again: | ||
- | Do you want your passphrase to be displayed for verification? | ||
- | Your passphrase (between double-quotes): | ||
- | (...) | ||
- | </ | ||
- | |||
- | On peut vérifier sur le serveurB : | ||
- | <code bash> | ||
- | $ ls -al / | ||
- | total 68 | ||
- | drwxr-xr-x 3 serveurA serveurA | ||
- | drwxr-xr-x 4 root root 4096 jui 29 14:21 .. | ||
- | -rw------- 1 serveurA serveurA | ||
- | drwx------ 3 serveurA serveurA | ||
- | -rw------- 1 serveurA serveurA | ||
- | -rw------- 1 serveurA serveurA 41258 jui 29 14:25 index.0 | ||
- | -rw------- 1 serveurA serveurA | ||
- | </ | ||
- | |||
- | Pour ce serveur, j'ai configuré la suite avec [[Borgmatic]]. | ||
- | ===== Faire un premier backup ===== | ||
- | <code bash> | ||
- | # borg create -v -s -p -C lzma,6 --exclude-from=/ | ||
- | Enter passphrase for key / | ||
- | 2.53 GB O 1.41 GB C 1.37 GB D 64649 N var/ | ||
- | Archive name: raspberrypi-20190629-155955 | ||
- | Archive fingerprint: | ||
- | Time (start): Sat, 2019-06-29 16:00:24 | ||
- | Time (end): | ||
- | Duration: 3 hours 25 minutes 28.50 seconds | ||
- | Number of files: 102169 | ||
- | ------------------------------------------------------------------------------ | ||
- | | ||
- | This archive: | ||
- | All archives: | ||
- | |||
- | | ||
- | Chunk index: | ||
- | ------------------------------------------------------------------------------ | ||
- | </ | ||
- | |||
- | Le fichier raspberrypi-exclude contient les répertoire que je ne veux pas sauvegarder : | ||
- | <code bash> | ||
- | # cat / | ||
- | /mnt | ||
- | /dev | ||
- | /media | ||
- | /proc | ||
- | /run | ||
- | /sys | ||
- | /tmp | ||
- | ~/.cache/ | ||
- | /var/cache/ | ||
- | </ | ||
- | |||
- | Un "borg list" nous montre bien ce premier backup : | ||
- | <code bash> | ||
- | # borg list / | ||
- | Enter passphrase for key / | ||
- | raspberrypi-20190629-155955 | ||
- | </ | ||
- | |||
- | Alias et second backup : | ||
- | <code bash> | ||
- | # cat ~/ | ||
- | alias backup=' | ||
- | |||
- | # backup | ||
- | Enter passphrase for key / | ||
- | ------------------------------------------------------------------------------ | ||
- | Archive name: raspberrypi-20190630-100756 | ||
- | Archive fingerprint: | ||
- | Time (start): Sun, 2019-06-30 10:08:10 | ||
- | Time (end): | ||
- | Duration: 3 minutes 44.00 seconds | ||
- | Number of files: 100691 | ||
- | ------------------------------------------------------------------------------ | ||
- | | ||
- | This archive: | ||
- | All archives: | ||
- | |||
- | | ||
- | Chunk index: | ||
- | ------------------------------------------------------------------------------ | ||
- | </ | ||
- | |||
- | 3 min 44 ! | ||
- | |||
- | <code bash> | ||
- | # borg list / | ||
- | Enter passphrase for key / | ||
- | raspberrypi-20190629-155955 | ||
- | raspberrypi-20190630-100756 | ||
- | </ | ||
- | |||
- | ===== Info ===== | ||
- | <code bash> | ||
- | # borg info / | ||
- | Enter passphrase for key / | ||
- | Name: raspberrypi-20190630-100756 | ||
- | Fingerprint: | ||
- | Hostname: raspberrypi | ||
- | Username: root | ||
- | Time (start): Sun, 2019-06-30 10:08:10 | ||
- | Time (end): | ||
- | Command line: / | ||
- | Number of files: 100691 | ||
- | |||
- | | ||
- | This archive: | ||
- | All archives: | ||
- | |||
- | | ||
- | Chunk index: | ||
- | </ | ||
- | |||
- | ===== List et mount ===== | ||
- | On a déjà vu la commande '' | ||
- | <code bash> | ||
- | # borg list / | ||
- | </ | ||
- | |||
- | ===== Monter une sauvegarde avec mount ===== | ||
- | On crée un dossier pour le point de montage et on monte notre sauvegarde dedans : | ||
- | <code bash> | ||
- | # mkdir /mnt/borg | ||
- | |||
- | # borg mount / | ||
- | Enter passphrase for key / | ||
- | |||
- | # ls -al /mnt/borg/ | ||
- | total 4 | ||
- | drwxr-xr-x 1 root root 0 jun 30 11:01 . | ||
- | drwxr-xr-x 4 root root 4096 jun 30 11:01 .. | ||
- | drwxr-xr-x 1 root root 0 jun 30 11:01 raspberrypi-20190629-155955 | ||
- | drwxr-xr-x 1 root root 0 jun 30 11:01 raspberrypi-20190630-100756 | ||
- | </ | ||
- | |||
- | On peut aller fouille une archive avec cette méthode : | ||
- | <code bash> | ||
- | # ls -al / | ||
- | total 10150 | ||
- | drwxr-xr-x 1 root root 0 jun 30 11:01 . | ||
- | drwxr-xr-x 1 root root 0 jun 30 11:01 . | ||
- | drwxr-xr-x 1 root root 0 jun 30 11:01 .. | ||
- | drwxr-xr-x 1 root root 0 mai 17 12:16 bin | ||
- | drwxr-xr-x 1 root root 0 jan 1 1970 boot | ||
- | -rw------- 1 root root 10391552 aoû 28 2016 core | ||
- | -rw-r--r-- 1 root root 2030 aoû 27 2016 equipment.dat | ||
- | drwxr-xr-x 1 root root 0 jun 29 15:09 etc | ||
- | drwxr-xr-x 1 root root 0 sep 3 2018 home | ||
- | drwxr-xr-x 1 root root 0 jun 29 15:09 lib | ||
- | drwx------ 1 root root 0 mai 27 2016 lost+found | ||
- | drwxr-xr-x 1 root root 0 nov 20 2018 opt | ||
- | drwx------ 1 root root 0 jun 30 10:07 root | ||
- | drwxr-xr-x 1 root root 0 jun 29 15:09 sbin | ||
- | drwxr-xr-x 1 root root 0 mai 27 2016 srv | ||
- | drwxr-xr-x 1 root root 0 mai 27 2016 usr | ||
- | drwxr-xr-x 1 root root 0 aoû 31 2018 var | ||
- | </ | ||
- | |||
- | ===== Restaurer avec extract ===== | ||
- | Quelques exemples sur [[https:// | ||
- | |||
- | <code bash> | ||
- | $ # Restaurer une sauvegarde complète | ||
- | $ borg extract < | ||
- | $ # Restaurer une partie de la sauvegarde | ||
- | $ borg extract < | ||
- | </ | ||
- | |||
- | ===== Automatiser ===== | ||
- | Je me suis inspiré des petits scripts trouvés sur [[https:// | ||
- | |||
- | <code bash> | ||
- | $ sudo cat / | ||
- | # | ||
- | |||
- | ## Set environment variables | ||
- | |||
- | export BORG_PASSPHRASE=" | ||
- | |||
- | ## Set some variables | ||
- | |||
- | LOG="/ | ||
- | |||
- | ## Output to a logfile | ||
- | |||
- | exec > >(tee -i ${LOG}) | ||
- | exec 2>&1 | ||
- | |||
- | echo "###### | ||
- | |||
- | borg create -v -s -p -C lzma,6 --exclude-from=/ | ||
- | / | ||
- | |||
- | echo "###### | ||
- | </ | ||
- | |||
- | On le rend exécutable : | ||
- | <code bash> | ||
- | $ sudo cat / | ||
- | </ | ||
- | |||
- | Et on le rajoute dans le crontab : | ||
- | <code bash> | ||
- | $ sudo crontab -e | ||
- | 30 3 * * * / | ||
- | </ | ||
- | |||
- | On fait la même chose pour le prune: | ||
- | <code bash> | ||
- | $ sudo cat / | ||
- | # | ||
- | |||
- | ## Set environment variables | ||
- | |||
- | export BORG_PASSPHRASE=" | ||
- | |||
- | ## Set some variables | ||
- | |||
- | LOG="/ | ||
- | |||
- | ## Output to a logfile | ||
- | |||
- | exec > >(tee -i ${LOG}) | ||
- | exec 2>&1 | ||
- | |||
- | echo "###### | ||
- | |||
- | borg prune --keep-daily 14 --keep-monthly 6 / | ||
- | |||
- | echo "###### | ||
- | </ | ||
- | |||
- | <code bash> | ||
- | $ sudo chmod +x / | ||
- | </ | ||
- | |||
- | <code bash> | ||
- | $ sudo crontab -e | ||
- | 30 4 * * * / | ||
- | </ | ||
- | |||
- | ===== Borgmatic ===== | ||
- | [[Borgmatic]] permet de gérer par un fichier de configuration la rétention, les dossiers à sauvegarder et ce genre de chose plutôt que par des scripts bash. | ||
- | ===== Sources ===== | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// |
borg.1564404848.txt.gz · Dernière modification : 2020/08/09 12:59 (modification externe)