aboutsummaryrefslogtreecommitdiff
path: root/cleaner.in
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-05-29 13:02:40 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-05-29 13:02:40 +0300
commitd669127d2efaf9969b081fbaff47ff8938388750 (patch)
tree1bcfab0a932b717284e67f957deb8506229ac4be /cleaner.in
parent8ceb3484f218d25e025deb618ae3d202e2599dab (diff)
downloadbeam-d669127d2efaf9969b081fbaff47ff8938388750.tar.gz
beam-d669127d2efaf9969b081fbaff47ff8938388750.tar.bz2
Rename project to BEAM (Backup Easy And Manageable).
Diffstat (limited to 'cleaner.in')
-rwxr-xr-xcleaner.in73
1 files changed, 73 insertions, 0 deletions
diff --git a/cleaner.in b/cleaner.in
new file mode 100755
index 0000000..c89511f
--- /dev/null
+++ b/cleaner.in
@@ -0,0 +1,73 @@
+#! /bin/sh
+
+libdir=@LIBDIR@/beam
+set -e
+. $libdir/common.sh
+set +e
+
+dir=
+suffix=
+retainweeks=3
+dry_run=
+verbose=:
+
+help() {
+ cat <<EOF
+usage: $0 [OPTIONS] DIR
+cleans up old backup files in DIR
+
+OPTIONS are:
+ -s, --suffix SUF consider only file names ending in SUF
+ -r, --retain N retain N last weeks of backups (default $retainweeks)
+ -v, --verbose verbosely list what is being done
+ -n, --dry-run do nothing, print what would have been done
+ -h, --help print this help list
+
+EOF
+ exit 0
+}
+
+while [ $# -ne 0 ]
+do
+ case $1 in
+ -s|--suffix) shift; suffix=$1;;
+ -r|--retain) shift; retainweeks=$1;;
+ -v|--verbose) verbose=echo;;
+ -n|--dry-run) dry_run=echo; verbose=echo;;
+ -h|--help) help;;
+ --wtf) wtf $(basename $0) clean up old files; exit 0;;
+ --) shift; break;;
+ -*) echo >&2 "$0: unrecognized option $1"
+ exit 1;;
+ *) break
+ esac
+ shift
+done
+
+case $# in
+0) echo >&2 "$0: not enough arguments"
+ exit 1;;
+1) dir=$1;;
+*) echo >&2 "$0: too many arguments"
+ exit 1;;
+esac
+
+thisweek=$(date +%U)
+lastweek=$((thisweek - retainweeks))
+
+$verbose \# removing files older than week $lastweek
+
+if [ -z "$suffix" ]; then
+ find $dir -type f -printf '%f\n'
+else
+ find $dir -type f -name "*$suffix" -printf '%f\n'
+fi |
+ while read name
+ do
+ $verbose \# considering $name
+ week=$(expr "$name" : '[^-][^-]*-\([0-9][0-9]*\)-.*')
+ if [ $week -le $lastweek ]; then
+ $verbose \# removing $name
+ $dry_run rm $dir/$name
+ fi
+ done

Return to:

Send suggestions and report system problems to the System administrator.