Also edit variables you need and replace database credentials at line starting with mysqldump after it press “Esc”.

Then save the file by pressing “:” (colon), then “wq” and press enter.

Run it to rest that it creates backups successfully:

/etc/cron.daily/db-backup-mydb

When you open your /home/myapp/backups folder you will see sql.gz backup file and a log file with debug information about backup process.

To make weekly backups the only few things you need to change is to place the script into /etc/cron.weekly/ folder, replace filename part “daily” to “weekly” and change “-mtime +8” to “-mtime +56” to keep last 8 weekly backups.