Created
November 29, 2013 22:31
-
-
Save rzbrk/7712809 to your computer and use it in GitHub Desktop.
Performs mysql backup (via mysql_dump). The database password is retrieved from /etc/mysql/debian.cnf. Therefore, run this script as root
This file contains 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_conf_file="/etc/mysql/debian.cnf" | |
mysqldump_opts="--all-databases --events --add-drop-table --add-locks --create-options --disable-keys --lock-tables --quick --set-charset" | |
now=$(date '+%Y%m%d-%H%M%S') | |
#Extract password for MySQL user debian-sys-maint from /etc/mysql/debian.cnf. Two | |
#code lines are necessary to cope with files that include to identical lines | |
#defining the password | |
temp=$(cat $mysql_conf_file | grep "password =" | sed -e '{:q;N;s/\n/ /g;t q}') | |
password=$(echo $temp | sed -e 's/.*\n//;s/password = //g;s/.* //') | |
# Create MySQL dump | |
dfile=~/mysql_backup_$HOSTNAME"_"$now.sql.gz | |
mysqldump $mysqldump_opts -u debian-sys-maint -p$password | gzip > $dfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment