Backup MySql

Give permissions for every database to the backup user (you might not need lock tables).

GRANT SELECT, LOCK TABLES ON *.* 
     TO backupuser@host IDENTIFIED BY 'password';
dbUser=
dbHost=
dbPass=
 
for db in $(mysql --user=$dbUser --host=$dbHost \
                  --password=$dbPass -Bse 'show databases')
do
   backupFile=sql/$db.$(date +%F)-$(date +"%T").sql.gz
   mysqldump --add-drop-database --user=$dbUser \
             --host=$dbHost --password=$dbPass  \
             $db | gzip -9 > $backupFile
done

Leave a Reply

Your email address will not be published. Required fields are marked *