Where does my mysqldump file get saved to?

Hi -

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?

4 Replies

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 /home/example_user.

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


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct