2024-09-26 08:10:02 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Account on spmt-backup
|
|
|
|
SPMT_USER=hpcjgrac
|
|
|
|
|
|
|
|
# Which directories should be backed up
|
|
|
|
# INCLUDE_BACKUP_DIRS=($HOME/delme $HOME/bin) # note: these are bsh arrays, keep the braces and escape spaces if necessary
|
|
|
|
INCLUDE_BACKUP_DIRS=($HOME)
|
|
|
|
# and which should not
|
|
|
|
# EXCLUDE_BACKUP_DIRS=($HOME/delme)
|
|
|
|
EXCLUDE_BACKUP_DIRS=($HOME/Library/Thunderbird/Profiles/ $HOME/delme $HOME/Downloads/ $HOME/Sync $HOME/work/ChEESE_audits $HOME/work/spack)
|
|
|
|
|
|
|
|
# Retention policies, how many daily, weekly, monthly backups to keep.
|
|
|
|
KEEP_DAILY=7
|
|
|
|
KEEP_WEEKLY=4
|
|
|
|
KEEP_MONTHLY=12
|
|
|
|
KEEP_YEARLY=-1 # never delete yearly backups
|
|
|
|
|
2024-09-26 08:43:12 +00:00
|
|
|
# Create file with borg repo passphrase: `echo "MY SUPER PASSPHRASE" | base64 > $HOME/.borg_passphrase`
|
2024-09-26 08:10:02 +00:00
|
|
|
export BORG_PASSCOMMAND="base64 -d $HOME/.borg_passphrase"
|
|
|
|
# or use BORG_PASSPHRASE below.
|
|
|
|
|
|
|
|
# See the section "Passphrase notes" for more infos.
|
|
|
|
# export BORG_PASSPHRASE='XYZl0ngandsecurepa_55_phrasea&&123'
|
|
|
|
|
|
|
|
|
2024-09-26 08:43:12 +00:00
|
|
|
#################################################################
|
|
|
|
#### Nothing else to be done below! Change at your onw risk. ####
|
2024-09-26 08:10:02 +00:00
|
|
|
|
|
|
|
export BORG_REPO=ssh://spmt-backup/storage/backup/repos/${SPMT_USER}
|
|
|
|
|
|
|
|
# some helpers and error handling:
|
|
|
|
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
|
|
|
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
|
|
|
|
|
|
|
|
info "Starting backup"
|
|
|
|
|
|
|
|
EXCLUDE_FROM=$(mktemp tmp.borg_dayly.XXXXX)
|
|
|
|
#EXCLUDE_FROM=tmp.borg_dayly
|
|
|
|
trap 'echo "Removing temporary files"; rm ${EXCLUDE_FROM}' EXIT
|
|
|
|
for d in "${EXCLUDE_BACKUP_DIRS[@]}"; do
|
|
|
|
echo ${d} >> ${EXCLUDE_FROM}
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Backup the most important directories into an archive named after
|
|
|
|
# the machine this script is currently running on
|
|
|
|
|
|
|
|
borg create \
|
|
|
|
--verbose \
|
|
|
|
--filter AME \
|
|
|
|
--list \
|
|
|
|
--stats \
|
|
|
|
--show-rc \
|
|
|
|
--compression lz4 \
|
|
|
|
--exclude-caches \
|
|
|
|
--exclude-from ${EXCLUDE_FROM} \
|
|
|
|
::'{hostname}-{now}' \
|
|
|
|
${INCLUDE_BACKUP_DIRS}
|
|
|
|
|
|
|
|
|
|
|
|
# Prune old backups and compact repo
|
|
|
|
|
|
|
|
borg prune \
|
|
|
|
--stats --verbose --list \
|
|
|
|
--keep-daily=${KEEP_DAILY} \
|
|
|
|
--keep-weekly=${KEEP_WEEKLY} \
|
|
|
|
--keep-monthly=${KEEP_MONTHLY} \
|
|
|
|
--keep-yearly=${KEEP_YEARLY}
|
|
|
|
|
|
|
|
borg compact \
|
|
|
|
--verbose
|