From a0a8de23ae7ba3ba34d16feb3f60e591ceec0549 Mon Sep 17 00:00:00 2001 From: Tim Eggert Date: Tue, 15 May 2012 13:14:52 +0300 Subject: [PATCH] made the script more generic to allow different databases to be backed up and be named as custom file name --- mysqltos3.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mysqltos3.sh b/mysqltos3.sh index b043efa..ec092f2 100644 --- a/mysqltos3.sh +++ b/mysqltos3.sh @@ -6,7 +6,9 @@ # change these variables to what you need MYSQLROOT=root MYSQLPASS=password -S3BUCKET=my-db-backup-bucket +S3BUCKET=bucketname +FILENAME=filename +DATABASE='--all-databases' # when running via cron, the PATHs MIGHT be different. If you have a custom/manual MYSQL install, you should set this manually like MYSQLDUMPPATH=/usr/local/mysql/bin/ MYSQLDUMPPATH= @@ -17,12 +19,12 @@ echo "Selected period: $PERIOD." echo "Starting backing up the database to a file..." # dump all databases -${MYSQLDUMPPATH}mysqldump --quick --user=${MYSQLROOT} --password=${MYSQLPASS} --all-databases > ~/all-databases.sql +${MYSQLDUMPPATH}mysqldump --quick --user=${MYSQLROOT} --password=${MYSQLPASS} ${DATABASE} > ~/${FILENAME}.sql echo "Done backing up the database to a file." echo "Starting compression..." -tar czf ~/all-databases.tar.gz ~/all-databases.sql +tar czf ~/${FILENAME}.tar.gz ~/${FILENAME}.sql echo "Done compressing the backup file." @@ -37,12 +39,12 @@ echo "Past backup moved." # upload all databases echo "Uploading the new backup..." -s3cmd put -f ~/all-databases.tar.gz s3://${S3BUCKET}/${PERIOD}/ +s3cmd put -f ~/${FILENAME}.tar.gz s3://${S3BUCKET}/${PERIOD}/ echo "New backup uploaded." echo "Removing the cache files..." # remove databases dump -rm ~/all-databases.sql -rm ~/all-databases.tar.gz +rm ~/${FILENAME}.sql +rm ~/${FILENAME}.tar.gz echo "Files removed." echo "All done." \ No newline at end of file