-
Notifications
You must be signed in to change notification settings - Fork 0
/
gopro-backup-sync.sh
executable file
·65 lines (50 loc) · 1.07 KB
/
gopro-backup-sync.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
58
59
60
61
62
63
64
65
#!/bin/sh
while getopts ":s:d:e:" option; do
case $option in
s)
source="$OPTARG"
;;
d)
destination="$OPTARG"
;;
e)
event="$OPTARG"
;;
*)
echo "Usage: $0 [-s source] [-d destination] [-e event_name]"
exit 1
;;
esac
done
if [ -z "$event" ]; then
echo "No event provided. Please provide an event name using -e"
exit 1
fi
if ! [ -d "$source" ]; then
echo "Invalid source directory"
exit 1
fi
if ! [ -d "$destination" ]; then
echo "Invalid destination directory"
exit 1
fi
echo "Backing up $source to $destination/$event..."
trap "echo Exited!; exit;" SIGINT SIGTERM
MAX_RETRIES=50
i=0
# Set the initial return value to failure
false
finaldestination="$destination/$event"
mkdir "$finaldestination"
while [ $? -ne 0 -a $i -lt $MAX_RETRIES ]
do
i=$(($i+1))
rsync -avzs --progress --partial --append "$source/" "$finaldestination/"
done
if [ $i -eq $MAX_RETRIES ]
then
echo "Hit maximum number of retries, giving up."
else
echo "Finished backing up."
touch "$finaldestination.finished.txt"
fi