-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync_backups_to_dropbox.sh
executable file
·55 lines (45 loc) · 1.37 KB
/
sync_backups_to_dropbox.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
#!/bin/bash
# Sync Backups to Dropbox
#
# Sync local backups to a Dropbox account
#
# @author Connor Bär
# @copyright Copyright (c) 2017 Connor Bär
# @link https://madebyconnor.co/
# @package wordpress-scripts
# @since 1.0.0
# @license MIT
# Get the directory of the currently executing script
DIR="$(dirname "${BASH_SOURCE[0]}")"
# Include files
INCLUDE_FILES=(
"common/defaults.sh"
".env.sh"
"common/common_env.sh"
)
for INCLUDE_FILE in "${INCLUDE_FILES[@]}"
do
if [ -f "${DIR}/${INCLUDE_FILE}" ]
then
source "${DIR}/${INCLUDE_FILE}"
else
echo "File ${DIR}/${INCLUDE_FILE} is missing, aborting."
exit 1
fi
done
# Set the compressed backup file name
BACKUP_FILE_NAME="backup-$(date '+%Y%m%d-%H%M%S').tar.gz"
# Make sure the local backup directory exists
if [[ ! -d "${LOCAL_BACKUPS_PATH}" ]] ; then
echo "Creating backup directory ${LOCAL_BACKUPS_PATH}"
mkdir -p "${LOCAL_BACKUPS_PATH}"
fi
# Archive and compress the local backup directory
tar -zcf "${BACKUP_FILE_NAME}" "${LOCAL_BACKUPS_PATH}"
# Upload the compressed backup to the Dropbox backup directory
dbxcli put "${BACKUP_FILE_NAME}" "${REMOTE_DROPBOX_PATH}${BACKUP_FILE_NAME}"
# Clean up the compressed backup file
rm -f "${BACKUP_FILE_NAME}"
echo "*** Synced backups to ${REMOTE_DROPBOX_PATH}"
# Normal exit
exit 0