Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide better naming with backuptarget=/ #32

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions acts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ for dir in $backuptargets; do
log_debug "message=\"Starting backup of $dir\""
archive_starttime=$(date +%s)
nicedirname=$(echo "$dir" | tr -d '/')
nicedirname=${nicedirname:+-nicedirname} # /foo -> -foo, / -> ''
# 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 All @@ -161,7 +162,7 @@ for dir in $backuptargets; do
archivetype="yearly"
fi
log_verbose "archive-type type=$archivetype"
archivename="$hostname-$archivetype-$today-$nicedirname"
archivename="$hostname-$archivetype-$today$nicedirname"
log_verbose "backup-start type=$archivetype dir=/$dir name=$archivename"
# Uncontrolled expansion is bad, but we have little choice. See https://github.com/koalaman/shellcheck/wiki/Sc2086
# shellcheck disable=SC2086
Expand All @@ -183,10 +184,11 @@ fi
for dir in $backuptargets; do
log_debug "message=\"Checking $dir for old backups to delete\""
nicedirname=$(echo "$dir" | tr -d '/')
nicedirname=${nicedirname:+-nicedirname} # /foo -> -foo, / -> ''
# 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 @@ -201,7 +203,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