forked from mohamnag/docker-s3-dir-backup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
backup.sh
31 lines (22 loc) · 1.07 KB
/
backup.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
#!/bin/bash
COMPARE_DIR="/compare_dir/"
echo "backup started at $(date +%Y-%m-%d_%H:%M:%S)"
echo "creating archive..."
# this has to be executed like this, because we have two level expansion in variables
eval "export BACKUP_DST_FULL_PATH=${BACKUP_TGT_DIR}${BACKUP_FILE_NAME}.tar.gz"
eval "export COMPARE_DST_FULL_PATH=${COMPARE_DIR}${BACKUP_FILE_NAME}.tar.gz"
BACKUP_DST_DIR=$(dirname "${BACKUP_DST_FULL_PATH}")
mkdir -p ${COMPARE_DIR}
echo "Gzipping ${BACKUP_SRC_DIR} into ${COMPARE_DST_FULL_PATH}"
tar -czf ${COMPARE_DST_FULL_PATH} --exclude-tag-all=exclude_dir_from_backup -C ${BACKUP_SRC_DIR} .
if cmp -s -i 8 "$BACKUP_DST_FULL_PATH" "$COMPARE_DST_FULL_PATH"
then
echo "Archive is the same of the old one, do nothing."
else
echo "Archive is different from the old one, uploading to s3..."
mkdir -p ${BACKUP_DST_DIR}
mv "$COMPARE_DST_FULL_PATH" "$BACKUP_DST_FULL_PATH"
#echo "archive created, uploading..."
/usr/local/bin/aws s3 sync ${BACKUP_TGT_DIR} s3://${BACKUP_S3_BUCKET} --region ${AWS_DEFAULT_REGION}
fi
echo "backup finished at $(date +%Y-%m-%d_%H:%M:%S)"