summaryrefslogtreecommitdiff
path: root/bin/backup
diff options
context:
space:
mode:
Diffstat (limited to 'bin/backup')
-rwxr-xr-xbin/backup37
1 files changed, 25 insertions, 12 deletions
diff --git a/bin/backup b/bin/backup
index 4ef83be..d56ee7f 100755
--- a/bin/backup
+++ b/bin/backup
@@ -3,21 +3,34 @@
[ "$USER" = root ] || exec sudo "$0" "$@"
-while getopts :v opt; do
+backup() {
+ date=$(date +%Y%m%d_%H%M%S)
+ last=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tail -1)
+
+ case $last in
+ ([12]*) opt_link=--link-dest=../$last;;
+ (*) opt_link=;;
+ esac
+
+ rsync -HSxa$optv --exclude-from=$ignore $opt_link / /boot "$dest/$date"
+}
+
+dest=/.history
+ignore=/etc/backup/ignore
+
+while getopts :d:i:nv opt; do
case $opt in
- (v) eval "opt$opt=$opt" ;;
- (*) echo "Usage: $0 [-v] [[host:]dir]"; exit 1 ;;
+ (d) dest="$OPTARG" ;;
+ (i) ignore="$OPTARG" ;;
+ (n|v) optv="$opt$optv" ;;
+ (*) echo "Usage: $0 [-nv] [-d [host:]dir] [clean|diff]"; exit 1 ;;
esac
done
shift $((OPTIND - 1))
-dest=${1:-/.history}
-date=$(date +%Y%m%d_%H%M%S)
-last=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tail -1)
-
-case $last in
-([12]*) opt_link=--link-dest=../$last;;
-(*) opt_link=;;
+[ "$1" ] && cmd=$1 && shift || cmd=""
+case $cmd in
+(""|save) backup ;;
+(clean) exec backup-clean ${optv+-$optv} "$@" "$dest";;
+(diff) exec diffdir "$@";;
esac
-
-rsync -HSxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot "$dest/$date"