Plan Borg: updated scripts and models.

This commit is contained in:
Christian P. MOMON 2023-01-16 19:44:21 +01:00
parent 861b7062d7
commit 891a47bc59
19 changed files with 287 additions and 75 deletions

View File

@ -38,10 +38,11 @@ Créer un dossier pour les scripts maison :
mkdir -p ~borg/bin mkdir -p ~borg/bin
``` ```
Copier les scripts utilitaires dans `~borg/bin/` : Récupérer les scripts et modèles :
``` ```
cd ~borg/bin/ cd ~borg/
git clone truc ou cp mkdir bin models
wget
``` ```
Créer les dossiers de configuration de Borgmatic : Créer les dossiers de configuration de Borgmatic :
@ -147,7 +148,7 @@ C'est le cas nominal. Le principe consiste à configurer le serveur de sauvegard
Configurer Borgmatic dans `/etc/borgmatic.d/foo.bar.org.yaml` : 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 cp /srv/borg/models/model-conf-remote.yaml /etc/borgmatic.d/config.yaml
``` ```
Modifier le chemin le chemin du dépôt : Modifier le chemin le chemin du dépôt :
@ -247,4 +248,27 @@ STU
STU STU
# Sauver les bases de données # Sauver les bases de données
STU STU
# Notes pour les mises à jour futures
Actuellement :
```
root@sauvkipeu:/var/backups/borg# borgmatic --version
1.5.13.dev0
root@sauvkipeu:/var/backups/borg# borg -V
borg 1.1.16
```
Or :
- [Borgmatic releases](https://projects.torsion.org/borgmatic-collective/borgmatic/releases) : 1.7.5
- [Borg release](https://github.com/borgbackup/borg/releases) : 1.2.3
Donc des précautions sont à prévoir dans le futur. Normalement, commme l'usage fait est relativment basique, cela devrait avoir des impactes limités.
Pour Borgmatic :
- [1.7.0](https://projects.torsion.org/borgmatic-collective/borgmatic/releases/tag/1.7.0) :
- #571: Add "--list" as alias for "--files" flag on "create" and "export-tar" actions.
- [1.6.1](https://projects.torsion.org/borgmatic-collective/borgmatic/releases/tag/1.6.1) :
- #402: Remove the error when "archive_name_format" is specified but a retention prefix isn't.
-

10
Plan Borg/bin/dobackup-local Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
COMPUTER=$(hostname -s)
CONFIG="/etc/borgmatic.d/$COMPUTER.yaml"
if [ -f "$CONFIG" ]; then
echo "=================================================================="
echo "=== BORG $COMPUTER started at $(date)"
borgmatic -c $CONFIG create $OPTIONS --stats --verbosity 1 --syslog-verbosity 1
echo "=== BORG $COMPUTER ended at $(date)"
fi

33
Plan Borg/bin/dobackup-remote Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
help()
{
echo "Usage: dobackup-remote [ -h | -help | --help | <COMPUTER> ]"
echo "Trigger backup on remote machine."
}
#
help=0
if (( $# != 1)); then
help=1
elif [ "$parameter" == "-h" ] || [ "$parameter" == "-help" ] || [ "$parameter" == "--help" ]; then
help=1
fi
if (( $help )); then
help
else
COMPUTER="$1"
echo "===== $COMPUTER ====="
# Fix repo owner.
BORG_REPO="/var/backups/borg/${COMPUTER}.repo"
chown -R borg.borg $BORG_REPO
# Trigger remote backup.
REMOTE_USER="admin666"
su - borg -c "ssh ${REMOTE_USER}@${COMPUTER} \"borgmatic create $OPTIONS --stats --verbosity 1 --syslog-verbosity 1\""
fi

View File

@ -0,0 +1,32 @@
#!/bin/bash
help()
{
echo "Usage: dobackup-rsync [ -h | -help | --help | <MACHINE> ]"
echo "Rsync remote before backup it."
}
#
help=0
if (( $# != 1)); then
help=1
elif [ "$parameter" == "-h" ] || [ "$parameter" == "-help" ] || [ "$parameter" == "--help" ]; then
help=1
fi
if (( $help )); then
help
else
MACHINE="$1"
REMOTE_USER=admin666
echo "===== $COMPUTER ====="
# rsync
rsync root@${COMPUTER} /var/backups/borg/mirrors/$COMPUTER --exclude
# Backup the rsync directory.
CONFIG="/etc/borgmatic.d/$COMPUTER.conf"
if [ -f "$CONFIG" ]; then
borgmatic -c $CONFIG create $OPTIONS --stats --verbosity 1 --syslog-verbosity 1
fi
fi

50
Plan Borg/bin/dobackups Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
BINDIR=$(dirname "$0")
echo $BINDIR
echo "================================================================================"
echo " Sauvegardes du "$(date)
echo "================================================================================"
# Local machine.
${BINDIR}/dobackup-local
# Main machines.
# aunt
# mother
# Routers.
# leparc
# fontainebleau
# gisors
# Virtual machines.
# audio
# audio.chalec.org
# ctrlv.chalec.org
# dns
# forge.chalec.org
# gestion.a-lec.org
# git
# isengard.libre-en-communs.org
# libreverse.chalec.org
# mail
# nuage.chalec.org
# pad.chalec.org
# petition.chalec.org
# stats.chalec.org
# status.chalec.org
# toot
# toot.chalec.org
# video.chalec.org
# visio.chalec.org
# www
# www.chalec.org
# xmpp
# xmpp.chalec.org
echo "====="
echo "Ended at: "`date`
echo "================================================================================"

View File

@ -1,27 +0,0 @@
#!/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

View File

@ -1,28 +0,0 @@
#!/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

View File

@ -1,5 +0,0 @@
#!/bin/bash
REPO_NAME="$1"
export BORG_REPOS="/var/backups/borg"
export BORG_REPO="${BORG_REPOS}/{REPO_NAME}.repo"

11
Plan Borg/bin/dochecks Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
echo "================================================================================"
echo " Checks du "$(date)
echo "================================================================================"
borgmatic check --verbosity 1
echo "====="
echo "Ended at: "`date`
echo "================================================================================"

17
Plan Borg/bin/dochecks2 Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
echo "================================================================================"
echo " Checks du "$(date)
echo "================================================================================"
REPO_DIR="/var/backups/borg"
for REPO in $(ls -d ${REPO_DIR}/*.repo); do
echo "$REPO"
borg check --info /var/backups/borg/sauvkipeu.repo/
echo "================================================================================"
done
echo "Ended at: "`date`
echo "================================================================================"

10
Plan Borg/bin/doborginit → Plan Borg/bin/doinit Normal file → Executable file
View File

@ -2,7 +2,8 @@
help() help()
{ {
echo "Usage: dobackupinit [ -h | -help | --help | <MACHINE> ]" echo "Usage: doinit [ -h | -help | --help | <MACHINE> ]"
echo "Init a borg repository."
} }
# #
@ -20,8 +21,9 @@ fi
if (( $help )); then if (( $help )); then
help help
else else
REPO_NAME="$1" COMPUTER="$1"
BORG_REPOS="/var/backups/borg"
borg init --encryption=repokey-blake2 ${BORG_REPOS}/${REPO_NAME}.repo borgmatic -c /etc/borgmatic.d/${COMPUTER}.yaml init --encryption=repokey-blake2
fi fi

11
Plan Borg/bin/doprunes Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
echo "================================================================================"
echo " Prunes du "$(date)
echo "================================================================================"
borgmatic prune --stats --files --verbosity 1
echo "====="
echo "Ended at: "`date`
echo "================================================================================"

17
Plan Borg/bin/doprunes2 Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
echo "================================================================================"
echo " Prunes du "$(date)
echo "================================================================================"
REPO_DIR="/var/backups/borg"
for REPO in $(ls -d ${REPO_DIR}/*.repo); do
echo "$REPO"
borg prune --keep-within 3d --keep-daily 7 --keep-weekly 8 --keep-monthly 6 --info --list --stats /var/backups/borg/sauvkipeu.repo/
echo "================================================================================"
done
echo "Ended at: "`date`
echo "================================================================================"

14
Plan Borg/bin/lastbackups Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
SCRIPT_NAME="$(basename "$0")"
BACKUPS_DIR="/var/backups/borg/$computer"
cd $BACKUPS_DIR
for BORG_REPO in $(ls -d *.repo); do
if [ -d "$BORG_REPO" ]; then
#echo "$BORG_REPO"
COMPUTER=$(printf "%-40s" ${BORG_REPO::-5})
OUTPUT=$(borg list "$BORG_REPO" | sort -h | tail -1 | awk '{ print $1}' )
echo "$COMPUTER $OUTPUT"
fi
done

View File

@ -1,2 +1,3 @@
10 0 * * * borgmaster /home/borgmaster/bin/dobackups >> /var/backups/borg/dobackups.log 2>&1 10 0 * * * root /srv/borg/bin/dobackups >> /var/backups/borg/dobackups.log 2>&1
10 12 * * * borgmaster /home/borgmaster/bin/dochecks >> /var/backups/borg/dobackups.log 2>&1 10 12 * * * root /srv/borg/bin/doprunes >> /var/backups/borg/doprunes.log 2>&1
10 6 * * * root /srv/borg/bin/dochecks >> /var/backups/borg/dochecks.log 2>&1

View File

@ -11,3 +11,4 @@ fm:*/cache2
fm:*/.davfs2 fm:*/.davfs2
fm:*/.local/share/Trash fm:*/.local/share/Trash
fm:*/lost+found fm:*/lost+found
fm:*/sharedfs |

View File

@ -0,0 +1,30 @@
location:
source_directories:
- /etc
- /home
- /opt
- /root
- /srv
- /usr
- /var
repositories:
- /var/backups/borg/{hostname}.repo
exclude_from:
- /etc/borgmatic/excludes
storage:
encryption_passcommand: 'cat /srv/borg/.borg-passphrase'
archive_name_format: '{now:%Y-%m-%dT%H:%M}'
retention:
!include /etc/borgmatic/retention.yaml
consistency:
checks:
- repository
- archives
output:
color: false

View File

@ -0,0 +1,19 @@
location:
source_directories: []
repositories:
- /var/backups/borg/<NAME>.repo
retention:
!include /etc/borgmatic/retention.yaml
consistency:
checks:
- repository
- archives
storage:
encryption_passcommand: 'cat /srv/borg/.borg-passphrase'
output:
color: false

View File

@ -1,6 +1,6 @@
keep_within: 14d keep_within: 3d
keep_daily: 7 keep_daily: 7
keep_weekly: 12 keep_weekly: 8
keep_monthly: 11 keep_monthly: 6
keep_yearly: -1 keep_yearly: -1
prefix: '20' prefix: '2'