Percona’s XtraBackup is really good solution for incremental backups if small or large MySQL/MariaDB databases. Mysqldump is really slow and is not downtimeless.
In our case, we need two week history of every day. Every Sunday the backup will be full and the rest of the days, backups will be incremental, based on Sunday’s full backup. The backups will be placed in a folder named current_week. Every Sunday, the folder will be renamed to last_week and new, empty current_week will be created before the full backup.

Here is the script:

It “wants” the day of the week as the first parameter, and the mysql password as a second parameter, like this:

1
2
./backup-mysql.sh Sunday 12345
./backup-mysql.sh Monday 12345

Put it in /usr/local/bin/backup-mysql for example and make it executable. Here is an example cron config, running every day at 2:00 AM:

1
2
3
4
5
6
7
0 2 * * 0 /usr/local/bin/backup-mysql Sunday 12345 >/dev/null 2>&1
0 2 * * 1 /usr/local/bin/backup-mysql Monday 12345 >/dev/null 2>&1
0 2 * * 2 /usr/local/bin/backup-mysql Tuesday 12345 >/dev/null 2>&1
0 2 * * 3 /usr/local/bin/backup-mysql Wednesday 12345 >/dev/null 2>&1
0 2 * * 4 /usr/local/bin/backup-mysql Thursday 12345 >/dev/null 2>&1
0 2 * * 5 /usr/local/bin/backup-mysql Friday 12345 >/dev/null 2>&1
0 2 * * 6 /usr/local/bin/backup-mysql Saturday 12345 >/dev/null 2>&1