From 1640ef083eae13d4f776648579c5c309e384e24b Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Mon, 27 Jun 2011 14:55:44 +1000 Subject: [PATCH] Initial attempt at an S3 upload post-backup script. It works out what to do based on the same logic as the main script and uploads the files to a named bucket and optional folder. --- s3-upload.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 s3-upload.sh diff --git a/s3-upload.sh b/s3-upload.sh new file mode 100755 index 0000000..1ce0358 --- /dev/null +++ b/s3-upload.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +PATH="/opt/local/bin:${PATH}" + +S3CMD="`which s3cmd`" + +if [ -z "$S3CMD" ]; then + echo "s3cmd command not found." + exit 1 +fi + +BUCKET="s3://" +BUCKETFOLDER="" + +# Test is seperate DB backups are required +if [ "${SEPDIR}" = "yes" ]; then + # Monthly Full Backup of all Databases + if [ ${DOM} = "01" ]; then + for MDB in ${MDBNAMES} + do + FILE="monthly/${MDB}/${MDB}_${DATE}.${M}.${MDB}.sql${SUFFIX}" + ${S3CMD} put "${BACKUPDIR}/${FILE}" "${BUCKET}${BUCKETFOLDER}/${FILE}" + done + fi + + for DB in ${DBNAMES} + do + # Prepare ${DB} for using + DB="`${ECHO} ${DB} | ${SED} 's/%/ /g'`" + + # Weekly Backup + if [ ${DNOW} = ${DOWEEKLY} ]; then + FILE="weekly/${DB}/${DB}_week.${W}.${DATE}.sql${SUFFIX}" + ${S3CMD} put "${BACKUPDIR}/${FILE}" "${BUCKET}${BUCKETFOLDER}/${FILE}" + # Daily Backup + else + FILE="daily/${DB}/${DB}_${DATE}.${DOW}.sql${SUFFIX}" + echo "Uploading daily ${FILE}" + ${S3CMD} put "${BACKUPDIR}/${FILE}" "${BUCKET}${BUCKETFOLDER}/${FILE}" + fi + done +else # One backup file for all DBs + # Monthly Full Backup of all Databases + if [ ${DOM} = "01" ]; then + FILE="monthly/${DATE}.${M}.all-databases.sql${SUFFIX}" + ${S3CMD} put "${BACKUPDIR}/${FILE}" "${BUCKET}${BUCKETFOLDER}/${FILE}" + fi + + # Weekly Backup + if [ ${DNOW} = ${DOWEEKLY} ]; then + FILE="weekly/week.${W}.${DATE}.sql${SUFFIX}" + ${S3CMD} put "${BACKUPDIR}/${FILE}" "${BUCKET}${BUCKETFOLDER}/${FILE}" + + # Daily Backup + else + FILE="daily/${DATE}.${DOW}.sql${SUFFIX}" + ${S3CMD} put "${BACKUPDIR}/${FILE}" "${BUCKET}${BUCKETFOLDER}/${FILE}" + fi +fi + +exit 0