55 lines
1.3 KiB
Bash
55 lines
1.3 KiB
Bash
|
#!/bin/sh
|
||
|
#
|
||
|
# Script de sauvegarde.
|
||
|
#
|
||
|
# Envoie les sauvegardes sur un serveur distant, via le programme borg.
|
||
|
# Les sauvegardes sont chiffrées
|
||
|
#
|
||
|
# http://borgbackup.readthedocs.or/g
|
||
|
#
|
||
|
# Est lancé quotidiennement.
|
||
|
|
||
|
set -e
|
||
|
|
||
|
ts_log()
|
||
|
{
|
||
|
echo `date '+%Y-%m-%d %H:%m:%S'` $1 >> ${LOG_PATH}
|
||
|
su {{ me[0].username }} -c "DISPLAY=:0 notify-send 'Borgbackup' '`date '+%Y-%m-%d %H:%m:%S'`' $1"
|
||
|
# su lafrite -c "DISPLAY=:0 notify-send 'Borgbackup' '`date '+%Y-%m-%d %H:%m:%S'` $1'"
|
||
|
}
|
||
|
|
||
|
# Trap on non-zero exit
|
||
|
# trap '[ "$?" -eq 0 ] || cleanup' EXIT
|
||
|
|
||
|
BACKUP_DATE=`date +%Y-%m-%d`
|
||
|
LOG_PATH=/var/log/borg-backup.log
|
||
|
|
||
|
BORG=/usr/bin/borg
|
||
|
# Fichier dans lequel est stocké la passphrase du dépôt borg
|
||
|
# (attention aux permissions)
|
||
|
export BORG_PASSPHRASE="`cat /root/.borg/passphrase`"
|
||
|
BORG_REPOSITORY={{ borg_backup_repo }}
|
||
|
# BORG_REPOSITORY=/media/backup/Choux
|
||
|
BORG_ARCHIVE=${BORG_REPOSITORY}::${BACKUP_DATE}
|
||
|
|
||
|
BACKUPED_DIR="/media/documents /home/"
|
||
|
|
||
|
ts_log "Starting new backup ${BACKUP_DATE}..."
|
||
|
|
||
|
ts_log "Pushing archive ${BORG_ARCHIVE}"
|
||
|
$BORG create \
|
||
|
-v --stats --compression none \
|
||
|
$BORG_ARCHIVE \
|
||
|
$BACKUPED_DIR
|
||
|
-e 'lost+found'
|
||
|
>> ${LOG_PATH} 2>&1
|
||
|
|
||
|
ts_log "Rotating old backups."
|
||
|
$BORG prune -v $BORG_REPOSITORY \
|
||
|
--keep-daily=7 \
|
||
|
--keep-weekly=4 \
|
||
|
--keep-monthly=6 \
|
||
|
>> ${LOG_PATH} 2>&1
|
||
|
|
||
|
ts_log "Backup done"
|