Daily mysqldump with cron to a flash drive

I am trying to mysqldump from raspberry pi to a flash disk connected to it in case the pi goes nuts one day.
I try to use the following script to be executed every day at 13:35, saved as /etc/cron.daily/<dated data.sql>
35 13 * * * mysqldump -u root -p mypassword --routines=true --add-drop-database --databases db5 > /media/Glide/db5_ data '+%m-%d-%Y'.sql

/media/Glide is my Flash disk.
So far no luck. Any suggestions?

Hi try this instead:

35 13 * * * /usr/bin/mysqldump -u root --password="mypassword" db5 > /media/Glide/db5_$(date +%m-%d-%Y).sql

Hope it helps …

Lubos

or this code try:

15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_data ' %m-%d-%Y'.sql.gz

I couldn’t get the scheduling part working by just using the sh file in /etc/cron.daily directory. I had to use crontab -e and add the following:

15 13 * * * /etc/cron.daily/myscript.sh

then
in myscript.sh the following worked best for me:

/usr/bin/mysqldump - u root pmypassword --routines --add-drop-database --database mydatabasename > /media/MyFlash/backupbycron_ date +\%d\%m\%Y.sql

In saying that, \ was needed in front of the % to ‘escape’ it. Otherwise the system somehow doesn’t get it.
Now it works.

What I don’t know is whether this should actually just work without the crontab file part - by using an sh file in /etc/cron.daily directory?

Hi,

You may need to remove the file extension. So for example rename your myscript.sh file to myscript. Place your file into /etc/cron.daily directory and do a test run to see whether it will run:

$ run-parts --test /etc/cron.daily

If all is correct you should see your script in the output of the above command.

Hope this helps…

Lubos