Hi I want to setup a cronjob to backup my mysql database autometically everyday to a folder in my server. What are the commands should I use? And, I want to gzip the output file for compressing. How can I do that?
Here's what I use when I'm after backing things up. Setup a cron job to run every day, and run something like this: mysqldump --add-drop-table database -u=dbuser -pyourpassword >> ~/yourdb.sql Code (markup): I wouldn't advise compressing it, as compression takes a good bit of server resources. Good luck!
This is what I found somewhere else. Please let me if it will work for me. mysqldump -uDBUSER -pDBPASSWORD -hlocalhost DBNAME > /home/usr/dump/backupdb.sql gzip -9 backupdb.sql Code (markup):
That's exactly what I said, only mine has the --add-drop-table argument to it which is going to come in handy when you have to use the backup whatever reason. Without that, you'd get tons of "table already exists" errors, and a whole lot of other stuff.