From b17fcb4249f9c7bd6448ea6dbd1b83b45698830e Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Mon, 19 Jun 2023 15:55:03 -0500 Subject: [PATCH] backup script headless --- backup | 26 ++++++++++++++------------ backup-headless | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/backup b/backup index f0a8a02..d7288ed 100755 --- a/backup +++ b/backup @@ -11,9 +11,10 @@ export BORG_PASSPHRASE='' export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes # 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 -logFile="/home/ez/.cache/logs/borg/$( date +%Y-%m-%d-%H:%M:%S.%N )" # Notify user of running backup notify() { @@ -28,13 +29,12 @@ notify() { notify-send -a 'luky-borg-backup' "$1" "$2" --icon=dialog-$dialog_kind done fi -} - -notify info "Starting backup to $BORG_REPO" -infoLine "Starting backup to $BORG_REPO" +} # Backup the most important directories into an archive named after # the machine this script is currently running on: +notify info "Starting backup to $BORG_REPO" +infoLine "Starting backup to $BORG_REPO" borg create \ --verbose \ @@ -76,13 +76,12 @@ borg create \ 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 # archives of THIS machine. The '{hostname}-*' matching is very important to # limit prune's operation to this machine's archives and not apply to # other machines' archives also: +notify info "Pruning repository" +infoLine "Pruning repository" borg prune \ --list \ @@ -98,8 +97,8 @@ prune_exit=$? # actually free repo disk space by compacting segments -notify info "Compacting repository: $BORG_REPO" -infoLine "Compacting repository: $BORG_REPO" +notify info "Compacting repository" +infoLine "Compacting repository" borg compact 2>> "$logFile" @@ -111,13 +110,16 @@ global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit )) if [ ${global_exit} -eq 0 ]; then 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 notify info "Backup, Prune, and/or Compact finished with warnings" infoLine "Backup, Prune, and/or Compact finished with warnings" + seeLog "Check log for warnings:" else notify info "Backup, Prune, and/or Compact finished with errors" infoLine "Backup, Prune, and/or Compact finished with errors" + seeLog "Check log for errors:" fi exit ${global_exit} diff --git a/backup-headless b/backup-headless index 2424975..87d6301 100755 --- a/backup-headless +++ b/backup-headless @@ -11,7 +11,7 @@ export BORG_PASSPHRASE='' export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes # 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"; } seeLog() { printf "\n%s %s" "$*" "$logFile"; } trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM