Automate backup with cron
This commit is contained in:
parent
a1192d707b
commit
091cc575ef
54
files/choux_borg_cron.sh
Normal file
54
files/choux_borg_cron.sh
Normal file
@ -0,0 +1,54 @@
|
||||
#!/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"
|
@ -1,6 +0,0 @@
|
||||
---
|
||||
- name: Install borgbackup
|
||||
pacman:
|
||||
name: borg
|
||||
state: present
|
||||
|
15
tasks/choux_borg_backup.yml
Normal file
15
tasks/choux_borg_backup.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Install borgbackup
|
||||
pacman:
|
||||
name: borg
|
||||
state: present
|
||||
|
||||
- name: Automate toward local RAID backup with cron.daily
|
||||
template:
|
||||
src: files/choux_borg_cron.sh
|
||||
dest: /etc/cron.daily/
|
||||
mode: 755
|
||||
|
||||
|
||||
|
||||
|
@ -2,3 +2,6 @@
|
||||
|
||||
deploy_public_key: files/id_ed25519_home.pub
|
||||
|
||||
borg_backup_repo: /media/backup/Choux
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user