Le Wiki de Tchack

Guides et documentation sur le serveur tchack.xyz

Outils pour utilisateurs

Outils du site


adminsys:script-save-auto-borg-rpi

Ceci est une ancienne révision du document !


#!/bin/bash

## Sauvegarde distante via un Borg local puis rsync du repo## # Auteur : Jaxom jaxom@tchack.xyz # Credits to https://blog.andrewkeech.com/posts/170719_borg.html # and https://jstaf.github.io/2018/03/12/backups-with-borg-rsync.html # Repo initialement créé avec “borg init –encryption=repokey /var/backups/borgRepoRPi/” # Exclure le repo du rsync quotidien via “RsyncExclusions.txt”

## Suivi ## # 19-02-25 Ca marche mais ne backup que les fichiers YNH-auto, notamment sans les data Nextcloud. # 19-05-14 Ajout etape Nextcloud suite a changement gestion Backup_core_only # 19-07-07 Debug suite a verrouillage de mi-juin et absence de rsync distant.

#identifiants pour transmission des SMS via FreeMobile user=“” pass=“”

## AUTO Part ## #From @djib https://forum.yunohost.org/t/sauvegardes-automatiques-a-j-1-j-7-et-j-30/6495 #Modified by @jaxom on 2018-12-19 #Licenced under GPL. https://www.gnu.org/licenses/gpl.html

#GOAL: Creates a backup and removes some of the previous backups #HOWTO: call it via cron as frequently as you want

# Backups are created with the following prefix PREFIX=“auto-” # All backups with the previous prefix are deleted except the following dates TODAY=`date '+%Y-%m-%d'` LAST_WEEK=`date -d “7 days ago” '+%Y-%m-%d'` BEGINNING_OF_MONTH=`date '+%Y-%m-01'` BEGINNING_OF_LAST_MONTH=`date -d “last month” '+%Y-%m-01'`

#separation between apps, config and Nextcloud without data export BACKUP_CORE_ONLY=0 yunohost backup create -n $PREFIX$TODAY-core –system yunohost backup create -n $PREFIX$TODAY-apps –apps `yunohost app list -i | grep id| sed 's/id: ' | sed 's/nextcloud' | tr -d '\n'`

#New management of data-only backups by Yunohost, see https://yunohost.org/#/backup_fr export BACKUP_CORE_ONLY=1 yunohost backup create -n $PREFIX$TODAY-apps-NC –apps nextcloud

#Removal of old backups cd /home/yunohost.backup/archives rm `ls | grep $PREFIX | grep -v “$TODAY\|$LAST_WEEK\|$BEGINNING_OF_MONTH\|$BEGINNING_OF_LAST_MONTH”`

## BORG Part ##

# the envvar $REPONAME is something you should just hardcode export REPOSITORY=“/var/backups/borgRepoRPi” # Fill in your password file here, borg picks it up automatically #https://borgbackup.readthedocs.io/en/stable/faq.html#how-can-i-specify-the-encryption-passphrase-programmatically #export BORG_PASSCOMMAND=“cat /root/.borgRepoRpi.passphrase” export BORG_PASSPHRASE=“”

# Dossier à sauvegarder DossierLocal=$REPOSITORY #Dossier de sauvegarde sur le NAS DossierDistant=/share/homes/Elias/

#Créer une sauvegarde borg create $REPOSITORY::$TODAY /home/yunohost.backup/archives/auto-*

# Reset en cas d'erreur if [ “$?” = “1” ] ; then

  export BORG_PASSPHRASE=""
  exit 1

fi

#Pruner le repo borg prune -v –list –stats –keep-weekly=4 –keep-monthly=-1 $REPOSITORY » /var/log/rsyncNasHerve/rsync-borg.log

#Transférer le repo actualisé rsync -azPvH –delete-during –bwlimit=2.1m $DossierLocal admin@NASHerve:$DossierDistant » /var/log/rsyncNasHerve/rsync-borg.log

#Confirmer par mail

#Confirmer par SMS message=“RPi borg ”+`date +%Y-%m-%d_%H:%M:%S` curl -s -i -k “https://smsapi.free-mobile.fr/sendmsg?user=$user&pass=$pass&msg=$message”

# Reset le password Borg #export BORG_PASSCOMMAND=“” export BORG_PASSPHRASE=“” exit 0

adminsys/script-save-auto-borg-rpi.1562610967.txt.gz · Dernière modification : 2019/07/08 20:36 de jaxom