aboutsummaryrefslogtreecommitdiff
path: root/home/bin/backup-manual
blob: c11b06df4a4d1c8f36521a22c5283b781ec103af (plain) (blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -e

# source folder to back up, don't forget to add trailing slash
: ${BACKUPSOURCE:="/home/jodersky/"}

# backup root folder, i.e. the one that will contain all backups in separate sub-folders
: ${BACKUPCAPSULE:="/mnt/backup/backup/"}


#destination folder to back up to
destination="$BACKUPCAPSULE"/$(date +%Y-%m-%d_%H-%M-%S)

#symbolic link to latest backup (if any)
latest="$BACKUPCAPSULE/latest"

# rsync options
roptions=(
    -a
    -P
    --copy-unsafe-links
    --delete
    --delete-excluded
    --filter=": .rsyncignore"
)

# settings that are passed through arguments
init=0; # initialise new backup
dryrun=0; # perform a simulated run, don't backup any files

# process arguments
while [ $# -gt 0 ]
do
    if [ "$1" = "--init" ]; then
    	init=1
    elif [ "$1" = "-n" ]; then
    	dryrun=1
    else
    	echo "invalid argument: $1"
		exit 1
	fi
    shift
done

if [ $init -eq 0 ]; then
	roptions+=(--link-dest="$latest")
fi
if [ $dryrun -eq 1 ]; then
	roptions+=(-n)
	roptions+=(-vv)
fi

rsync "${roptions[@]}" "$BACKUPSOURCE" "$destination"

if [ $dryrun -eq 0 ]; then
	rm -f $latest
	ln -s "$destination" "$latest"
fi