This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-backup.sh
69 lines (55 loc) · 1.5 KB
/
run-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
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
66
67
68
69
#!/bin/sh -xe
#
# main entry point to run s3cmd
#
S3CMD_PATH=/opt/s3cmd/s3cmd
#
# Check for required parameters
#
if [ -z "${aws_key}" ]; then
echo "The environment variable aws_key is not set. Attempting to create empty creds file to use role."
aws_key=""
fi
if [ -z "${aws_secret}" ]; then
echo "The environment variable aws_secret is not set."
aws_secret=""
security_token=""
fi
if [ -z "${DEST_S3}" ]; then
echo "The environment variable DEST_S3 is not set."
aws_secret=""
security_token=""
fi
#
# Replace key and secret in the /.s3cfg file with the one the user provided
#
echo "" >> ${PROJECT_PATH}/s3cfg
echo "access_key = ${aws_key}" >> ${PROJECT_PATH}/s3cfg
echo "secret_key = ${aws_secret}" >> ${PROJECT_PATH}/s3cfg
if [ -z "${security_token}" ]; then
echo "security_token = ${aws_security_token}" >> ${PROJECT_PATH}/s3cfg
fi
#
# Add region base host if it exist in the env vars
#
if [ "${s3_host_base}" != "" ]; then
sed -i "s/host_base = s3.amazonaws.com/# host_base = s3.amazonaws.com/g" ${PROJECT_PATH}/s3cfg
echo "host_base = ${s3_host_base}" >> /.s3cfg
fi
#
# Create and archive of current rancher-data and use current date and time as it's PROJECT_NAME
#
ARCHIVE_NAME=$(date '+%Y-%m-%d-%H:%M:%S')
tar -zcvf ~/$ARCHIVE_NAME.tar.gz ~/rancher-data
#
# Upload to S3
#
${S3CMD_PATH} --config=${PROJECT_PATH}/s3cfg sync ~/$ARCHIVE_NAME.tar.gz ${DEST_S3}
#
# Remove uploaded archive from container
#
rm -f ~/$ARCHIVE_NAME.tar.gz
#
# Finished operations
#
echo "Done!"