mirror of
https://github.com/ChrisSewell/MySQL-backup-to-Amazon-S3.git
synced 2025-07-01 18:47:26 -04:00
made the script more generic to allow different databases to be backed up and be named as custom file name
This commit is contained in:
14
mysqltos3.sh
14
mysqltos3.sh
@ -6,7 +6,9 @@
|
|||||||
# change these variables to what you need
|
# change these variables to what you need
|
||||||
MYSQLROOT=root
|
MYSQLROOT=root
|
||||||
MYSQLPASS=password
|
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/
|
# 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=
|
MYSQLDUMPPATH=
|
||||||
|
|
||||||
@ -17,12 +19,12 @@ echo "Selected period: $PERIOD."
|
|||||||
echo "Starting backing up the database to a file..."
|
echo "Starting backing up the database to a file..."
|
||||||
|
|
||||||
# dump all databases
|
# 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 "Done backing up the database to a file."
|
||||||
echo "Starting compression..."
|
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."
|
echo "Done compressing the backup file."
|
||||||
|
|
||||||
@ -37,12 +39,12 @@ echo "Past backup moved."
|
|||||||
|
|
||||||
# upload all databases
|
# upload all databases
|
||||||
echo "Uploading the new backup..."
|
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 "New backup uploaded."
|
||||||
|
|
||||||
echo "Removing the cache files..."
|
echo "Removing the cache files..."
|
||||||
# remove databases dump
|
# remove databases dump
|
||||||
rm ~/all-databases.sql
|
rm ~/${FILENAME}.sql
|
||||||
rm ~/all-databases.tar.gz
|
rm ~/${FILENAME}.tar.gz
|
||||||
echo "Files removed."
|
echo "Files removed."
|
||||||
echo "All done."
|
echo "All done."
|
Reference in New Issue
Block a user