-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-backup.s3
executable file
·61 lines (43 loc) · 1.62 KB
/
db-backup.s3
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
#!/bin/sh
# This file is executed from crontab after the db-backup.batch has been run
# NOTE: Only the short-term backup purges the source dir;
# run the long-term backup in cron before the short-term one!
#
# NOTE: 'longterm' arg triggers the long-term backup
ARGV="$@"
#### EDIT ###########################################################
BAKROOTPATH=/bak
# Backups in S3STANDBYPATH are always the latest compressed
# full database dumps. These can be copied as-is to a bucket with
# a lifecycle policy.
S3STANDBYPATH=${BAKROOTPATH}/s3-standby
# Target dir in S3
BUCKETDIR=my-target-dir-name-here
if [ "${ARGV}" = "longterm" ] ; then
S3TARGETPATH=s3://my-db-backups-exppol/${BUCKETDIR}
else
S3TARGETPATH=s3://my-db-backups-shortterm-exppol/${BUCKETDIR}
fi
#####################################################################
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
LOG=/var/log/db-backup.log
exec 3>&1 1>>${LOG} 2>&1
echo -----
echo `date` `tty` $*
type s3cmd > /dev/null 2>&1 || { echo "I require s3cmd but it's not installed. Aborting." | tee /dev/fd/3; exit 1; }
if [ ! -d ${S3STANDBYPATH} ] ; then
echo "S3 Standby Directory does not exist. Aborting." | tee /dev/fd/3
exit 1
fi
if [ ! "$(ls -A $S3STANDBYPATH)" ] ; then
echo "S3 Standby Directory is empty; nothing to copy. Aborting." | tee /dev/fd/3
exit 1
fi
s3cmd -e put ${S3STANDBYPATH}/* ${S3TARGETPATH}/
echo Compressed backup dumps copied to S3 at ${S3TARGETPATH}
if [ ! "${ARGV}" = "longterm" ] ; then
rm -rf ${S3STANDBYPATH}/*
echo S3 standby directory \(${S3STANDBYPATH}\) purged.
fi
exit 0