In today's digital age, data security is paramount. Regular database backups are essential to safeguard your valuable information. MySQL, a popular open-source database system, offers robust backup mechanisms. By combining Cron jobs, a powerful scheduling tool, with MySQL's backup utilities, you can automate the process of creating daily database backups.
Making database backups for each day of the week
* 4 * * * mysqldump --no-tablespaces --result-file=/var/www/site/backup/site_$(date +\%a).sql -u mysql_user --password='mysql_password' site_db_name > /var/www/site/backup/site_$(date +\%a).sql >> /var/www/site/logs/cron_error.log 2>&1
* 4 * * *
- run mysqldump every day at 4 AM
--result-file=/var/www/site/backup/site_$(date +\%a).sql
- file name using the name of the day of the week
mysql_user
- name of mysql user
mysql_password
- password of mysql user
site_db_name
- mysql database name
/var/www/site/logs/cron_error.log
- name of log file
Add command into crontab file
crontab -e