Skip to content

Commit

Permalink
Added debug logging at the start of the backup and deletion loops.
Browse files Browse the repository at this point in the history
Added '$' to the end of the grep statements to enhance safety

Removed extra blank line
  • Loading branch information
shortchanged13 committed Feb 8, 2019
1 parent 559ffa3 commit fb0a7af
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions acts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ fi
# PART 3: Backup
backuprc=0 # Notice any failed backups
for dir in $backuptargets; do
log_debug "message=\"Starting backup of $dir\""
archive_starttime=$(date +%s)
nicedirname=$(echo "$dir" | tr -d '/')
# Determine the archive type to create
if echo "$archives" | grep -E -q "^$hostname-yearly-$year-.+-$nicedirname"; then
if echo "$archives" | grep -E -q "^$hostname-monthly-$year-$month-.+-$nicedirname"; then
if echo "$archives" | grep -E -q "^$hostname-yearly-$year-.+-$nicedirname$"; then
if echo "$archives" | grep -E -q "^$hostname-monthly-$year-$month-.+-$nicedirname$"; then
# There's a yearly and monthly backup already
archivetype="daily"
else
Expand Down Expand Up @@ -179,13 +180,13 @@ if [ "$backuprc" != "0" ]; then
die "acts-tarsnap-error One of the backups failed -- not deleting old backups"
fi


for dir in $backuptargets; do
log_debug "message=\"Checking $dir for old backups to delete\""
nicedirname=$(echo "$dir" | tr -d '/')
# We don't delete any yearly backups

# We keep 12 monthly backups
monthlybackups=$(echo "$archives" | grep "$hostname-monthly-.+-$nicedirname" | sort -rn)
monthlybackups=$(echo "$archives" | grep "$hostname-monthly-.+-$nicedirname$" | sort -rn)
if [ "$(echo "$monthlybackups" | wc -l)" -gt 12 ]; then
log_debug 'message="More than 12 monthly backups, deleting the oldest"'
echo "$monthlybackups" | tail -n +13 | while read -r archiveprefixtodel; do
Expand All @@ -200,7 +201,7 @@ for dir in $backuptargets; do
fi

# We keep 31 daily backups
dailybackups=$(echo "$archives" | grep "$hostname-daily-.+-$nicedirname" | sort -rn)
dailybackups=$(echo "$archives" | grep "$hostname-daily-.+-$nicedirname$" | sort -rn)
if [ "$(echo "$dailybackups" | wc -l)" -gt 31 ]; then
log_debug "message=\"More than 30 daily backups, deleting the oldest\""
echo "$dailybackups" | tail -n +32 | while read -r archiveprefixtodel; do
Expand Down

0 comments on commit fb0a7af

Please sign in to comment.