Backup MySQL

This is how I backup MySQL databases.

Solution consists of three files

Find complete solution here

The backup-db.sh is called every day with Parameter -b for backup and with parameter -c for cleanup. The backup routine dumps all MySQL databases into one file. TheĀ  cleanup routine removes old backups (older than 30 days, see LIMIT variable). The restore routine requires to hardcode a certain snapshot into the script. The variables.conf must be placed in same folder as backup-db.sh .

This is how the backup folder looks after running the script for 32 days at 23h.

20181009-023001.sql 20181020-023001.sql 20181031-023001.sql
20181010-023001.sql 20181021-023001.sql 20181101-023001.sql
20181011-023001.sql 20181022-023001.sql 20181102-023001.sql
20181012-023001.sql 20181023-023001.sql 20181103-023001.sql
20181013-023001.sql 20181024-023001.sql 20181104-023001.sql
20181014-023001.sql 20181025-023001.sql 20181105-023001.sql
20181015-023001.sql 20181026-023002.sql 20181106-023001.sql
20181016-023001.sql 20181027-023001.sql 20181107-023001.sql
20181017-023001.sql 20181028-023001.sql 20181108-023001.sql
20181018-023001.sql 20181029-023002.sql
20181019-023001.sql 20181030-023001.sql

The folder will contain backups for the last 31 days.

 

Leave a Reply