Using Cron Jobs to Execute files and Backup Databases ( mysqlDump )
Posted: Wed Jun 13, 2007 11:37 am
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
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