Le Wiki de Tchack

Guides et documentation sur le serveur tchack.xyz

Outils pour utilisateurs

Outils du site


adminsys:script-save-auto-borg-vps
no way to compare when less than two revisions

Différences

Ci-dessous, les différences entre deux révisions de la page.


adminsys:script-save-auto-borg-vps [2019/02/25 16:09] (Version actuelle) – créée jaxom
Ligne 1: Ligne 1:
 +<file bash Auto-BorgBackup-VPS.sh>
 +#!/bin/bash
  
 +## Sauvegarde distante du VPS 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/borgRepoVPS/"
 +# Arrêt du rsync quotidien, pas de données critiques.
 +# Appel hebdomadaire par Cron.
 +
 +## Suivi ##
 +# 19-02-25 mise en place.
 +
 +#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"`
 +
 +
 +#Send an SMS notification using FreeMobileAPI
 +#curl --insecure "https://smsapi.free-mobile.fr/sendmsg?user=##REPLACEWITHYOURUSER##&pass=##REPLACEWITHYOURAPIKEY##&msg=AutoYNHBackup"
 +
 +## BORG Part ##
 +
 +# the envvar $REPONAME is something you should just hardcode
 +export REPOSITORY="/var/backups/borgRepoVPS"
 +# 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/.borgRepoVPS.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é --exclude-from=/usr/local/src/RsyncExclusions.txt 
 +rsync -azPvH --delete-during --bwlimit=2.1m $DossierLocal admin@cloudherve.myqnapcloud.com:$DossierDistant >> /var/log/rsyncNasHerve/rsync.log
 +
 +
 +#Confirmer par SMS
 +message="Auto-VPS "+`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
 +
 +
 +</file>
adminsys/script-save-auto-borg-vps.txt · Dernière modification : 2019/02/25 16:09 de jaxom