1
0
Fork 0

backup: add (redacted) secret

This commit is contained in:
Luca Bilke 2024-10-16 19:42:04 +02:00
commit 27d3394d19

View file

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