From 891a47bc593670aae3d10cc94395bb03923d07ba Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 16 Jan 2023 19:44:21 +0100 Subject: [PATCH] Plan Borg: updated scripts and models. --- Plan Borg/README.md | 34 ++++++++++++++--- Plan Borg/bin/dobackup-local | 10 +++++ Plan Borg/bin/dobackup-remote | 33 ++++++++++++++++ Plan Borg/bin/dobackup-rsync | 32 ++++++++++++++++ Plan Borg/bin/dobackups | 50 +++++++++++++++++++++++++ Plan Borg/bin/doborgbackup | 27 ------------- Plan Borg/bin/doborgchecks | 28 -------------- Plan Borg/bin/doborgenv | 5 --- Plan Borg/bin/dochecks | 11 ++++++ Plan Borg/bin/dochecks2 | 17 +++++++++ Plan Borg/bin/{doborginit => doinit} | 10 +++-- Plan Borg/bin/doprunes | 11 ++++++ Plan Borg/bin/doprunes2 | 17 +++++++++ Plan Borg/bin/lastbackups | 14 +++++++ Plan Borg/models/cron | 5 ++- Plan Borg/models/excludes | 1 + Plan Borg/models/model-conf-local.yaml | 30 +++++++++++++++ Plan Borg/models/model-conf-remote.yaml | 19 ++++++++++ Plan Borg/models/retention.yaml | 8 ++-- 19 files changed, 287 insertions(+), 75 deletions(-) create mode 100755 Plan Borg/bin/dobackup-local create mode 100755 Plan Borg/bin/dobackup-remote create mode 100644 Plan Borg/bin/dobackup-rsync create mode 100755 Plan Borg/bin/dobackups delete mode 100644 Plan Borg/bin/doborgbackup delete mode 100644 Plan Borg/bin/doborgchecks delete mode 100644 Plan Borg/bin/doborgenv create mode 100755 Plan Borg/bin/dochecks create mode 100755 Plan Borg/bin/dochecks2 rename Plan Borg/bin/{doborginit => doinit} (59%) mode change 100644 => 100755 create mode 100755 Plan Borg/bin/doprunes create mode 100755 Plan Borg/bin/doprunes2 create mode 100755 Plan Borg/bin/lastbackups create mode 100644 Plan Borg/models/model-conf-local.yaml create mode 100644 Plan Borg/models/model-conf-remote.yaml diff --git a/Plan Borg/README.md b/Plan Borg/README.md index 48b30e1..b2f54e8 100644 --- a/Plan Borg/README.md +++ b/Plan Borg/README.md @@ -38,10 +38,11 @@ Créer un dossier pour les scripts maison : mkdir -p ~borg/bin ``` -Copier les scripts utilitaires dans `~borg/bin/` : +Récupérer les scripts et modèles : ``` -cd ~borg/bin/ -git clone truc ou cp +cd ~borg/ +mkdir bin models +wget ``` 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` : ``` -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 : @@ -247,4 +248,27 @@ STU STU # Sauver les bases de données -STU \ No newline at end of file +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. +- \ No newline at end of file diff --git a/Plan Borg/bin/dobackup-local b/Plan Borg/bin/dobackup-local new file mode 100755 index 0000000..24f018c --- /dev/null +++ b/Plan Borg/bin/dobackup-local @@ -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 diff --git a/Plan Borg/bin/dobackup-remote b/Plan Borg/bin/dobackup-remote new file mode 100755 index 0000000..a50a9da --- /dev/null +++ b/Plan Borg/bin/dobackup-remote @@ -0,0 +1,33 @@ +#!/bin/bash + +help() +{ + echo "Usage: dobackup-remote [ -h | -help | --help | ]" + 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 + + + diff --git a/Plan Borg/bin/dobackup-rsync b/Plan Borg/bin/dobackup-rsync new file mode 100644 index 0000000..621dab5 --- /dev/null +++ b/Plan Borg/bin/dobackup-rsync @@ -0,0 +1,32 @@ +#!/bin/bash + +help() +{ + echo "Usage: dobackup-rsync [ -h | -help | --help | ]" + 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 + diff --git a/Plan Borg/bin/dobackups b/Plan Borg/bin/dobackups new file mode 100755 index 0000000..4436832 --- /dev/null +++ b/Plan Borg/bin/dobackups @@ -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 "================================================================================" diff --git a/Plan Borg/bin/doborgbackup b/Plan Borg/bin/doborgbackup deleted file mode 100644 index bae1152..0000000 --- a/Plan Borg/bin/doborgbackup +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -help() -{ - echo "Usage: doborgbackup [ -h | -help | --help | ]" -} - -# -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 diff --git a/Plan Borg/bin/doborgchecks b/Plan Borg/bin/doborgchecks deleted file mode 100644 index be65002..0000000 --- a/Plan Borg/bin/doborgchecks +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -help() -{ - echo "Usage: doborgchecks [ -h | -help | --help | ]" -} - -# -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 diff --git a/Plan Borg/bin/doborgenv b/Plan Borg/bin/doborgenv deleted file mode 100644 index efe1fbb..0000000 --- a/Plan Borg/bin/doborgenv +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -REPO_NAME="$1" -export BORG_REPOS="/var/backups/borg" -export BORG_REPO="${BORG_REPOS}/{REPO_NAME}.repo" diff --git a/Plan Borg/bin/dochecks b/Plan Borg/bin/dochecks new file mode 100755 index 0000000..b36d4b5 --- /dev/null +++ b/Plan Borg/bin/dochecks @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "================================================================================" +echo " Checks du "$(date) +echo "================================================================================" + +borgmatic check --verbosity 1 + +echo "=====" +echo "Ended at: "`date` +echo "================================================================================" diff --git a/Plan Borg/bin/dochecks2 b/Plan Borg/bin/dochecks2 new file mode 100755 index 0000000..d50e692 --- /dev/null +++ b/Plan Borg/bin/dochecks2 @@ -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 "================================================================================" diff --git a/Plan Borg/bin/doborginit b/Plan Borg/bin/doinit old mode 100644 new mode 100755 similarity index 59% rename from Plan Borg/bin/doborginit rename to Plan Borg/bin/doinit index c92903d..755f86a --- a/Plan Borg/bin/doborginit +++ b/Plan Borg/bin/doinit @@ -2,7 +2,8 @@ help() { - echo "Usage: dobackupinit [ -h | -help | --help | ]" + echo "Usage: doinit [ -h | -help | --help | ]" + echo "Init a borg repository." } # @@ -20,8 +21,9 @@ fi if (( $help )); then help else - REPO_NAME="$1" - BORG_REPOS="/var/backups/borg" + COMPUTER="$1" - borg init --encryption=repokey-blake2 ${BORG_REPOS}/${REPO_NAME}.repo + borgmatic -c /etc/borgmatic.d/${COMPUTER}.yaml init --encryption=repokey-blake2 fi + + diff --git a/Plan Borg/bin/doprunes b/Plan Borg/bin/doprunes new file mode 100755 index 0000000..96a0778 --- /dev/null +++ b/Plan Borg/bin/doprunes @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "================================================================================" +echo " Prunes du "$(date) +echo "================================================================================" + +borgmatic prune --stats --files --verbosity 1 + +echo "=====" +echo "Ended at: "`date` +echo "================================================================================" diff --git a/Plan Borg/bin/doprunes2 b/Plan Borg/bin/doprunes2 new file mode 100755 index 0000000..279b77e --- /dev/null +++ b/Plan Borg/bin/doprunes2 @@ -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 "================================================================================" diff --git a/Plan Borg/bin/lastbackups b/Plan Borg/bin/lastbackups new file mode 100755 index 0000000..3a5d4b0 --- /dev/null +++ b/Plan Borg/bin/lastbackups @@ -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 diff --git a/Plan Borg/models/cron b/Plan Borg/models/cron index 45f0629..e85b24d 100644 --- a/Plan Borg/models/cron +++ b/Plan Borg/models/cron @@ -1,2 +1,3 @@ -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 +10 0 * * * root /srv/borg/bin/dobackups >> /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 diff --git a/Plan Borg/models/excludes b/Plan Borg/models/excludes index 52a91e6..d14d55b 100644 --- a/Plan Borg/models/excludes +++ b/Plan Borg/models/excludes @@ -11,3 +11,4 @@ fm:*/cache2 fm:*/.davfs2 fm:*/.local/share/Trash fm:*/lost+found +fm:*/sharedfs | diff --git a/Plan Borg/models/model-conf-local.yaml b/Plan Borg/models/model-conf-local.yaml new file mode 100644 index 0000000..2a4603b --- /dev/null +++ b/Plan Borg/models/model-conf-local.yaml @@ -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 diff --git a/Plan Borg/models/model-conf-remote.yaml b/Plan Borg/models/model-conf-remote.yaml new file mode 100644 index 0000000..7103d09 --- /dev/null +++ b/Plan Borg/models/model-conf-remote.yaml @@ -0,0 +1,19 @@ +location: + source_directories: [] + + repositories: + - /var/backups/borg/.repo + +retention: + !include /etc/borgmatic/retention.yaml + +consistency: + checks: + - repository + - archives + +storage: + encryption_passcommand: 'cat /srv/borg/.borg-passphrase' + +output: + color: false diff --git a/Plan Borg/models/retention.yaml b/Plan Borg/models/retention.yaml index f0c7c05..f0d1b3e 100644 --- a/Plan Borg/models/retention.yaml +++ b/Plan Borg/models/retention.yaml @@ -1,6 +1,6 @@ - keep_within: 14d + keep_within: 3d keep_daily: 7 - keep_weekly: 12 - keep_monthly: 11 + keep_weekly: 8 + keep_monthly: 6 keep_yearly: -1 - prefix: '20' + prefix: '2'