From 2522f701cc35893860230b5d69d86db25d2ddf06 Mon Sep 17 00:00:00 2001 From: Fabio Woxxy Date: Sat, 17 Sep 2011 18:52:16 +0200 Subject: [PATCH] Moved some things into variables --- README.md | 6 ++++-- mysqltos3.sh | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6b7a0b6..a92de8d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ woxxy / MySQL-backup-to-Amazon-S3 ================================= +(This is not really an application, just a manual and some lines of code) + Amazon S3 can be an interestingly safe and cheap way to store your important data. Some of the most important data in the world is saved in... MySQL, and surely mine is quite important, so I needed such a script. If you have a 500mb database (that's 10 times larger than any small site), with the priciest plan, keeping 6 backups (two months, two weeks, two days) costs $0.42 a month ($0.14GB/month). With 99.999999999% durability and 99.99% availability. Uploads are free, downloads would happen only in case you actually need to retrieve the backup (which hopefully won't be needed, but first GB is free, and over that $0.12/GB). @@ -25,13 +27,13 @@ Setup s3cmd --configure -5. Make a bucket +5. Make a bucket (must be an original name, s3cmd will tell you if it's already used) s3cmd mb s3://my-database-backups 6. Put the mysqltos3.sh file somewhere in your server, like `/home/youruser` 7. Give the file 755 permissions `chown 755 /home/youruser/mysqltos3.sh` or via FTP -8. Edit the mysqldump line in mysqltos3.sh with your MySQL root credentials +8. Edit the variables near the top of the mysqltos3.sh file to match your bucket and MySQL authentication Now we're set. You can use it manually: diff --git a/mysqltos3.sh b/mysqltos3.sh index 8e1bbc1..4c8df80 100644 --- a/mysqltos3.sh +++ b/mysqltos3.sh @@ -3,8 +3,12 @@ # Updates etc at: https://github.com/woxxy/MySQL-backup-to-Amazon-S3 # Under a MIT license +MYSQLROOT=root +MYSQLPASS=password +S3BUCKET=mybucket + # dump all databases -mysqldump --quick --user=youruser --password=yourpassword --single-transaction --all-databases > ~/all-databases.sql +mysqldump --quick --user=${MYSQLROOT} --password=${MYSQLPASS} --single-transaction --all-databases > ~/all-databases.sql if [ $1 != month ] then @@ -20,11 +24,11 @@ else fi # we want at least two backups, two months, two weeks, and two days -s3cmd del --recursive s3://my-database-backups/previous_${PERIOD}/ -s3cmd mv --recursive s3://my-database-backups/${PERIOD}/ s3://FoOlDB/previous_${PERIOD}/ +s3cmd del --recursive s3://${S3BUCKET}/my-database-backups/previous_${PERIOD}/ +s3cmd mv --recursive s3://${S3BUCKET}/${PERIOD}/ s3://${S3BUCKET}/previous_${PERIOD}/ # upload all databases -s3cmd put -f ~/all-databases.sql s3://my-database-backups/${PERIOD}/ +s3cmd put -f ~/all-databases.sql s3://${S3BUCKET}/${PERIOD}/ # remove databases dump rm ~/all-databases.sql \ No newline at end of file