Page 1 of 1

Using Cron Jobs to Execute files and Backup Databases ( mysqlDump )

Posted: Wed Jun 13, 2007 11:37 am
by blue-sky
It is very fast and easy to backup your databases with CRON JOBS....

let see what it is:

With CRON JOBS you can execute your files and commands on a specific time which you want them to be executed.


in CPanel select Cron Job icon and select advanced (Unix Style) :


The timing:

* * * * * => Execute every minute
0 * * * * => Execute every Hour
0 0 * * * => Execute every mid-night
0 0 0 * * => Execute every Month
0 0 0 0 * => Execute every Weekday



DATABASE: ( mySQLdump ) -------------------------------------

command:

date=`date -I` ; mysqldump -uDBUSER -pDBPASS DBNAME | gzip > /home/USERNAME/public_html/backups/db_$date.gz

DBUSER : your database user name
DBPASS : your database password
DBNAME : your database name
USERNAME : your hosting username

Note: it will backup your database and stores it on your backups folder on your root folder of the host. the naming of the file will form the dates.



EXECUTING FILES: -------------------------------------

run a script on your host by this code:

0 * * * * /usr/local/bin/php -q /home/USERNAME/public_html/filename.php

USERNAME : your hosting username
filename.php : your file name to be executed

Note: the timing is scheduled to run the file every hour in this example



TAKE a complete backup from your host: -------------------------------------

0 0 0 0 *

command:
date=`date -I` ; tar -zcf /home/USERNAME/public_html/backups/host_backup_$date.tgz ./public_html

USERNAME : your hosting username

Posted: Tue Jun 26, 2007 1:11 pm
by bilalghouri
wow thats the coolest post here..
by this way..we can also increase our site rankings by loading our site every hour through cpanel..

Posted: Sun Sep 16, 2007 5:05 pm
by Gyanu
wow wht a cool coding.Thanx alot.

Posted: Sat Oct 06, 2007 10:42 pm
by bilalghouri
hey could u please tell me how to send these backups to a different server through ftp??
i know the ssh command to do that.. how will we do i it through cron?
the ssh is :

/usr/bin/perl /usr/local/cpanel/bin/ftpput /home/USERNAME/Backup_FILENAME.gz FTP_Host_NAME FTP_USERNAME ftp /home/USERNAME/ 21

that command i got when i was generating full backup using cpanel and was sending it to my another server.. i got that command from WHM(root account)'s log , but it doesnt show where to write the ftp password...thats why i need you to help me.. :) hope u can help.

Posted: Sat Oct 06, 2007 10:55 pm
by Tails5
try putting the password after the username, prefaced by a colon, like admin:password

Posted: Sun Oct 07, 2007 9:14 am
by bilalghouri
but how to generate and send full backup using cron jobs?

Posted: Sun Oct 07, 2007 9:46 pm
by Tails5
Well use

Code: Select all

date=`date -I` ; tar -zcf /home/USERNAME/public_html/backups/host_backup_$date.tgz ./public_html
to make the backup, then

Code: Select all

date=`date -I` ;/usr/bin/perl /usr/local/cpanel/bin/ftpput /home/USERNAME/backups/host_backup.tgz FTP_Host_NAME admin:password ftp /home/USERNAME/ 21
to send it, just replace the things like host name, and admin/password, and username witht he right things and it should work.