Added plan b (step).
This commit is contained in:
parent
c2fb193eb0
commit
dd79dea284
9 changed files with 321 additions and 112 deletions
|
@ -1,169 +1,242 @@
|
|||
# Plan Borg
|
||||
| Plan Borg |
|
||||
| --------- |
|
||||
|
||||
# Introduction
|
||||
|
||||
Le plan Borg est une solution de sauvegarde basée sur Borgmatic.
|
||||
|
||||
__TOC__
|
||||
[[_TOC_]]
|
||||
|
||||
## Installation d'un serveur de sauvegarde
|
||||
# Installation d'un serveur de sauvegarde
|
||||
|
||||
### Prérequis
|
||||
## Prérequis
|
||||
|
||||
Ajouter les backports bullseye dans `/etc/apt/source.list` :
|
||||
```
|
||||
deb http://ftp.fr.debian.org/debian/ bullseye-backports main
|
||||
|
||||
```
|
||||
|
||||
Installer les paquets nécessaires :
|
||||
```
|
||||
apt install borgmatic
|
||||
apt install -t bullseye-backports borgmatic borgbackup
|
||||
```
|
||||
|
||||
Créer un utilisateur dédié :
|
||||
Créer un utilisateur dédié `borg` :
|
||||
```
|
||||
adduseradd borgmaster
|
||||
adduser --disabled-password --system --group --home /srv/borg/ --shell /bin/bash borg
|
||||
```
|
||||
|
||||
Créer des clés `ssh` pour l'utilisateur `borg` :
|
||||
```
|
||||
su - borg
|
||||
mkdir ~/.ssh
|
||||
chmod go-rwx ~/.ssh
|
||||
ssh-keygen -t ed25519
|
||||
```
|
||||
|
||||
Créer un dossier pour les scripts maison :
|
||||
```
|
||||
mkdir -p /home/borgmaster/bin
|
||||
mkdir -p ~borg/bin
|
||||
```
|
||||
|
||||
Déclarer ce dossier dans le `path` de `borgmaster` :
|
||||
Copier les scripts utilitaires dans `~borg/bin/` :
|
||||
```
|
||||
export PATH=$PATH:~/bin/
|
||||
```
|
||||
|
||||
Copier les scripts utilitaires dans `~borgmaster/bin/` :
|
||||
```
|
||||
cd ~borgmaster/bin/
|
||||
cd ~borg/bin/
|
||||
git clone truc ou cp
|
||||
```
|
||||
|
||||
Ajouter le script d'initialisation de dépôt de sauvegarde `~borgmaster/bin/doborginit` :
|
||||
Créer les dossiers de configuration de Borgmatic :
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
REPO_NAME="$1"
|
||||
BORG_REPO_ZONE="/var/backups/borgzone"
|
||||
|
||||
borg init --encryption=repokey-blake2 ${BORG_REPO_ZONE}/${REPO_NAME}.repo
|
||||
mkdir -p /etc/borgmatic/ /etc/borgmatic.d/
|
||||
```
|
||||
|
||||
Ajouter le script d'environnement `~borgmaster/bin/doborgenv` :
|
||||
Définir dans `/etc/borgmatic/retention.yaml` les valeurs de rétentions communes :
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
REPO_NAME="$1"
|
||||
export BORG_REPO_ZONE="/var/backups/borgzone"
|
||||
export BORG_REPO="${BORG_REPO_ZONE}/{REPO_NAME}.repo"
|
||||
keep_within: 14d
|
||||
keep_daily: 7
|
||||
keep_weekly: 12
|
||||
keep_monthly: 11
|
||||
```
|
||||
|
||||
Ajouter le script de sauvegarde générale `~borgmaster/bin/dobackups` :
|
||||
Définir dans `/etc/borgmatic/excludes` les patterns d'exclusion :
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
# TODO
|
||||
sh root@$COMPUTER "borgmatic create $OPTIONS --stats --verbosity 1 --syslog-verbosity 1"
|
||||
```
|
||||
|
||||
Ajouter le script de sauvegarde générale `~borgmaster/bin/checks` :
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
borgmatic -c $CONFIG check --verbosity 1
|
||||
borgmatic -c $CONFIG prune --stats --verbosity 1
|
||||
|
||||
# TODO
|
||||
pp:var/cache/
|
||||
pp:var/backups/vm/
|
||||
pp:var/backups/borg/
|
||||
fm:*/.gvfs
|
||||
fm:*/.thumbnails
|
||||
fm:*/.bkl-thumbnails
|
||||
fm:*/Cache
|
||||
fm:*/.cache
|
||||
fm:*/cache
|
||||
fm:*/cache2
|
||||
fm:*/.davfs2
|
||||
fm:*/.local/share/Trash
|
||||
fm:*/lost+found
|
||||
fm:*/sharedfs
|
||||
```
|
||||
|
||||
Définir une passphrase générique :
|
||||
```
|
||||
echo "blablablablablabla" > ~borgmaster/.borg-passphrase
|
||||
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXX" > ~borg/.borg-passphrase
|
||||
```
|
||||
|
||||
Créer un dossier des sauvegardes dédiées au plan Borg :
|
||||
Ajouter la ligne suivante dans `/root/.bashrc` (facilite la commande `borg` directe même si normalement on fait tout avec la commande `borgmatic`) :
|
||||
```
|
||||
mkdir -p /var/backup/borgzone
|
||||
chown borgmaster /var/backup/borgzone
|
||||
export BORG_PASSCOMMAND="cat /srv/borg/.borg-passphrase"
|
||||
```
|
||||
|
||||
Créer un dossier dédié aux sauvegardes du plan Borg :
|
||||
```
|
||||
mkdir -p /var/backup/borg
|
||||
chown borg /var/backup/borg
|
||||
```
|
||||
|
||||
Configurer le `cron` dans `/etc/cron.d/backups` :
|
||||
```
|
||||
10 0 * * * borgmaster /home/borgmaster/bin/dobackups >> /var/backups/borgzone/dobackups.log 2>&1
|
||||
10 12 * * * borgmaster /home/borgmaster/bin/dochecks >> /var/backups/borgzone/dobackups.log 2>&1
|
||||
10 0 * * * borg /srv/borg/bin/dobackups >> /var/backups/borg/dobackups.log 2>&1
|
||||
10 12 * * * borg /srv/borg/bin/doprune >> /var/backups/borg/doprune.log 2>&1
|
||||
10 5 * * 0 borg /srv/borg/bin/dochecks >> /var/backups/borg/dochecks.log 2>&1
|
||||
```
|
||||
|
||||
## Configurer une nouvelle machine sur le serveur de sauvegarde
|
||||
## Configurer la sauvegarde de la machine locale.
|
||||
|
||||
Créer le dossier de dépôt (avec l'utilisateur `borgmaster`) :
|
||||
Créer une configuration pour la sauvegarde de la machine locale `/etc/borgmatic.d/sauvkipeu.yaml` :
|
||||
```
|
||||
doborginit foo.bar.org
|
||||
cp /srv/borg/models/model-conf-local.yaml /etc/borgmatic.d/
|
||||
```
|
||||
|
||||
Configurer Borgmatic dans `/etc/borgmatic/foo.bar.org.conf` :
|
||||
Vérifier que la configuration Borgmatic est valide :
|
||||
```
|
||||
validate-borgmatic-config
|
||||
```
|
||||
|
||||
Initialiser le dépôt de la machine locale :
|
||||
```
|
||||
/srv/borg/bin/doinit sauvkipeu
|
||||
```
|
||||
|
||||
Lancer la première sauvegarde locale (dure moins d'une minutes) :
|
||||
```
|
||||
time /srv/borg/bin/dobackup-local
|
||||
```
|
||||
|
||||
Afficher les informations du dépôt :
|
||||
```
|
||||
borgmatic -c /etc/borgmatic.d/sauvkipeu.yaml info
|
||||
```
|
||||
|
||||
Afficher la liste des sauvegardes du dépôt :
|
||||
```
|
||||
borgmatic -c /etc/borgmatic.d/sauvkipeu.yaml list
|
||||
```
|
||||
|
||||
Afficher le contenu de la sauvegarde :
|
||||
```
|
||||
borgmatic -c /etc/borgmatic.d/sauvkipeu.yaml list --archive 2023-01-14T09:20
|
||||
```
|
||||
|
||||
Ajouter le lancement de la sauvegarde dans `/srv/borg/bin/dobackups` :
|
||||
```
|
||||
/srv/borg/bin/dobackup-local
|
||||
```
|
||||
## Configurer la sauvegarde d'une machine en rsync
|
||||
|
||||
Le principe consiste en deux étapes :
|
||||
- création d'un miroir de la machine à sauvegarder ;
|
||||
- sauvegarde borgmatic du miroir.
|
||||
|
||||
C'est notamment adapté aux cas des routeurs où le logiciel Borgmatic n'est pas déployable.
|
||||
|
||||
|
||||
## Configurer la sauvegarde d'une machine en remote
|
||||
|
||||
C'est le cas nominal. Le principe consiste à configurer le serveur de sauvegarde pour déclencher l'action de sauvegarde sur la machine à sauvegarder.
|
||||
|
||||
### Côté serveur de sauvegarde
|
||||
|
||||
Configurer Borgmatic dans `/etc/borgmatic.d/foo.bar.org.yaml` :
|
||||
```
|
||||
cp /srv/borg/models/model-conf-remote.yaml /etc/borgmatic.d/foo.bar.org.yaml
|
||||
```
|
||||
|
||||
Modifier le chemin le chemin du dépôt :
|
||||
```
|
||||
location:
|
||||
source_directories: []
|
||||
|
||||
repositories:
|
||||
- /var/backups/borgzone/foo.bar.org.repo
|
||||
|
||||
retention:
|
||||
keep_within: 14d
|
||||
keep_daily: 7
|
||||
keep_weekly: 12
|
||||
keep_monthly: 6
|
||||
keep_yearly: 1
|
||||
prefix: 'foo.bar.org-'
|
||||
|
||||
consistency:
|
||||
checks:
|
||||
- repository
|
||||
- archives
|
||||
prefix: 'foo.bar.org-'
|
||||
|
||||
storage:
|
||||
encryption_passphrase: blablabla
|
||||
|
||||
output:
|
||||
color: false
|
||||
- /var/backups/borg/foo.bar.org.repo
|
||||
```
|
||||
|
||||
Autoriser un accès ssh restreint dans `/home/borgmaster/.ssh/authorized_keys` :
|
||||
Créer le dossier du nouveau dépôt de sauvegarde :
|
||||
```
|
||||
command="export BORG_PASSCOMMAND=/home/borg/.borg-passphrase; borg serve --restrict-to-path /var/backups/borgzone/foo.bar.org.repo/ --restrict-to-repository /var/backups/borgzone/foo.bar.org.repo --append-only",restrict ssh-rsa AAAAZZZZZ root@foo.bar.org
|
||||
/srv/borg/bin/doinit foo.bar.org
|
||||
```
|
||||
|
||||
## Configurer une nouvelle machine sur le serveur de sauvegarde
|
||||
|
||||
Installer des paquets nécessaires :
|
||||
Ajouter un accès ssh restreint dans `/srv/borg/.ssh/authorized_keys` :
|
||||
```
|
||||
apt install borgmatic
|
||||
command="export BORG_PASSCOMMAND=/srv/borg/.borg-passphrase; borg serve --restrict-to-path /var/backups/borg/foo.bar.org.repo/ --restrict-to-repository /var/backups/borg/foo.bar.org.repo --append-only",restrict ssh-rsa AAAAZZZZZ admin666@foo.bar.org
|
||||
```
|
||||
|
||||
Configurer Borgmatic dans `/etc/borgmatic/config.yaml` :
|
||||
### Côté machine à sauvegarder
|
||||
|
||||
Ajouter les backports bullseye dans `/etc/apt/source.list` :
|
||||
```
|
||||
location:
|
||||
source_directories:
|
||||
- /etc
|
||||
- /home
|
||||
- /opt
|
||||
- /root
|
||||
- /srv
|
||||
- /usr
|
||||
- /var
|
||||
|
||||
repositories:
|
||||
- borgmaster@sauvkipeu:/var/backups/borgzone/foo.bar.org.repo
|
||||
- borgmaster@gardefou:/var/backups/borgzone/foo.bar.org.repo
|
||||
|
||||
exclude_from:
|
||||
- /etc/borgmatic/excludes
|
||||
|
||||
storage:
|
||||
ssh_command: ssh -p XXXXX
|
||||
encryption_passphrase: blablabla
|
||||
# archive_name_format: '{fqdn}-{now:%Y-%m-%dT%H:%M}'
|
||||
archive_name_format: '{fqdn}-{now:%Y%m%d}'
|
||||
|
||||
retention:
|
||||
prefix: '{fqdn}-'
|
||||
|
||||
output:
|
||||
color: false
|
||||
deb http://ftp.fr.debian.org/debian/ bullseye-backports main
|
||||
```
|
||||
|
||||
Installer les paquets nécessaires :
|
||||
```
|
||||
apt install -t bullseye-backports borgmatic borgbackup
|
||||
```
|
||||
|
||||
Créer et peupler le dossier de configruation de Borgmatic :
|
||||
```
|
||||
mkdir -p /etc/borgmatic
|
||||
cd /etc/borgmatic
|
||||
wget htpps://.../retention.yaml
|
||||
wget htpps://.../Plan B/models/excludes
|
||||
wget htpps://.../Plan B/models/model-conf-remote2.yaml /etc/borgmatic/config.yaml
|
||||
```
|
||||
|
||||
Vérifier que la configuration Borgmatic est valide :
|
||||
```
|
||||
validate-borgmatic-config
|
||||
```
|
||||
|
||||
Configurer la passphrase dans `/etc/borgmatic/config.yaml` :
|
||||
```
|
||||
encryption_passphrase: XXXXXXXXXXXXXX
|
||||
```
|
||||
|
||||
Ajouter des clés dans `/home/admin666/.ssh/authorized_keys` :
|
||||
```
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKUUCCsn2YK4j++wT+ZgQrHazAzW0g9B3tViyu1ByevV borg@sauvkipeu.libre-en-communs.org
|
||||
ssh-ed25519 AAAACXXXXXXXXXXXXXXXXX borg@gardefou.libre-en-communs.org
|
||||
```
|
||||
|
||||
### Tester côté serveur
|
||||
|
||||
Lancer une première sauvegarde :
|
||||
```
|
||||
time sudo /srv/borg/bin/dobackup-remote foo.bar.org
|
||||
```
|
||||
|
||||
Afficher les informations du dépôt :
|
||||
```
|
||||
borgmatic -c /etc/borgmatic.d/foo.bar.org.yaml info
|
||||
```
|
||||
|
||||
Afficher la liste des sauvegardes du dépôt :
|
||||
```
|
||||
borgmatic -c /etc/borgmatic.d/foo.bar.orgyaml list
|
||||
```
|
||||
|
||||
Afficher le contenu de la sauvegarde :
|
||||
```
|
||||
borgmatic -c /etc/borgmatic.d/foo.bar.org.yaml list --archive 2023-XX-XXTXX:XX
|
||||
```
|
||||
|
||||
Ajouter le lancement de la sauvegarde dans `/srv/borg/bin/dobackups` :
|
||||
```
|
||||
/srv/borg/bin/dobackup-remote foo.bar.org
|
||||
```
|
||||
|
|
27
Plan Borg/bin/doborgbackup
Normal file
27
Plan Borg/bin/doborgbackup
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
|
||||
help()
|
||||
{
|
||||
echo "Usage: doborgbackup [ -h | -help | --help | <MACHINE> ]"
|
||||
}
|
||||
|
||||
#
|
||||
help=0
|
||||
if (( $# != 1)); then
|
||||
help=1
|
||||
else
|
||||
for parameter in $@; do
|
||||
if [ "$parameter" == "-h" ] || [ "$parameter" == "-help" ] || [ "$parameter" == "--help" ]; then
|
||||
help=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if (( $help )); then
|
||||
help
|
||||
else
|
||||
MACHINE="$1"
|
||||
BORG_REPOS="/var/backups/borg"
|
||||
|
||||
sh root@$COMPUTER "borgmatic create $OPTIONS --stats --verbosity 1 --syslog-verbosity 1"
|
||||
fi
|
28
Plan Borg/bin/doborgchecks
Normal file
28
Plan Borg/bin/doborgchecks
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
help()
|
||||
{
|
||||
echo "Usage: doborgchecks [ -h | -help | --help | <MACHINE> ]"
|
||||
}
|
||||
|
||||
#
|
||||
help=0
|
||||
if (( $# != 1)); then
|
||||
help=1
|
||||
else
|
||||
for parameter in $@; do
|
||||
if [ "$parameter" == "-h" ] || [ "$parameter" == "-help" ] || [ "$parameter" == "--help" ]; then
|
||||
help=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if (( $help )); then
|
||||
help
|
||||
else
|
||||
MACHINE="$1"
|
||||
BORG_REPOS="/var/backups/borg"
|
||||
|
||||
borgmatic -c $CONFIG check --verbosity 1
|
||||
borgmatic -c $CONFIG prune --stats --verbosity 1
|
||||
fi
|
5
Plan Borg/bin/doborgenv
Normal file
5
Plan Borg/bin/doborgenv
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
REPO_NAME="$1"
|
||||
export BORG_REPOS="/var/backups/borg"
|
||||
export BORG_REPO="${BORG_REPOS}/{REPO_NAME}.repo"
|
27
Plan Borg/bin/doborginit
Normal file
27
Plan Borg/bin/doborginit
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
|
||||
help()
|
||||
{
|
||||
echo "Usage: dobackupinit [ -h | -help | --help | <MACHINE> ]"
|
||||
}
|
||||
|
||||
#
|
||||
help=0
|
||||
if (( $# != 1)); then
|
||||
help=1
|
||||
else
|
||||
for parameter in $@; do
|
||||
if [ "$parameter" == "-h" ] || [ "$parameter" == "-help" ] || [ "$parameter" == "--help" ]; then
|
||||
help=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if (( $help )); then
|
||||
help
|
||||
else
|
||||
REPO_NAME="$1"
|
||||
BORG_REPOS="/var/backups/borg"
|
||||
|
||||
borg init --encryption=repokey-blake2 ${BORG_REPOS}/${REPO_NAME}.repo
|
||||
fi
|
28
Plan Borg/models/config-client.yaml
Normal file
28
Plan Borg/models/config-client.yaml
Normal file
|
@ -0,0 +1,28 @@
|
|||
location:
|
||||
source_directories:
|
||||
- /etc
|
||||
- /home
|
||||
- /opt
|
||||
- /root
|
||||
- /srv
|
||||
- /usr
|
||||
- /var
|
||||
|
||||
repositories:
|
||||
- borgmaster@sauvkipeu:/var/backups/borg/foo.bar.org.repo
|
||||
- borgmaster@gardefou:/var/backups/borg/foo.bar.org.repo
|
||||
|
||||
exclude_from:
|
||||
- /etc/borgmatic/excludes
|
||||
|
||||
storage:
|
||||
ssh_command: ssh -p XXXXX
|
||||
encryption_passphrase: blablabla
|
||||
# archive_name_format: '{fqdn}-{now:%Y-%m-%dT%H:%M}'
|
||||
archive_name_format: '{fqdn}-{now:%Y%m%d}'
|
||||
|
||||
retention:
|
||||
prefix: '{fqdn}-'
|
||||
|
||||
output:
|
||||
color: false
|
2
Plan Borg/models/cron
Normal file
2
Plan Borg/models/cron
Normal file
|
@ -0,0 +1,2 @@
|
|||
10 0 * * * borgmaster /home/borgmaster/bin/dobackups >> /var/backups/borg/dobackups.log 2>&1
|
||||
10 12 * * * borgmaster /home/borgmaster/bin/dochecks >> /var/backups/borg/dobackups.log 2>&1
|
13
Plan Borg/models/excludes
Normal file
13
Plan Borg/models/excludes
Normal file
|
@ -0,0 +1,13 @@
|
|||
pp:var/cache/
|
||||
pp:var/backups/vm/
|
||||
pp:var/backups/borg/
|
||||
fm:*/.gvfs
|
||||
fm:*/.thumbnails
|
||||
fm:*/.bkl-thumbnails
|
||||
fm:*/Cache
|
||||
fm:*/.cache
|
||||
fm:*/cache
|
||||
fm:*/cache2
|
||||
fm:*/.davfs2
|
||||
fm:*/.local/share/Trash
|
||||
fm:*/lost+found
|
6
Plan Borg/models/retention.yaml
Normal file
6
Plan Borg/models/retention.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
keep_within: 14d
|
||||
keep_daily: 7
|
||||
keep_weekly: 12
|
||||
keep_monthly: 11
|
||||
keep_yearly: -1
|
||||
prefix: '20'
|
Loading…
Reference in a new issue