blob: 72c69c3fdf4dc5ed1a7047e22184d7631b2bcd7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/bin/sh
# Incremental backup using rsync(1).
[ "$USER" = root ] || exec sudo "$0" "$@"
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
(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))
[ "$1" ] && cmd=$1 && shift || cmd=""
case $cmd in
(""|save) backup ;;
(clean) exec backup-clean ${optv+-$optv} "$dest";;
(diff) exec diffdir "$@";;
esac
|