Created
February 20, 2009 16:58
-
-
Save dstrelau/67564 to your computer and use it in GitHub Desktop.
mysql backups with duplicity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE USER 'backup'@'localhost'; | |
GRANT SELECT, LOCK TABLES ON *.* TO 'backup'@'localhost'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export AWS_ACCESS_KEY_ID="XXX" | |
export AWS_SECRET_ACCESS_KEY="XXX" | |
AWS_BUCKET='XXX' | |
GPG_KEY="XXX" | |
DUPLICITY='/usr/bin/duplicity' | |
ARCHIVE_DIR='/var/cache/duplicity' | |
## DO NOT EDIT BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ## | |
S3_DEST="s3+http://${AWS_BUCKET}/" | |
ARGS="--encrypt-key=${GPG_KEY} --archive-dir=${ARCHIVE_DIR}" | |
mkdir -p ${ARCHIVE_DIR} | |
case "$1" in | |
'--backup') | |
if [ -n "${2}" ]; then | |
${DUPLICITY} ${ARGS} "${2}" "${S3_DEST}" | |
else | |
echo "usage: ${0} --backup source" | |
fi | |
;; | |
'--full') | |
if [ -n "${2}" ]; then | |
${DUPLICITY} full ${ARGS} "${2}" "${S3_DEST}" | |
else | |
echo "usage: ${0} --full source" | |
fi | |
;; | |
'--incremental') | |
if [ -n "${2}" ]; then | |
${DUPLICITY} incremental ${ARGS} "${2}" "${S3_DEST}" | |
else | |
echo "usage: ${0} --incremental source" | |
fi | |
;; | |
'--remove') | |
if [ -n "${2}" ]; then | |
${DUPLICITY} remove-older-than --force ${ARGS} "${2}" "${S3_DEST}" | |
else | |
echo "usage: ${0} --remove time" | |
fi | |
;; | |
'restore') | |
if [ -n "${2}" ]; then | |
${DUPLICITY} remove-older-than --force ${ARGS} "${S3_DEST}" "${2}" | |
else | |
echo "usage: ${0} --restore destination" | |
fi | |
;; | |
'--list') | |
${DUPLICITY} list-current-files ${ARGS} "${S3_DEST}" | |
;; | |
'--status') | |
${DUPLICITY} collection-status ${ARGS} "${S3_DEST}" | |
;; | |
*) | |
echo "$0 [--backup|--full|--incremental] source" | |
echo "$0 --remove time" | |
echo "$0 --restore destination" | |
echo "$0 [--list|--status]" | |
;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
case "$1" in | |
'--full') | |
FILE="/tmp/$(date +%s).sql" && | |
mysqldump -u backup --all-databases > ${FILE} && | |
/usr/local/bin/duplicity_ctl --full ${FILE} && | |
rm -f ${FILE} | |
;; | |
'--incremental') | |
FILE="/tmp/$(date +%s).sql" && | |
mysqldump -u backup --all-databases > ${FILE} && | |
/usr/local/bin/duplicity_ctl --backup ${FILE} && | |
rm -f ${FILE} | |
;; | |
'--remove') | |
/usr/local/bin/duplicity_ctl --remove 1M | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# min hour day month weekday user cmd | |
0 0 * * * root /usr/local/bin/mysql_backup --incremental > /dev/null 2>&1 | |
5 0 * * 0 root /usr/local/bin/mysql_backup --full > /dev/null 2>&1 | |
10 0 1 * 0 root /usr/local/bin/mysql_backup --remove > /dev/null 2>&1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment