dragonknight
New Member
Hab jetzt mir mal ein Backup Script gebastelt, welche primär für einen VHCS Server gedacht ist:
Ist im Moment ein reines Shell Script.
Für Crons gibts auch die gleiche Variante, welches das Backup in eine Log Datei zur Protokolierung schreibt.
mfg
chris
PHP:
#!/usr/bin/php5 -q
<?php
#wpWDG Backup Solution Script
$dir = "/root/backup";
$inc = 0;
if(!is_dir($dir)){
echo ":==>".mkdir ($dir,0777,1);
$c = fopen($dir."/increment.num","w");
fwrite($c,"1");
fclose($c);
$inc = 1;
}else{
$c = fopen($dir."/increment.num","r");
$inc = fgetc($c);
fclose($c);
$c = fopen($dir."/increment.num","w+");
fwrite($c,intval($inc)+1);
fclose($c);
}
if(intval($inc>7)){
$inc = 1;
unlink($dir."/backup.7.tar");
}
chmod($dir,0777);
echo "----------------------------------------------------------------------";
echo "Beginning Backup: ".date("r")."";
echo "----------------------------------------------------------------------";
exec("nice --adjustment=19 tar -cz --file=".$dir."/etc.tgz /etc ",$array1,$return);
echo "Backup: /etc";
echo $return;
echo "----------------------------------------------------------------------";
exec("nice --adjustment=19 tar -cz --file=".$dir."/virtual.tgz /var/www/virtual ",$array1,$return);
echo "Backup: /var/www/virtual";
echo $return;
echo "----------------------------------------------------------------------";
exec("nice --adjustment=19 tar -cz --file=".$dir."/vhcs2.tgz /var/www/vhcs2 ",$array1,$return);
echo "Backup: //var/www/vhcs2";
echo $return;
echo "----------------------------------------------------------------------";
exec("nice --adjustment=19 tar -cz --file=".$dir."/mysql_files.tgz /var/lib/mysql ",$array1,$return);
echo "Backup: /var/lib/mysql";
echo $return;
echo "----------------------------------------------------------------------";
exec("nice --adjustment=19 tar -cz --file=".$dir."/mail.tgz /var/mail ",$array1,$return);
echo "Backup: /var/mail";
echo $return;
echo "----------------------------------------------------------------------";
echo "Backup: MySQL Datenbank Backup";
$mysqlbkpdir = "".$dir."/mysql";
if(!is_dir($mysqlbkpdir)){
mkdir ($mysqlbkpdir,0777,1);
}
chmod($mysqlbkpdir,0777);
system("/usr/bin/mysqldump -uroot -pxxxxxxxx -h localhost db1 > ".$mysqlbkpdir."/db1.sql");
system("/usr/bin/mysqldump -uroot -pxxxxxxxxx -h localhost db2> ".$mysqlbkpdir."/db2.sql");
system("/usr/bin/mysqldump -uroot -pxxxxxxxxxxxxxxxxx -h localhost db3> ".$mysqlbkpdir."/db3.sql");
system("/usr/bin/mysqldump -uroot -pxxxxxxxxxxxxxxxx -h localhost db4> ".$mysqlbkpdir."/db4.sql");
system("/usr/bin/mysqldump -uroot -pyyyyyyyyyyyyyyyy -h localhost db5> ".$mysqlbkpdir."/db5.sql");
exec("nice --adjustment=19 tar -cz --file=".$dir."/mysql.tgz $mysqlbkpdir/*.sql ",$array1,$return);
echo "Backup: MySQL Database Backup: sql";
echo $return;
exec("nice --adjustment=19 tar -c --file=".$dir."/backup.$inc.tar /root/backup/*.tgz ",$array1,$return);
echo "Making Big Archiv";
echo $return;
echo "----------------------------------------------------------------------";
unlink($dir."virtual.tgz");
unlink($dir."vhcs2.tgz");
unlink($dir."mysql_files.tgz");
unlink($dir."mail.tgz");
unlink($dir."mysql.tgz");
unlink($mysqlbkpdir."db1.sql");
unlink($mysqlbkpdir."db2.sql");
unlink($mysqlbkpdir."db3.sql");
unlink($mysqlbkpdir."db4.sql");
unlink($mysqlbkpdir."db5.sql");
echo "Cleaning Up";
echo $return;
echo "----------------------------------------------------------------------";
$conn_id = ftp_connect("ftpurl");
$login_result = ftp_login($conn_id, "user", "passwort");
if ((!$conn_id) || (!$login_result)) {
ftp_chdir($conn_id,"backup/".$inc);
echo "If OLD Backup Files Exists, Delete it";
$delete = ftp_delete($conn_id,"backup.tar");
echo "Delete: ".$delete;
echo "Uploading FTP Files";
$upload = ftp_put($conn_id,"backup.tar","backup.$inc.tar",FTP_BINARY);
echo "Upload: $upload";
unlink("$dir/backup.$inc.tgz");
echo "Removing Local Backup";
ftp_close($conn_id);
}else{
echo "Leaving Local Files";
echo $return;
}
echo "----------------------------------------------------------------------";
echo "Backup Finished at: ".date("r")."";
echo "----------------------------------------------------------------------";
fclose($a);
?>
Ist im Moment ein reines Shell Script.
Für Crons gibts auch die gleiche Variante, welches das Backup in eine Log Datei zur Protokolierung schreibt.
mfg
chris
Last edited by a moderator: