-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-Files.sh
executable file
·49 lines (45 loc) · 960 Bytes
/
backup-Files.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
#!/bin/bash
#
Print-Usage(){
printf %s\\n "Backup each input folde ror file, overwriting if existing \
to BackupPath/ using rsync with --delete."
printf "Usage: %s [-v] [-c] [-p <BackupPath>] [-e RemoteShell] PATH...\\n" "$0" >&2
exit 0
}
BackupPath="root@10.0.1.21:/Data/Backup/daily"
RemoteShell="ssh"
while getopts ":hvcp:e:" arg; do
case $arg in
h)
Print-Usage
;;
p)
BackupPath=${OPTARG}
;;
e)
RemoteShell=${OPTARG}
;;
v)
VERBOSE=1
;;
c)
CONTINUE=1
;;
\?)
Print-Usage
;;
esac
done
shift $((OPTIND-1))
Write-Verbose(){
[ "$VERBOSE" -eq 1 ] && echo "$@"
}
Write-Verbose "INFO: BackupPath = $BackupPath"
Write-Verbose "INFO: RemoteShell = $RemoteShell"
RETURN=0
for file in "$@"; do
rsync -e "$RemoteShell" -i -ahxHAX --delete "$file" "$BackupPath"/"$file"
RETURN=$?
[ "$RETURN" -ne 0 ] && [ "$FORCE" -ne 1 ] && exit "$RETURN"
done
exit "$RETURN"