-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudsync.sh
More file actions
executable file
·56 lines (47 loc) · 2.17 KB
/
Copy pathcloudsync.sh
File metadata and controls
executable file
·56 lines (47 loc) · 2.17 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
#!/usr/bin/env bash
# Get the location this script is running in
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
logsdir="$dir/logs"
log="$logsdir/output-$(date -u +'%Y%m%d').txt"
syncPrefix=".CloudSync_"
source "$dir/config.sh"
if [ ! -f "$dir/excludes.txt" ]; then
echo "Unable to find excludes.txt This is required for the script to run. Make sure it exists in the same directory as this script." | tee -a "$log"
exit 1
fi
if [ ! $(command -v duplicity) ]; then
echo "duplicity is required but is not installed! This is available via most package managers such as APT or Homebrew. Install and try again." | tee -a "$log"
exit 1
fi
if [ ! -f "$dir/config.sh" ]; then
echo "Unable to find $dir/config.sh. Make sure it exists and try again." | tee -a "$log"
exit 1
fi
export PASSPHRASE="$gpgEncryptionKeyPassphrase"
export SIGN_PASSPHRASE="$gpgEncryptionKeyPassphrase"
mkdir -vp "$logsdir"
echo "########################################################################" | tee -a "$log"
echo "$(date -u +'%Y-%m-%dT%H:%M:%SZ') Running cloud-sync" | tee -a "$log"
echo "$(date -u +'%Y-%m-%dT%H:%M:%SZ') Using bash version: $BASH_VERSION" | tee -a "$log"
$(ulimit -n 1024) | tee -a "$log"
for fIdx in "${!folders[@]}"; do
backupLocation="$(dirname ${folders[$fIdx]})/${syncPrefix}$(basename ${folders[$fIdx]})"
$(mkdir -vp "$backupLocation") | tee -a "$log"
duplicity \
--verbosity 9 \
--encrypt-key "$gpgDecryptionKeyId" \
--sign-key "$gpgEncryptionKeyId" \
--exclude-globbing-filelist "$dir/excludes.txt" \
"${folders[$fIdx]}" \
"file://${backupLocation}" \
| tee -a "$log"
for cIdx in "${!clouds[@]}"; do
if [ ! -d "${clouds[$cIdx]}/$(basename ${folders[$fIdx]})" ]; then
echo "$(date -u +'%Y-%m-%dT%H:%M:%SZ') Directory does not exist. Creating ${clouds[$cIdx]}/$(basename ${folders[$fIdx]})" | tee -a "$log"
mkdir -vp "${clouds[$cIdx]}/$(basename ${folders[$fIdx]})"
fi
echo "$(date -u +'%Y-%m-%dT%H:%M:%SZ') Syncing to cloud folder: ${clouds[$cIdx]}" | tee -a "$log"
rsync --delete -av "${backupLocation}"/** "${clouds[$cIdx]}/$(basename ${folders[$fIdx]})/" | tee -a "$log"
done
done
echo "$(date -u +'%Y-%m-%dT%H:%M:%SZ') Finished sync" | tee -a "$log"