Skip to content

Instantly share code, notes, and snippets.

@infynyxx
Created June 11, 2010 16:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save infynyxx/434737 to your computer and use it in GitHub Desktop.
Save infynyxx/434737 to your computer and use it in GitHub Desktop.
automated mysql dump using Linux Cron tab
#!/bin/sh
mysqldump -u root -pmysql123 –all-databases –routines| gzip > /root/MySQLDB_`date ‘+%m-%d-%Y’`.sql.gz
mysqldump -h 172.16.21.3 -u root -pmysql123 –all-databases –routines | gzip > /root/MySQLDB.3_`date ‘+%m-%d-%Y’`.sql.gz
#now create cron script smth like this
#crontab -e
#30 15 * * * /root/MySQLdump.sh 2>&1>> /root/MySQLdump.log
#The above will dump the database every day at 15:30.
#http://dbperf.wordpress.com/2010/06/11/automate-mysql-dumps-using-linux-cron-job/
@buisine
Copy link

buisine commented Jan 30, 2018

Should read :

date +'%m-%d-%Y'`.sql.gz

singles quotes around date format and the + signe outside of quotes

@nmehari
Copy link

nmehari commented Mar 15, 2019

I have configured mysqldump on my mysql database server but,

  1. it takes only 20 byte mysql data.
  2. it doesn't take the backup automatically.

Here is my config on "/home/user/mysqldump.sh" script file


20 09 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /home/user/Documents/database_data '+%m-%d-%Y'.sql.gz

then I restart the crontab "/etc/init.d/cron restart"
So , please if anyone have the solution.

@1fancy
Copy link

1fancy commented Aug 7, 2019

I have configured mysqldump on my mysql database server but,

  1. it takes only 20 byte mysql data.
  2. it doesn't take the backup automatically.

Here is my config on "/home/user/mysqldump.sh" script file

20 09 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /home/user/Documents/database_data '+%m-%d-%Y'.sql.gz

then I restart the crontab "/etc/init.d/cron restart"
So , please if anyone have the solution.

If you read the file, you will see that's the password is wrong!
Make it like that: -u yourusername -p'YOURPASSWORD'
the -p is attached to '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment