Backupsql
Backupsql
php
/*
* Backup script on server.
*
* Runs on the server, called by Cron. Connects to the mySQL
* database and creates a backup file of the whole database.
* Saves to file in current directory.
*
* @author Cow <[email protected]>
* @version 0.2
* @date 18/08/2004
* @package Backup Server
* Upgraded Ver 2.0 (sending sql backup as attachment
* as email attachment, or send to a remote ftp server by
* @co-authors Cool Surfer<[email protected]> and
* Neagu Mihai<[email protected]>
*/
set_time_limit(0);
$date = date("mdy-hia");
$dbserver = "localhost";
$dbuser = "vhacker_robot";
$dbpass = "mp2811987";
$dbname = "tvhacker_vbb3";
$file = "N-Cool-$date.sql.gz";
$gzip = TRUE;
$silent = TRUE;
function write($contents) {
if ($GLOBALS['gzip']) {
gzwrite($GLOBALS['fp'], $contents);
} else {
fwrite($GLOBALS['fp'], $contents);
}
}
if ($gzip) {
$fp = gzopen($file, "w");
} else {
$fp = fopen($file, "w");
}
if (!$silent) {
echo "Backing up table ".$i."\n";
}
// Create DB code
$create = mysql_fetch_array(mysql_query ("SHOW CREATE TABLE ".$i));
write($create['Create Table'].";\n\n");
$use_gzip = "yes"; // Set to No if you don't want the files sent in .gz
format
$remove_sql_file = "no"; // Set this to yes if you want to remove the sql file
after gzipping. Yes is recommended.
$remove_gzip_file = "no"; // Set this to yes if you want to delete the gzip file
also. I recommend leaving it to "no"
// Do not Modify below this line! It will void your warranty :-D!
$date = date("mdy-hia");
$filename = "$savepath/$dbname-$date.sql";
if($use_gzip=="yes"){
$filename2 = $file;
} else {
$filename2 = "$savepath/$dbname-$date.sql";
}
if($send_email == "yes" ){
$fileatt_type = filetype($filename2);
$fileatt_name = "".$dbname."-".$date."_sql.tar.gz";
if($use_ftp == "yes"){
$ftpconnect = "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log
-e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2";
shell_exec($ftpconnect);
echo "<h4><center>$filename2 Was created and uploaded to your FTP
server!</center></h4>";
if($remove_gzip_file=="yes"){
exec("rm -r -f $filename2");
}
?>