matthew
January 29th, 2008, 10:22 PM
I have several websites. In each of them, I use a variation of the following script to perform a nightly backup of the site. The script is kept in my server's home directory, one level above public_html, and called up via cron. I've been using this for a long time and it works well.
<?php
$emailaddress = "myemail@address.com";
$target = "/home/".get_current_user()."/backup.".date(d).".tar.gz";
if (file_exists($target)) unlink($target);
system("tar --create --preserve --gzip --file=".$target." ~/public_html ~/mail",$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 = "The website 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, "Website Backup Message" , $message, "From: Website <>");
?> One of my sites has lots of graphic images in a specific directory, and it is getting to be quite big. I have the images backed up using another method, and would like to exclude that one directory.
Would I just change this line to read
system("tar --create --preserve --gzip --file=".$target." --exclude=~/backupexclude ~/public_html ~/mail",$result);I'm familiar enough with tar to be pretty sure that should do the trick...am I fooling myself or is it really that easy?
<?php
$emailaddress = "myemail@address.com";
$target = "/home/".get_current_user()."/backup.".date(d).".tar.gz";
if (file_exists($target)) unlink($target);
system("tar --create --preserve --gzip --file=".$target." ~/public_html ~/mail",$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 = "The website 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, "Website Backup Message" , $message, "From: Website <>");
?> One of my sites has lots of graphic images in a specific directory, and it is getting to be quite big. I have the images backed up using another method, and would like to exclude that one directory.
Would I just change this line to read
system("tar --create --preserve --gzip --file=".$target." --exclude=~/backupexclude ~/public_html ~/mail",$result);I'm familiar enough with tar to be pretty sure that should do the trick...am I fooling myself or is it really that easy?