add dijkstra backup script
This commit is contained in:
parent
c1c20ee5d0
commit
0bd1a7f039
|
@ -0,0 +1,79 @@
|
|||
#!/bin/sh
|
||||
|
||||
backup_key="${HOME}/.ssh/backup"
|
||||
prune_key="${HOME}/.ssh/prune"
|
||||
backup_host="luca@server155.tralios.de"
|
||||
# shellcheck disable=SC2088
|
||||
repo="~/backup/dijkstra"
|
||||
# shellcheck disable=SC2155
|
||||
export BORG_PASSPHRASE="$(cat "${HOME}"/.secrets/borg)"
|
||||
export BORG_REPO="ssh://${backup_host}:22/${repo}"
|
||||
export BORG_RSH="ssh -i ${backup_key}"
|
||||
|
||||
echo >"${XDG_DATA_HOME}/backup.log"
|
||||
exec >>"${XDG_DATA_HOME}/backup.log" 2>&1
|
||||
|
||||
max() {
|
||||
printf "%s\n" "$@" | sort -nr | head -n1
|
||||
}
|
||||
|
||||
info() {
|
||||
[ "$1" = "-e" ] && {
|
||||
shift
|
||||
notify-send -u critical Backupper "$*"
|
||||
}
|
||||
printf "\n%s %s\n\n" "$(date)" "$*"
|
||||
}
|
||||
trap 'echo $(date) Backup interrupted >&2; exit 2' INT TERM
|
||||
|
||||
info "Starting backup"
|
||||
|
||||
borg create \
|
||||
--verbose \
|
||||
--filter AME \
|
||||
--list \
|
||||
--stats \
|
||||
--show-rc \
|
||||
--compression lz4 \
|
||||
--exclude-caches \
|
||||
--exclude "${XDG_CACHE_HOME}/*" \
|
||||
--exclude "${XDG_STATE_HOME}/*" \
|
||||
--exclude "${XDG_CONFIG_HOME}/borg/*" \
|
||||
--exclude "${XDG_CONFIG_HOME}/chromium/*" \
|
||||
--exclude "${XDG_DATA_HOME}/Trash/*" \
|
||||
--exclude "${XDG_DATA_HOME}/zsh/history" \
|
||||
--exclude "${XDG_DATA_HOME}/backup.log" \
|
||||
--exclude "${HOME}/.secrets/*" \
|
||||
--exclude "${HOME}/.mozilla/firefox/*" \
|
||||
--exclude "${HOME}/.thunderbird/*" \
|
||||
::'{hostname}-{now}' \
|
||||
"${HOME}"
|
||||
|
||||
backup_exit=$?
|
||||
|
||||
info "Pruning repository"
|
||||
|
||||
# shellcheck disable=SC2029
|
||||
echo "${BORG_PASSPHRASE}" | ssh \
|
||||
-o "IdentitiesOnly=yes" \
|
||||
-i "${prune_key}" \
|
||||
"${backup_host}" \
|
||||
false # This command is ignored but must be set
|
||||
|
||||
prune_exit=$?
|
||||
|
||||
info "Compacting repository"
|
||||
|
||||
borg compact
|
||||
|
||||
compact_exit=$?
|
||||
|
||||
global_exit=$(max $backup_exit $prune_exit $compact_exit)
|
||||
|
||||
case ${global_exit} in
|
||||
0) info "Backup, Prune, and Compact finished successfully" ;;
|
||||
1) info -e "Backup, Prune, and/or Compact finished with warnings" ;;
|
||||
*) info -e "Backup, Prune, and/or Compact finished with errors" ;;
|
||||
esac
|
||||
|
||||
exit "${global_exit}"
|
Loading…
Reference in New Issue