View Full Version : [all variants] A bundle of command line for crontab

April 10th, 2010, 12:15 PM
Hi there, I was trying to backup mySQL file in my server daily.

Is there anyway that we could generate a bundles of command in the below method?

/etc/rc.d/init.d/mysqld stop #stoping mysql
cd /home/mybackup #change directory...
tar -cvf <myBackupfile.tar> /var/lib/mysql/myDB/* #create a tar file

# when it is done...
/etc/rc.d/init.d/mysqld start

And I dont think putting all these line in crontab is the proper way of doing it..

Is there any way I can write the above code in one file and execute it in the crontab:confused:

April 10th, 2010, 01:53 PM
Write a backup script and call it from crontab.

April 10th, 2010, 03:26 PM

I have the following script run every night on my database:

DAY=`/bin/date +%Y%m%d`
mysqldump DATABASE -u USERNAME -pPASSWORD > /storage/backup/mysql.$DAY.sql

Hope it helps.



April 12th, 2010, 04:19 AM
minaev, sprouty

Thanks for the info...and sharing for codes....

Now it seems working fine and crontab are clean once again...