-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackupto-remote
More file actions
executable file
·69 lines (59 loc) · 1.91 KB
/
Copy pathbackupto-remote
File metadata and controls
executable file
·69 lines (59 loc) · 1.91 KB
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
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# backup selected directories/files to remote host,
# config file as argument
#
# $1 settings file
#
# the config file shall contain the variables:
#
# SRC_PATH_ABS absolute path to the files to backup, e.g. $HOME
# BACKUP_LIST list of files/directories to backup,
# the list may contain # comments and empty lines
# EXCLUDES_LIST list containing excludes, acc. to rsync --exclude-from
#
# BACKUP_PREFIX backups will be in the form of PREFIX_DATE_TIME
# DEST_PATH destination path, can be relative
#
# REMOTE_HOST remote hostname/ip addr.
# REMOTE_USER remote username to use for login
#
# ADD_RSYNC_OPTS additional rsync options, e.g. used -R used for system backup
#
#
# using rsync (incremental)
# reference:
# - http://www.ibm.com/developerworks/aix/library/au-spunix_rsync/index.html#backup
# found on: https://wiki.archlinux.org/index.php/Backup_programs
#
# includes
. common_f
check_config_arg "$1"
source "$1"
check_config_opts
DATE=$(date "+%Y-%m-%d_%H:%M:%S")
echo "Backup start: $DATE"
# temporary preprocessed list file
TMP_LIST="/tmp/backup-${BACKUP_PREFIX}-remote-TMP.list"
preprocess_list
# incremental backup
# --link-dest: if relative path, it's relative to the destination dir (!)
rsync -av -r --numeric-ids --link-dest=../"$BACKUP_PREFIX"_last \
--files-from="$TMP_LIST" \
--exclude-from="$EXCLUDES_LIST" \
$ADD_RSYNC_OPTS \
"$SRC_PATH_ABS" \
"$REMOTE_USER"@"$REMOTE_HOST":"$DEST_PATH"/"$BACKUP_PREFIX"_"$DATE"
# exit on failure
if [[ "$?" -ne 0 ]]; then
echo "A failure occured during rsync, exiting."
rm "$TMP_LIST"
exit 1
fi
# cleanup
rm "$TMP_LIST"
# relink last
# (rm needed or it goes into the link to create new one)
ssh "$REMOTE_USER"@"$REMOTE_HOST" rm "$DEST_PATH"/"${BACKUP_PREFIX}_last"
ssh "$REMOTE_USER"@"$REMOTE_HOST" ln -s "${BACKUP_PREFIX}_${DATE}" "$DEST_PATH"/"${BACKUP_PREFIX}_last"
echo "Backup end."