backup script headless

This commit is contained in:
Eric Lay 2023-06-19 15:55:03 -05:00
parent 3c4b90b3eb
commit b17fcb4249
2 changed files with 15 additions and 13 deletions

24
backup
View File

@ -11,9 +11,10 @@ export BORG_PASSPHRASE=''
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
# some helpers and error handling: # some helpers and error handling:
infoLine() { printf "\n%s\n%s\n" "$( date +%H:%M:%S )" "$*" | tee -a "$logFile"; } logFile="/home/ez/.cache/logs/borg/$( date +%Y-%m-%d-%H:%M:%S )"
infoLine() { printf "%s\t%s\n" "$( date +%H:%M:%S )" "$*" | tee -a "$logFile"; }
seeLog() { printf "\n%s %s" "$*" "$logFile"; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
logFile="/home/ez/.cache/logs/borg/$( date +%Y-%m-%d-%H:%M:%S.%N )"
# Notify user of running backup # Notify user of running backup
notify() { notify() {
@ -30,11 +31,10 @@ notify() {
fi fi
} }
notify info "Starting backup to $BORG_REPO"
infoLine "Starting backup to $BORG_REPO"
# Backup the most important directories into an archive named after # Backup the most important directories into an archive named after
# the machine this script is currently running on: # the machine this script is currently running on:
notify info "Starting backup to $BORG_REPO"
infoLine "Starting backup to $BORG_REPO"
borg create \ borg create \
--verbose \ --verbose \
@ -76,13 +76,12 @@ borg create \
backup_exit=$? backup_exit=$?
notify info "Pruning repository: $BORG_REPO"
infoLine "Pruning repository: $BORG_REPO"
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-*' matching is very important to # archives of THIS machine. The '{hostname}-*' matching is very important to
# limit prune's operation to this machine's archives and not apply to # limit prune's operation to this machine's archives and not apply to
# other machines' archives also: # other machines' archives also:
notify info "Pruning repository"
infoLine "Pruning repository"
borg prune \ borg prune \
--list \ --list \
@ -98,8 +97,8 @@ prune_exit=$?
# actually free repo disk space by compacting segments # actually free repo disk space by compacting segments
notify info "Compacting repository: $BORG_REPO" notify info "Compacting repository"
infoLine "Compacting repository: $BORG_REPO" infoLine "Compacting repository"
borg compact 2>> "$logFile" borg compact 2>> "$logFile"
@ -111,13 +110,16 @@ global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit ))
if [ ${global_exit} -eq 0 ]; then if [ ${global_exit} -eq 0 ]; then
notify info "Backup, Prune, and Compact finished successfully to $BORG_REPO" notify info "Backup, Prune, and Compact finished successfully to $BORG_REPO"
infoLine "Backup, Prune, and Compact finished successfully to $BORG_REPO" infoLine "Backup, Prune, and Compact finished successfully"
seeLog "Log available:"
elif [ ${global_exit} -eq 1 ]; then elif [ ${global_exit} -eq 1 ]; then
notify info "Backup, Prune, and/or Compact finished with warnings" notify info "Backup, Prune, and/or Compact finished with warnings"
infoLine "Backup, Prune, and/or Compact finished with warnings" infoLine "Backup, Prune, and/or Compact finished with warnings"
seeLog "Check log for warnings:"
else else
notify info "Backup, Prune, and/or Compact finished with errors" notify info "Backup, Prune, and/or Compact finished with errors"
infoLine "Backup, Prune, and/or Compact finished with errors" infoLine "Backup, Prune, and/or Compact finished with errors"
seeLog "Check log for errors:"
fi fi
exit ${global_exit} exit ${global_exit}

View File

@ -11,7 +11,7 @@ export BORG_PASSPHRASE=''
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
# some helpers and error handling: # some helpers and error handling:
logFile="/home/ez/.cache/logs/borg/$( date +%Y-%m-%d-%H:%M:%S.%N )" logFile="/home/ez/.cache/logs/borg/$( date +%Y-%m-%d-%H:%M:%S )"
infoLine() { printf "%s\t%s\n" "$( date +%H:%M:%S )" "$*" | tee -a "$logFile"; } infoLine() { printf "%s\t%s\n" "$( date +%H:%M:%S )" "$*" | tee -a "$logFile"; }
seeLog() { printf "\n%s %s" "$*" "$logFile"; } seeLog() { printf "\n%s %s" "$*" "$logFile"; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM