First create a shell script which is used to backup database, here we named the script as mysql_backup.sh:
1 2 |
current_date=`date +"%y-%m-%d"` mysqldump -u.. -p.. db_name > db_name$current_date.sql |
In above command, we use date command to generate current date, and use it as part of filename.
After that we need to make this file executable
1 |
chmod +x mysql_backup.sh |
To make this backup script run automatically, we should create a cronjob. Type following command to open cronjob editor
crontab -e
Write following text and save it
1 |
0 0 * * * /home/usernane/mysql_backup.sh |
Above command means the cronjob will run at 0:00 everyday