Last active
December 5, 2017 12:54
-
-
Save tiagocardosos/c1588c55660efd309695c5800bd6bb79 to your computer and use it in GitHub Desktop.
MySQL database backup (mysqldump) shell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#mysql_config_editor set --login-path=local --host=localhost --user=username --password | |
echo "$(date +'%Y%m%d %k%M%S'): Starting daily backup." >> dump.log | |
echo "SET autocommit=0; | |
SET unique_checks=0; | |
SET foreign_key_checks=0;" > /root/backup.sql | |
#bkp mysql | |
/usr/bin/mysqldump --login-path=local --databases my_db >> /root/backup.sql | |
echo "SET autocommit=1; | |
SET unique_checks=1; | |
SET foreign_key_checks=1; | |
COMMIT;" >> /root/backup.sql | |
name=bkp_$(date +'%Y%m%d').tar.gz | |
/usr/bin/tar vcfz $name backup.sql | |
echo "$(date +'%Y%m%d %k%M%S'): Finished daily backup." >> dump.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment