Skip to content

Commit

Permalink
Add option to call tarsnap with a function
Browse files Browse the repository at this point in the history
  • Loading branch information
wraugh committed Dec 16, 2019
1 parent 6d00964 commit 7ea84cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions acts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ lockfile="${lockfile=/var/run/acts}"
dailybackups="${dailybackups:=31}"
monthlybackups="${monthlybackups:=12}"
yearlybackups="${yearlybackups:=0}"
type calltarsnap >/dev/null 2>&1 || calltarsnap() { $tarsnap "$@"; }
LANG="${LANG=en_US.UTF-8}"
export LANG

Expand Down Expand Up @@ -166,7 +167,7 @@ prettyprint() {

# PART 2: Preparation
log_debug "Listing tarsnap archives before creating backups"
if ! archives_unsorted=$($tarsnap --list-archives); then
if ! archives_unsorted=$(calltarsnap --list-archives); then
die "acts-tarsnap-error message=\"Couldn't get list of existing archives (Hint: is Tarsnap configured correctly?)\""
exit 1
fi
Expand Down Expand Up @@ -205,7 +206,7 @@ for dir in $backuptargets; do
log_verbose "backup-start type=daily dir=/$dir name=$dailyarchive"
# Uncontrolled expansion is bad, but we have little choice. See https://github.com/koalaman/shellcheck/wiki/Sc2086
# shellcheck disable=SC2086
if output="$($tarsnap -c -f "$dailyarchive" -C / $tarsnapbackupoptions "$dir" 2>&1)"; then
if output="$(calltarsnap -c -f "$dailyarchive" -C / $tarsnapbackupoptions "$dir" 2>&1)"; then
backuplist="$backuplist $dailyarchive"
else
log_output=$(prettyprint log_output "$output")
Expand All @@ -222,7 +223,7 @@ for dir in $backuptargets; do
log_debug "message=\"Copying $logdirname daily archive to yearly archive\""
archive_starttime=$(date +%s)
# shellcheck disable=SC2086
if output="$($tarsnap -c -f "$yearlyarchive" $tarsnapbackupoptions "@@$dailyarchive" 2>&1)"; then
if output="$(calltarsnap -c -f "$yearlyarchive" $tarsnapbackupoptions "@@$dailyarchive" 2>&1)"; then
backuplist="$backuplist $yearlyarchive"
else
log_output=$(prettyprint log_output "$output")
Expand All @@ -238,7 +239,7 @@ for dir in $backuptargets; do
log_debug "message=\"Copying $logdirname daily archive to monthly archive\""
archive_starttime=$(date +%s)
# shellcheck disable=SC2086
if output="$($tarsnap -c -f "$monthlyarchive" $tarsnapbackupoptions "@@$dailyarchive" 2>&1)"; then
if output="$(calltarsnap -c -f "$monthlyarchive" $tarsnapbackupoptions "@@$dailyarchive" 2>&1)"; then
backuplist="$backuplist $yearlyarchive"
else
log_output=$(prettyprint log_output "$output")
Expand All @@ -251,7 +252,7 @@ for dir in $backuptargets; do
done
# Update the archive listing
log_debug "Listing tarsnap archives before deleting old backups"
archives=$($tarsnap --list-archives | sort -n)
archives=$(calltarsnap --list-archives | sort -n)

# PART 4: Trim old backups.
if [ "$backuprc" != "0" ]; then
Expand All @@ -270,7 +271,7 @@ prune_backups() {
log_verbose "message=\"Deleting backup prefix $archiveprefixtodel*\""
echo "$archives" | grep -E "^$archiveprefixtodel" | while read -r archivetodel; do
log_debug "message=\"Deleting backup $archivetodel\""
if ! output="$($tarsnap -d -f "$archivetodel" 2>&1)"; then
if ! output="$(calltarsnap -d -f "$archivetodel" 2>&1)"; then
log_output=$(prettyprint log_output "$output")
log_message "delete-error type=$backuplevel output=\"$log_output\""
fi
Expand Down
7 changes: 7 additions & 0 deletions acts.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
# Default: unset
tarsnapbackupoptions="--one-file-system --humanize-numbers"

# calltarsnap
# The function that invokes the tarsnap command.
# It will receive command line parameters for tarsnap as arguments.
# Use this when you need to run tarsnap in a pipeline.
# Default: calltarsnap() { $tarsnap "$@"; }
#calltarsnap() { pass show tarsnap-passphrase | $tarsnap --passphrase-stdin "$@" }

# verbose
# Log verbosity. Output is written to stderr.
# -1 silent. 0=normal. 1=verbose. 2=debug.
Expand Down

0 comments on commit 7ea84cc

Please sign in to comment.