Outils pour utilisateurs

Outils du site


borg

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
borg [2019/07/29 12:51] – [Distant] simonborg [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 /mnt/data/backups/raspberrypi 
-Enter new passphrase:  
-Enter same passphrase again:  
-Do you want your passphrase to be displayed for verification? [yN]: y 
-Your passphrase (between double-quotes): "maSuperLongueEtCompliquéePassphrase" 
-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 '/mnt/data/backups/raspberrypi' 
- 
-See https://borgbackup.readthedocs.io/en/stable/changes.html#pre-1-0-9-manifest-spoofing-vulnerability for details about the security implications. 
-</code> 
- 
-<code bash> 
-# ls -al /mnt/data/backups/raspberrypi/ 
-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 
-</code> 
- 
-==== 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 /mnt/data/backups/serveurA 
-$ sudo chown -R serveurA:serveurA /mnt/data/backups/serveurA 
-</code> 
- 
-Sur le serveur A, qui envoie son backup sur B, j'initialise le repository : 
-<code bash> 
-root@debian:/home/simon# borg init --encryption=repokey-blake2 serveurA@serveurB:/mnt/data/backups/serveurA 
-Enter new passphrase:  
-Enter same passphrase again:  
-Do you want your passphrase to be displayed for verification? [yN]: y 
-Your passphrase (between double-quotes): "MaGrossePassPhraseQueJeDonneraiPas" 
-(...) 
-</code> 
- 
-On peut vérifier sur le serveurB : 
-<code bash> 
-$ ls -al /mnt/data/backups/serveurA/ 
-total 68 
-drwxr-xr-x 3 serveurA serveurA  4096 jui 29 14:25 . 
-drwxr-xr-x 4 root    root       4096 jui 29 14:21 .. 
--rw------- 1 serveurA serveurA   919 jui 29 14:25 config 
-drwx------ 3 serveurA serveurA  4096 jui 29 14:25 data 
--rw------- 1 serveurA serveurA    31 jui 29 14:25 hints.0 
--rw------- 1 serveurA serveurA 41258 jui 29 14:25 index.0 
--rw------- 1 serveurA serveurA    26 jui 29 14:21 README 
-</code> 
-===== Faire un premier backup ===== 
-<code bash> 
-# borg create -v -s -p -C lzma,6 --exclude-from=/mnt/data/backups/raspberrypi-exclude /mnt/data/backups/raspberrypi::{hostname}-{now:%Y%m%d-%H%M%S} / 
-Enter passphrase for key /root/.config/borg/keys/mnt_data_backups_raspberrypi:  
-2.53 GB O 1.41 GB C 1.37 GB D 64649 N var/lib/docker/overlay2/dd058fc33661deeca3f305d03...itemap-1.2.0/spec/fixtures/_posts/2016-04-02-错误.ht------------------------------------------------------------------------------                                                                 
-Archive name: raspberrypi-20190629-155955 
-Archive fingerprint: 7526334a84d9a8db637909dac461073e10a8f9fa4300f6b205459c1ee802ceee 
-Time (start): Sat, 2019-06-29 16:00:24 
-Time (end):   Sat, 2019-06-29 19:25:53 
-Duration: 3 hours 25 minutes 28.50 seconds 
-Number of files: 102169 
------------------------------------------------------------------------------- 
-                       Original size      Compressed size    Deduplicated size 
-This archive:                3.00 GB              1.55 GB              1.50 GB 
-All archives:                3.00 GB              1.55 GB              1.50 GB 
- 
-                       Unique chunks         Total chunks 
-Chunk index:                   85977               100707 
------------------------------------------------------------------------------- 
-</code> 
- 
-Le fichier raspberrypi-exclude contient les répertoire que je ne veux pas sauvegarder :  
-<code bash> 
-# cat /mnt/data/backups/raspberrypi-exclude 
-/mnt 
-/dev 
-/media 
-/proc 
-/run 
-/sys 
-/tmp 
-~/.cache/ 
-/var/cache/ 
-</code> 
- 
-Un "borg list" nous montre bien ce premier backup : 
-<code bash> 
-# borg list /mnt/data/backups/raspberrypi/ 
-Enter passphrase for key /root/.config/borg/keys/mnt_data_backups_raspberrypi:  
-raspberrypi-20190629-155955          Sat, 2019-06-29 16:00:24 
-</code> 
- 
-Alias et second backup :  
-<code bash> 
-# cat ~/.bash_aliases  
-alias backup='borg create -v -s -p -C lzma,6 --exclude-from=/mnt/data/backups/raspberrypi-exclude /mnt/data/backups/raspberrypi::{hostname}-{now:%Y%m%d-%H%M%S} /' 
- 
-# backup  
-Enter passphrase for key /root/.config/borg/keys/mnt_data_backups_raspberrypi:  
------------------------------------------------------------------------------- 
-Archive name: raspberrypi-20190630-100756 
-Archive fingerprint: 8f2aae9f8f3db9e086c746f686ddc999c8996e470cd066524509b6eb47253e7a 
-Time (start): Sun, 2019-06-30 10:08:10 
-Time (end):   Sun, 2019-06-30 10:11:54 
-Duration: 3 minutes 44.00 seconds 
-Number of files: 100691 
------------------------------------------------------------------------------- 
-                       Original size      Compressed size    Deduplicated size 
-This archive:                2.21 GB            806.89 MB              2.19 MB 
-All archives:                5.21 GB              2.36 GB              1.51 GB 
- 
-                       Unique chunks         Total chunks 
-Chunk index:                   86057               199693 
------------------------------------------------------------------------------- 
-</code> 
- 
-3 min 44 ! 
- 
-<code bash> 
-# borg list /mnt/data/backups/raspberrypi 
-Enter passphrase for key /root/.config/borg/keys/mnt_data_backups_raspberrypi:  
-raspberrypi-20190629-155955          Sat, 2019-06-29 16:00:24 
-raspberrypi-20190630-100756          Sun, 2019-06-30 10:08:10 
-</code> 
- 
-===== Info ===== 
-<code bash> 
-# borg info /mnt/data/backups/raspberrypi::raspberrypi-20190630-100756 
-Enter passphrase for key /root/.config/borg/keys/mnt_data_backups_raspberrypi:  
-Name: raspberrypi-20190630-100756 
-Fingerprint: 8f2aae9f8f3db9e086c746f686ddc999c8996e470cd066524509b6eb47253e7a 
-Hostname: raspberrypi 
-Username: root 
-Time (start): Sun, 2019-06-30 10:08:10 
-Time (end):   Sun, 2019-06-30 10:11:54 
-Command line: /usr/bin/borg create -v -s -p -C lzma,6 --exclude-from=/mnt/data/backups/raspberrypi-exclude /mnt/data/backups/raspberrypi::{hostname}-{now:%Y%m%d-%H%M%S} / 
-Number of files: 100691 
- 
-                       Original size      Compressed size    Deduplicated size 
-This archive:                2.21 GB            806.89 MB              2.19 MB 
-All archives:                5.21 GB              2.36 GB              1.51 GB 
- 
-                       Unique chunks         Total chunks 
-Chunk index:                   86057               199693 
-</code> 
- 
-===== List et mount ===== 
-On a déjà vu la commande ''bord list'' qui permet de voir les différentes sauvegardes effectuées. On peut aussi l'utiliser pour afficher tous les fichiers sauvegardés. (Attention, ça va afficher des centaines/milliers de lignes... C'est intéressant seulement pour vérifier qu'un fichier particulier est bien sauvegardé, j'imagine.) 
-<code bash> 
-# borg list /mnt/data/backups/raspberrypi::raspberrypi-20190630-100756 
-</code> 
- 
-===== 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 /mnt/data/backups/raspberrypi /mnt/borg/ 
-Enter passphrase for key /root/.config/borg/keys/mnt_data_backups_raspberrypi: 
- 
-# 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 
-</code> 
- 
-On peut aller fouille une archive avec cette méthode : 
-<code bash> 
-# ls -al /mnt/borg/raspberrypi-20190630-100756/ 
-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 
-</code> 
- 
-===== Restaurer avec extract ===== 
-Quelques exemples sur [[https://blog.garamotte.net/posts/2018/01/11/fr-backup-and-restore-with-borg.html#restauration-dune-sauvegarde|garamotte.net]] : 
- 
-<code bash> 
-$ # Restaurer une sauvegarde complète 
-$ borg extract <RepoPath>::<SaveName> 
-$ # Restaurer une partie de la sauvegarde 
-$ borg extract <RepoPath>::<SaveName> <Filename> <Path>/<Directory> 
-</code> 
- 
-===== Automatiser ===== 
-Je me suis inspiré des petits scripts trouvés sur [[https://community.hetzner.com/tutorials/install-and-configure-borgbackup|hetzner.com]] pour automatiser le backup (et le prune derrière!).  
- 
-<code bash> 
-$ sudo cat /usr/local/bin/backup.sh  
-#!/usr/bin/env bash 
- 
-## Set environment variables 
- 
-export BORG_PASSPHRASE="monSuperGrosPassword" 
- 
-## Set some variables 
- 
-LOG="/var/log/borg/backup.log" 
- 
-## Output to a logfile 
- 
-exec > >(tee -i ${LOG}) 
-exec 2>&1 
- 
-echo "###### Backup started: $(date) ######" 
- 
-borg create -v -s -p -C lzma,6 --exclude-from=/mnt/data/backups/raspberrypi-exclude \ 
- /mnt/data/backups/raspberrypi::{hostname}-{now:%Y%m%d-%H%M%S} / 
- 
-echo "###### Backup ended: $(date) ######" 
-</code> 
- 
-On le rend exécutable :  
-<code bash> 
-$ sudo cat /usr/local/bin/backup.sh  
-</code> 
- 
-Et on le rajoute dans le crontab :  
-<code bash> 
-$ sudo crontab -e 
-30 3 * * * /usr/local/bin/backup.sh > /dev/null 2>&1 
-</code> 
- 
-On fait la même chose pour le prune:  
-<code bash> 
-$ sudo cat /usr/local/bin/backup-prune.sh  
-#!/usr/bin/env bash 
- 
-## Set environment variables 
- 
-export BORG_PASSPHRASE="monSuperGrosPassword" 
- 
-## Set some variables 
- 
-LOG="/var/log/borg/backup.log" 
- 
-## Output to a logfile 
- 
-exec > >(tee -i ${LOG}) 
-exec 2>&1 
- 
-echo "###### Prune backups started: $(date) ######" 
- 
-borg prune --keep-daily 14 --keep-monthly 6 /mnt/data/backups/raspberrypi/ 
- 
-echo "###### Prune backups ended: $(date) ######" 
-</code> 
- 
-<code bash> 
-$ sudo chmod +x /usr/local/bin/backup-prune.sh 
-</code> 
- 
-<code bash> 
-$ sudo crontab -e 
-30 4 * * * /usr/local/bin/backup-prune.sh > /dev/null 2>&1 
-</code> 
- 
-===== 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://www.sysnove.fr/blog/2016/06/backupninja-borg.html|Backup avec Borg et BackupNinja (sysnove.fr)]] 
-  * [[https://blog.garamotte.net/posts/2018/01/11/fr-backup-and-restore-with-borg.html|Backup-restore with borg (blog.garamotte.net)]] 
-  * [[https://community.hetzner.com/tutorials/install-and-configure-borgbackup|Install and configure BorgBackup (hetzner.com)]] 
-  * [[https://torsion.org/borgmatic/|Borgmatic]] pour simplifier l'automatisation des backups 
borg.1564404693.txt.gz · Dernière modification : 2020/08/09 12:59 (modification externe)