hi you had asked about a backup script…if you know how to use cron…you can have it automatically execute this nightly or whenever you want it to trigger.
- please make sure you check the settings correctly on this one. you have to replace a few sections.
- i have my setup to be like
/httpdocs/mydomain.com/cron/backup.php
then i execute cron from my plesk/cpanel to execute that nightly.
- ensure that the place you have as your TARGET directory, can hold the data (chmod permissions etc) and you have the capacity to do this.
- once u have for example gone thru 01/01/2010
on 02/01/2010 it auto overwrites 01/01/2010 so you can have a daily backup done and save it for up to 1 month with this script:
// SYSTEM BACKUP
$emailaddress = "admin@yourdomainname.com";
$target = "/var/backup/your_folder_name/backup." . date("d") . ".tar.gz";
//if (file_exists($target)) unlink($target);
system("tar -C / --create --preserve --gzip --file=".$target." var/www/vhosts/yourdomain.com/httpdocs ",$result);
$size = filesize($target);
switch ($size) {
case ($size>=1048576): $size = round($size/1048576) . " MB"; break;
case ($size>=1024); $size = round($size/1024) . " KB"; break;
default: $size = $size . " bytes"; break;
}
$message = "Your Domain backup has been run.\n\n";
$message .= "The return code was: " . $result . "\n\n";
$message .= "The file path is: " . $target . "\n\n";
$message .= "Size of the backup: " . $size . "\n\n";
$message .= "Server time of the backup: " . date(" F d h:ia") . "\n\n";
mail($emailaddress, "Site Backup Complete" , $message, "From: Website <>");
//DATABASE BACKUP
$host="localhost"; // database host
$dbuser="add_your_username_here"; // database user name
$dbpswd="add_your_pass_here"; // database password
$mysqldb="db_name_here"; // name of database
$filename = "/var/backup/foldername/backup" . date("d") . ".sql";
if ( file_exists($filename) ) unlink($filename);
system("mysqldump --user=$dbuser --password=$dbpswd --host=$host $mysqldb > $filename",$result);
$size = filesize($filename);
switch ($size) {
case ($size>=1048576): $size = round($size/1048576) . " MB"; break;
case ($size>=1024): $size = round($size/1024) . " KB"; break;
default: $size = $size . " bytes"; break;
}
$message = "The database backup for " . $mysqldb . " has been run.\n\n";
$message .= "The return code was: " . $result . "\n\n";
$message .= "The file path is: " . $filename . "\n\n";
$message .= "Size of the backup: " . $size . "\n\n";
$message .= "Server time of the backup: " . date(" F d h:ia") . "\n\n";
mail($emailaddress, "DB Backup Complete" , $message, "From: Website <>");
?>