-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·69 lines (52 loc) · 1.19 KB
/
run
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/bash -e
if [ -z "$TIMEOUT" ] ; then
TIMEOUT=86400
fi
if [ -z "$DBHOST" ] ; then
echo "DBHOST not specified"
exit 1
fi
if [ -z "$DBPORT" ] ; then
echo "DBPORT not specified"
exit 1
fi
if [ -z "$DBUSER" ] ; then
echo "DBUSER not specified"
exit 1
fi
if [ -z "$DBPASS" ] ; then
echo "DBPASS not specified"
exit 1
fi
if [ -z "$AWS_ACCESS_KEY_ID" ] ; then
echo "AWS_ACCESS_KEY_ID not specified"
exit 1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ] ; then
echo "AWS_SECRET_ACCESS_KEY not specified"
exit 1
fi
if [ -z "$BUCKET" ] ; then
echo "BUCKET not specified"
exit 1
fi
DATADIR="/data"
backup_and_stream_to_s3() {
while true
do
echo "Clean"
rm -rf /backup/*
echo "Backup"
innobackupex --defaults-file=/app/my.cnf --host=$DBHOST --port=$DBPORT --user=$DBUSER --password=$DBPASS /backup
BACKUP=`ls /backup`
innobackupex --defaults-file=/app/my.cnf --apply-log /backup/$BACKUP
tar -cf /backup/$BACKUP.tar /backup/$BACKUP
gzip -7 /backup/$BACKUP.tar
echo "Upload $BACKUP"
aws s3 cp "/backup/$BACKUP.tar.gz" $BUCKET/$BACKUP.tar.gz
echo "Sleep"
sleep $TIMEOUT
done
}
backup_and_stream_to_s3
wait