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 !


Auto-BorgBackup-RPi.sh
#!/bin/bash
 
## Sauvegarde distante via un Borg local ##
# 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.
 
#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 and config
 
yunohost backup create -n $PREFIX$TODAY-core --system
yunohost backup create -n $PREFIX$TODAY-apps --apps
 
#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::{now} /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-daily=7 --keep-weekly=4 --keep-monthly=-1 $REPOSITORY
 
#Transférer le repo actualisé
rsync -azPvH --delete-during --bwlimit=2.1m $DossierLocal admin@cloudherve.myqnapcloud.com:$DossierDistant >> /var/log/rsyncNasHerve/rsync.log
 
#Confirmer par mail
 
#Confirmer par SMS
message="Auto-RPi "+`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.1551107250.txt.gz · Dernière modification : 2019/02/25 16:07 de jaxom