170 lines
3.6 KiB
Markdown
170 lines
3.6 KiB
Markdown
|
# Plan Borg
|
|||
|
|
|||
|
Le plan Borg est une solution de sauvegarde basée sur Borgmatic.
|
|||
|
|
|||
|
__TOC__
|
|||
|
|
|||
|
## Installation d'un serveur de sauvegarde
|
|||
|
|
|||
|
### Prérequis
|
|||
|
|
|||
|
Installer les paquets nécessaires :
|
|||
|
```
|
|||
|
apt install borgmatic
|
|||
|
```
|
|||
|
|
|||
|
Créer un utilisateur dédié :
|
|||
|
```
|
|||
|
adduseradd borgmaster
|
|||
|
```
|
|||
|
|
|||
|
Créer un dossier pour les scripts maison :
|
|||
|
```
|
|||
|
mkdir -p /home/borgmaster/bin
|
|||
|
```
|
|||
|
|
|||
|
Déclarer ce dossier dans le `path` de `borgmaster` :
|
|||
|
```
|
|||
|
export PATH=$PATH:~/bin/
|
|||
|
```
|
|||
|
|
|||
|
Copier les scripts utilitaires dans `~borgmaster/bin/` :
|
|||
|
```
|
|||
|
cd ~borgmaster/bin/
|
|||
|
git clone truc ou cp
|
|||
|
```
|
|||
|
|
|||
|
Ajouter le script d'initialisation de dépôt de sauvegarde `~borgmaster/bin/doborginit` :
|
|||
|
```
|
|||
|
#!/bin/bash
|
|||
|
|
|||
|
REPO_NAME="$1"
|
|||
|
BORG_REPO_ZONE="/var/backups/borgzone"
|
|||
|
|
|||
|
borg init --encryption=repokey-blake2 ${BORG_REPO_ZONE}/${REPO_NAME}.repo
|
|||
|
```
|
|||
|
|
|||
|
Ajouter le script d'environnement `~borgmaster/bin/doborgenv` :
|
|||
|
```
|
|||
|
#!/bin/bash
|
|||
|
|
|||
|
REPO_NAME="$1"
|
|||
|
export BORG_REPO_ZONE="/var/backups/borgzone"
|
|||
|
export BORG_REPO="${BORG_REPO_ZONE}/{REPO_NAME}.repo"
|
|||
|
```
|
|||
|
|
|||
|
Ajouter le script de sauvegarde générale `~borgmaster/bin/dobackups` :
|
|||
|
```
|
|||
|
#!/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
|
|||
|
```
|
|||
|
|
|||
|
Définir une passphrase générique :
|
|||
|
```
|
|||
|
echo "blablablablablabla" > ~borgmaster/.borg-passphrase
|
|||
|
```
|
|||
|
|
|||
|
Créer un dossier des sauvegardes dédiées au plan Borg :
|
|||
|
```
|
|||
|
mkdir -p /var/backup/borgzone
|
|||
|
chown borgmaster /var/backup/borgzone
|
|||
|
```
|
|||
|
|
|||
|
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
|
|||
|
```
|
|||
|
|
|||
|
## Configurer une nouvelle machine sur le serveur de sauvegarde
|
|||
|
|
|||
|
Créer le dossier de dépôt (avec l'utilisateur `borgmaster`) :
|
|||
|
```
|
|||
|
doborginit foo.bar.org
|
|||
|
```
|
|||
|
|
|||
|
Configurer Borgmatic dans `/etc/borgmatic/foo.bar.org.conf` :
|
|||
|
```
|
|||
|
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
|
|||
|
```
|
|||
|
|
|||
|
Autoriser un accès ssh restreint dans `/home/borgmaster/.ssh/authorized_keys` :
|
|||
|
```
|
|||
|
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
|
|||
|
```
|
|||
|
|
|||
|
## Configurer une nouvelle machine sur le serveur de sauvegarde
|
|||
|
|
|||
|
Installer des paquets nécessaires :
|
|||
|
```
|
|||
|
apt install borgmatic
|
|||
|
```
|
|||
|
|
|||
|
Configurer Borgmatic dans `/etc/borgmatic/config.yaml` :
|
|||
|
```
|
|||
|
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
|
|||
|
```
|