Saturday, July 25, 2015

MySQL backup database to a compressed GZIP and with date and time in file name

How to backup a MySQL database to a compressed zip file with current date and time

mysqldump -u {username} -p{password} {database} | gzip -9 - > /{target_directory}/{sub_dir}/{dbname}-`date '+\%Y_\%m_\%d-\%H_\%M'`.sql.gz



To Restore (decompress zip and restore to MySQL)

gunzip < some-backup-file.gz | mysql -u {username} -p{password}


No comments:

Post a Comment