Les backups pour l'infra Colibris
Sources : Doc borgmatic officielle, doc de Luc Didry, référence commandes borgmatic
Sur le serveur à backuper
Ajout des infos ssh de Globenet
vi /root/.ssh/config
Host * IgnoreUnknown UseKeychain AddKeysToAgent yes UseKeychain yes Host <nom alias exemple : globenet> HostName <hostname exemple : be-heb.globenet.org> Port <port ssh exemple : 22 > User <user ssh> IdentitiesOnly yes IdentityFile <chemin vers la clé>
on met la clé échangée avec Globenet dans le home qui va bien
puis on rentre le mot de passe pour qu'il le garde en mémoire
eval `ssh-agent` ssh-add -k /root/.ssh/id_rsa
une autre solution serait d'avoir une passphrase vide
ssh-keygen -p -f /root/.ssh/id_rsa
Install de borgmatic
apt install borgbackup python3-pip -y pip3 install borgmatic # pour maj de borgmatic faire `sudo pip3 install --upgrade borgmatic` generate-borgmatic-config # création du fichier de conf vi /etc/borgmatic/config.yaml # ajustements aux besoins du serveur colibris voir ci dessous validate-borgmatic-config # # vérification du fichier de conf
Changements notables dans /etc/borgmatic/config.yaml (à adapter a chaque serveur), ATTENTION les "..." ne sont pas à copier, ils indiquent des parties non modifiées du fichier de config original
...
location:
# List of source directories to backup (required). Globs and
# tildes are expanded.
source_directories:
- /home
- /etc
- /var/www
# Paths to local or remote repositories (required). Tildes are
# expanded. Multiple repositories are backed up to in
# sequence. See ssh_command for SSH options like identity file
# or port.
repositories:
# on utilise l'alias configuré dans /root/.ssh/config et le nom du serveur comme repo
- ssh://globenet/srv/backups/colibris/ivanillitch
...
# Où on évite de sauvegarde les fichiers temporaires et le cache
# Any paths matching these patterns are included/excluded from
# backups. Globs are expanded. (Tildes are not.) Note that
# Borg considers this option experimental. See the output of
# "borg help patterns" for more details. Quote any value if it
# contains leading punctuation, so it parses correctly.
# patterns:
# - R /
# - '- /home/*/.cache'
# - + /home/susan
# - '- /home/*'
- */tmp/
- */log/
- */cache/
...
""<span id="TOC_1_5" class="yeswiki-title-anchor"></span>""# Repository storage options. See
======https://borgbackup.readthedocs.io/en/stable/usage/create.html and
""<span id="TOC_1_9" class="yeswiki-title-anchor"></span>""# https://borgbackup.readthedocs.io/en/stable/usage/general.html for
======details.
storage:
...
encryption_passphrase: "<mettre une passphrase de ouf que personne ne trouvera jamais>"
...
# Command to use instead of "ssh". This can be used to specify
# ssh options. Defaults to not set.
ssh_command: ssh -i <chemin vers la clé privée ssh>
...
retention:
...
# Number of daily archives to keep.
keep_daily: 7
# Number of weekly archives to keep.
keep_weekly: 4
# Number of monthly archives to keep.
keep_monthly: 3
...
consistency:
# List of one or more consistency checks to run: "repository",
# "archives", "data", and/or "extract". Defaults to
# "repository" and "archives". Set to "disabled" to disable
# all consistency checks. "repository" checks the consistency
# of the repository, "archives" checks all of the archives,
# "data" verifies the integrity of the data within the
# archives, and "extract" does an extraction dry-run of the
# most recent archive. Note that "data" implies "archives".
checks:
- repository
- archives
...
# Restrict the number of checked archives to the last n.
# Applies only to the "archives" check. Defaults to checking
# all archives.
check_last: 3
...
hooks:
...
mysql_databases:
# Database name (required if using this hook). Or
# "all" to dump all databases on the host. Note
# that using this database hook implicitly enables
# both read_special and one_file_system (see
# above) to support dump and restore streaming.
# on sauve toutes les bases
- name: "all"
...
# Username with which to connect to the database.
# Defaults to the username of the current user.
username: root
# Password with which to connect to the database.
# Omitting a password will only work if MySQL is
# configured to trust the configured username
# without a password.
password: "<mot de passe root de mysql pour avoir toutes les dbs>"
# Additional mysqldump options to pass directly to
# the dump command, without performing any
# validation on them. See mysqldump documentation
# for details.
options: --skip-comments
...
Premier backup crash test
Init de repositoryborgmatic init -e repokey
Premier lancement du backup
borgmatic --verbosity 1 --files
Mise en place du cron
rajout d'une tâche CRONcrontab -e # a faire en tant que root
pour un démarrage à 3h15
15 3 * * * PATH=$PATH:/usr/bin:/usr/local/bin /usr/local/bin/borgmatic --verbosity -1 --syslog-verbosity 1
Commandes borgmatic utiles
Lister les archives du repoborgmatic list
Lister de maniere compacte les archives du repo
borgmatic list --short --last 1
la chaine de carctère entre [ ] représente l'ID de la sauvegarde
Lancement d'une session de sauvegarde
borgmatic create --progress --stats --files
Restaurer une sauvegarde
borgmatic mount --archive [NOMDELARCHIVE] --mount-point /root/RestoreBackups
le nom de l'archive etant de la forme <nomserveur-date> exemple : ivanillitch-2022-01-24T02:15:04.683566
Une fois le backup copié/recupéré, faire un
borgmatic umount --mount-point /root/RestoreBackups
En cas d'erreur Failed to create/acquire the lock /srv/backups/colibris/ivanillitch/lock (timeout). s'assurer que rien ne tourne et faire
borgmatic borg break-lock