Create bash file
Create file
vim [file name].sh
#!/bin/bash USER=”[user name]” PASSWORD=”[password]” DATABASE=”[db name]” SAVEDIR=”/[save folder]” /opt/lampp/bin/mysqldump -u $USER –password=$PASSWORD –add-drop-database –default-character-set=utf8 $DATABASE > $SAVEDIR/$DATABASE-$(date ‘+%Y%m%d-%H%M%S’).sql
Add execution permission
chmod +x /path/to/[file name].sh
Run bash file
sh /path/to/[file name].sh
Set cron tab
[js]
sudo crontab -e
[/js]
And add the following line at the bottom of the file:
[js]
30 23 * * * /path/to/[file name].sh
[/js]
This will execute the script every day at 23:30.
Leave a Reply