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

General discussion regarding computers can be carried out here.
Locked
blue-sky
Posts: 33
Joined: Tue Jun 12, 2007 3:41 pm

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

Post 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


bilalghouri
Posts: 56
Joined: Sat Mar 10, 2007 11:36 am

Post 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..
Gyanu
Posts: 338
Joined: Mon Jul 30, 2007 2:03 pm
Contact:

Post by Gyanu »

wow wht a cool coding.Thanx alot.
Image
bilalghouri
Posts: 56
Joined: Sat Mar 10, 2007 11:36 am

Post 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.
Tails5
Posts: 1302
Joined: Wed Mar 15, 2006 8:09 am
Contact:

Post by Tails5 »

try putting the password after the username, prefaced by a colon, like admin:password
Webmaster Yoda: You must confront the cPanel. Then, and only then, a webmaster will you be.
Julius Caesar: Veni, vidi, posti
bilalghouri
Posts: 56
Joined: Sat Mar 10, 2007 11:36 am

Post by bilalghouri »

but how to generate and send full backup using cron jobs?
Tails5
Posts: 1302
Joined: Wed Mar 15, 2006 8:09 am
Contact:

Post 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.
Webmaster Yoda: You must confront the cPanel. Then, and only then, a webmaster will you be.
Julius Caesar: Veni, vidi, posti
Locked