-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumples
executable file
·49 lines (39 loc) · 1.1 KB
/
dumples
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
#!/bin/sh
USERNAME=''
PASSWORD=''
DATABASE=${1:-''}
DESTINATION=${2:-''}
if [ ! -w "${DESTINATION}" ]; then
>&2 echo "Destination ${DESTINATION} is not accessible for writing"
>&2 echo "Aborting..."
exit 1
fi
if ! command -v mysqldump > /dev/null; then
>&2 echo "It looks like mysqldump is not available"
>&2 echo "Aborting..."
exit 1
fi
if ! command -v gzip > /dev/null; then
>&2 echo "It looks like gzip is not available"
>&2 echo "Aborting..."
exit 1
fi
DATE=`date +%Y%m%d`
if ! mysqldump -u ${USERNAME} -p${PASSWORD} ${DATABASE} | gzip > ${DESTINATION}/${DATABASE}-${DATE}.sql.gz; then
>&2 echo "Gzip failed"
>&2 echo "Aborting..."
exit 1
fi
find ${DESTINATION} -maxdepth 1 -type f -name "${DATABASE}-*.sql.gz" -mtime +14 -execdir rm '{}' \;
#exit 0
if ! command -v zcat > /dev/null; then
>&2 echo "It looks like zcat is not available"
>&2 echo "Aborting..."
exit 2
fi
DATE_COMPLETED=`date +%Y-%m-%d`
if ! zcat ${DESTINATION}/${DATABASE}-${DATE}.sql.gz | tail -1 | grep "Dump completed.*${DATE_COMPLETED}" >/dev/null; then
>&2 echo "There may be a problem with the compressed dump"
exit 2
fi
exit 0