Where does my mysqldump file get saved to?
I followed your mysql backup tutorial and added the following line to my crontab (with minor edits):
0 1 * * * /usr/bin/mysqldump --all-databases > dump-$( date '+%Y-%m-%d_%H-%M-%S' ).sql -u root -pPASSWORD
I cannot find the backup file. Does crontab save the sql file in a specific location?
Could you kindly let me know that location so I can verify if the script works correctly?
When you run a cron job it would be stored in the path or directory from where you are running the mysql command, unless you specify a specific path/directory.
In this case, since you're running the command without specifying a directory, it will save to your home directory
If you wanted to specify a directory you could do so before the file name. Here's an example:
0 1 * * * /usr/bin/mysqldump --all-databases > /home/example_user/dump-$( date '+\%Y-\%m-\%d_\%H-\%M-\%S' ).sql -u root -pPASSWORD
(Note: In your crontab you'll need to include backslashes to escape the percent (%) signs, since they have a special meaning in crontabs. They are interpreted as newline characters.)
In this case you would find it in your
I did check in my home directory but didn't find any autogenerated file in there.
Next I will try buy given the destination path as you have shown in the example.
Just to confirm @LineOfSight - Did you also add the backslashes to escape the percent (%) signs?
Another thing you could check is whether your cron is throwing any errors is your syslog file:
cat /var/log/syslog | tail -50
That way you could confirm if it's running, too.
Joe's suggestion should help determine if the .sql file is not being generated because its running into an error.
It may be that the mysqldump is being generated, but you can't locate it. To see if this is the case, use the following
find command to search your root partition for any .sql files to see if you can locate it.
find / -name "*.sql" 2> /dev/null