Skip to content

Instantly share code, notes, and snippets.

@tiagocardosos
Last active December 5, 2017 12:54
Show Gist options
  • Save tiagocardosos/c1588c55660efd309695c5800bd6bb79 to your computer and use it in GitHub Desktop.
Save tiagocardosos/c1588c55660efd309695c5800bd6bb79 to your computer and use it in GitHub Desktop.
MySQL database backup (mysqldump) shell script
#!/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