backup script headless
This commit is contained in:
parent
3c4b90b3eb
commit
b17fcb4249
24
backup
24
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() {
|
||||
|
@ -30,11 +31,10 @@ notify() {
|
|||
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}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue