summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xremoveOldBackups.in32
1 files changed, 22 insertions, 10 deletions
diff --git a/removeOldBackups.in b/removeOldBackups.in
index 67d0828..c1602d2 100755
--- a/removeOldBackups.in
+++ b/removeOldBackups.in
@@ -7,26 +7,33 @@
usage () {
>&2 echo \
-'Usage: removeOldBackups
-Remove old backups keeping only one backup per month for all but the present year.
+'Usage: removeOldBackups [-n]
+Remove backups older than one year, keeping only one backup per month.
Options:
-#HELPTEXT# #'
+#HELPTEXT# #
+ -n only print what would be removed'
[ -n "$1" ] && exit $1
exit 1
}
+no_action=false
+
if [ $# -eq 1 ]
then
- if [ "$1" == "--help" ]
+ if [ "x$1" == 'x--help' ]
then
usage 0
- elif [ "$1" == "--version" ]
+ elif [ "x$1" == 'x--version' ]
then
>&2 echo '#VERSION#'
exit 0
+ elif [ "x$1" == 'x-n' ]
+ then
+ no_action=true
+ else
+ usage
fi
- usage
elif [ $# -gt 1 ]
then
usage
@@ -53,14 +60,19 @@ backups=$(
sort -k5,5 -k4,4 -k3,3 -k2,2 -k1,1 | \
uniq -f2
printf '%s\n' "${backups}" | \
- sed '
- / '"$(date +%Y)"' \S\+$/p
- '
+ sed "$(
+ for dist in $(seq 0 20 365); do
+ printf '/ %s \S\+$/p\n' \
+ "$(date '+%m %Y' -d@$(($(date +%s)-24*60*60*${dist})))"
+ done
+ )"
} | \
cut -d' ' -f1 | \
sort | \
uniq -u | \
while read -r dir; do
echo rm -rf --one-file-system "${dir}"
- rm -rf --one-file-system "${dir}"
+ if ! ${no_action}; then
+ rm -rf --one-file-system "${dir}"
+ fi
done