-
Notifications
You must be signed in to change notification settings - Fork 8
/
backup.sh
executable file
·34 lines (26 loc) · 871 Bytes
/
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
#!/bin/bash
# Generate a (gzipped) dumpfile for each database specified in ${DBS}.
# Upload to S3.
. /etc/container_environment.sh
# Bailout if any command fails
set -e
# Create a temporary directory to hold the backup files.
DIR=$(mktemp -d)
# Generate a timestamp to name the backup files with.
TS=$(date +%s)
# Backup all databases, unless a list of databases has been specified
if [ -z "$DBS" ]
then
# Backup all DB's in bulk
mysqldump -uroot -p$MYSQL_ENV_MYSQL_ROOT_PASSWORD -hmysql --all-databases | gzip > $DIR/all-databases-$TS.sql.gz
else
# Backup each DB separately
for DB in $DBS
do
mysqldump -uroot -p$MYSQL_ENV_MYSQL_ROOT_PASSWORD -hmysql -B $DB | gzip > $DIR/$DB-$TS.sql.gz
done
fi
# Upload the backups to S3 --region=$REGION
s3cmd --access_key=$ACCESS_KEY --secret_key=$SECRET_KEY --region=$REGION sync $DIR/ $BUCKET
# Clean up
rm -rf $DIR