summaryrefslogtreecommitdiff
path: root/bin/backup
blob: 3f1d586605146b5c431a6b6333878a374c188dc8 (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
#!/bin/sh

[ "$USER" = root ] || exec sudo "$0" "$@"

# incremental backup using rsync(1)

die() { echo "$0: fatal: $@" >&2; exit 1; }

#[ "$(id -u)" = 0 ] || die must run as root

while getopts :v opt; do
	case $opt in
	(v) optv=v ;;
	(*) echo "Usage: $0 [-v] [[host:]dir]"; 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
(2*) opt_link=--link-dest=../$last;;
(*) opt_link=;;
esac

rsync -DSHxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot $dest/$date