-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·57 lines (46 loc) · 1.46 KB
/
backup.sh
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
#!/bin/sh
# Simple backup script
# Antti Laine <[email protected]>
#
# Not tested too well.
# Keep away from kittens and little children.
#
# Initial copy done with tar, because rsync sucks
# with huge amount of small files
# Here be settings
# ----------------
# Hostname of the remote machine to backup to.
# Use localhost when making a local copy
REMOTEHOST="localhost"
# Full directory path of the directory on the remote host to backup to.
# Must end with /
REMOTEDIR="/home/antti/backuptesti/backup/"
# List of directories to backup. Each directory must end with / (because: rsync)
BACKUPLIST="/home/antti/backuptesti/directory/"
# List of patterns for files and directories to exclude from the backup
#EXCLUDELIST="--exclude notthis --exclude northis"
EXCLUDELIST="--exclude antti/.VirtualBox --exclude antti/.wine"
# Magic begins. No touchy!
# ------------------------
current="$REMOTEDIR""current"
backup="$REMOTEDIR""backup-\$(stat -c %y $current)"
function show_help {
echo "Usage: backup.sh [-i]
-i Do initial copy"
}
function backup {
ssh "$REMOTEHOST" "cp -al \"$current\" \"$backup\""
rsync -azv --progress --delete --delete-excluded $EXCLUDELIST $BACKUPLIST "$REMOTEHOST":"$current"
}
function init {
tar -cv $EXCLUDELIST $BACKUPLIST | ssh "$REMOTEHOST" "tar --preserve-permissions --numeric-owner -xv -C \"$current\""
}
if test $# -eq 0; then
backup
else
if test "$*" == "-i"; then
init
else
show_help
fi
fi