Moved some things into variables

This commit is contained in:
Fabio Woxxy
2011-09-17 18:52:16 +02:00
parent 9c3316f1f2
commit 2522f701cc
2 changed files with 12 additions and 6 deletions

View File

@ -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:

View File

@ -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