2019-10-06 20:55:56 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# pass an arbitrary number of additional arguments to borg create by using
|
|
|
|
# borgbackup.sh $option1 $option2 ... $optionN
|
|
|
|
# pass -v --stats to show more information
|
|
|
|
# pass --list --filter AME to show all fiels Added Modified or with Error
|
|
|
|
|
2019-11-12 20:06:04 +00:00
|
|
|
export BORG_RSH='ssh -i {{ borgbackup_ssh_id }}'
|
|
|
|
export BORG_PASSPHRASE='{{ borgbackup_passphrase }}'
|
|
|
|
export BORG_REPO='{{ borgbackup_repo }}'
|
2019-10-06 20:55:56 +00:00
|
|
|
|
|
|
|
# some helpers and error handling:
|
|
|
|
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
|
|
|
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
|
|
|
|
|
|
|
|
|
|
|
|
# Backup the most important directories
|
|
|
|
borg create \
|
|
|
|
$@ \
|
|
|
|
--compression lz4 \
|
|
|
|
--exclude-caches \
|
|
|
|
--exclude '/home/*/.cache/*' \
|
|
|
|
--exclude '/var/run' \
|
|
|
|
--exclude '/var/cache/*' \
|
|
|
|
--exclude '/var/tmp/*' \
|
|
|
|
--exclude '/var/lib/apt/*' \
|
|
|
|
--exclude '/var/lib/dpkg/*' \
|
|
|
|
--exclude '/var/lib/yum/*' \
|
|
|
|
--exclude '/var/lib/docker/overlay2' \
|
|
|
|
--exclude '/var/lib/docker/containers' \
|
|
|
|
--exclude '/var/lib/docker/image' \
|
|
|
|
--exclude '/var/lib/docker/tmp' \
|
|
|
|
--exclude '/var/lib/lxcfs' \
|
|
|
|
--exclude '/var/log/*' \
|
|
|
|
\
|
2019-11-12 20:06:04 +00:00
|
|
|
$BORG_REPO::'{{ borgbackup_hostname }}-{now:%Y%m%d_%H%M}' \
|
2019-10-06 20:55:56 +00:00
|
|
|
/etc \
|
|
|
|
/var \
|
|
|
|
/root \
|
|
|
|
/home \
|
|
|
|
|
|
|
|
backup_exit=$?
|
|
|
|
|
|
|
|
|
2019-10-27 10:40:03 +00:00
|
|
|
# Prune old backups: keep 7 daily, 3 weekly and 2 monthly (3 months total)
|
2019-10-06 20:55:56 +00:00
|
|
|
borg prune \
|
2019-11-12 20:06:04 +00:00
|
|
|
--prefix '{{ borgbackup_hostname }}-' \
|
2019-10-06 20:55:56 +00:00
|
|
|
--keep-daily 7 \
|
2019-10-27 10:40:03 +00:00
|
|
|
--keep-weekly 3 \
|
|
|
|
--keep-monthly 2
|
2019-10-06 20:55:56 +00:00
|
|
|
|
|
|
|
prune_exit=$?
|
|
|
|
|
|
|
|
# use highest exit code as global exit code
|
|
|
|
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
|
|
|
|
|
|
|
|
if [ ${global_exit} -eq 1 ];
|
|
|
|
then
|
|
|
|
info "Backup and/or Prune finished with a warning"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${global_exit} -gt 1 ];
|
|
|
|
then
|
|
|
|
info "Backup and/or Prune finished with an error"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit ${global_exit}
|