Ansible_workstation/files/choux_borg.sh

55 lines
1.2 KiB
Bash
Raw Normal View History

2018-08-25 06:47:57 +00:00
#!/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}
}
# 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/local_documents /home/"
2018-08-25 06:47:57 +00:00
ts_log "Starting new backup ${BACKUP_DATE}..."
ts_log "Pushing archive ${BORG_ARCHIVE}"
$BORG create \
-v --stats --compression none \
$BORG_ARCHIVE \
$BACKUPED_DIR \
--exclude 'lost+found' \
--exclude '/home/*/.cache' \
--exclude '/home/*/.ccache'
2018-08-25 06:47:57 +00:00
>> ${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"