Scheduled Backups auf FTP-Server mit ISPCONFIG
ISPCONFIG bietet die Möglichkeit, automatisch für jeden Tag ein Backup einer Domäne zu erstellen. Mit den nachfolgenden Anpassungen am Backup-Script von ISPCONFIG ist es möglich, diese Backups gleichzeitig auf einen FTP-Server zu kopieren. Zudem kann angegeben werden, wie viele Backups auf dem FTP-Server bleiben soll.
Die Script-Anpassungen stammen aus dem Forum von ISPCONFIG. Quelle: http://www.howtoforge.com/forums/showthread.php?t=23878&highlight=backup+ftp&page=3
Betroffenes File (unter Debian-Linux):
/root/ispconfig/scripts/shell/backup.php
Script-Code:
// HENRI Version 3
set_time_limit(0);
include("/root/ispconfig/scripts/lib/config.inc.php");
include("/root/ispconfig/scripts/lib/server.inc.php");
if($go_info["server"]["do_automated_backups"] != 1) die();
// Erstelle Namen für Backup Datei
$backup_file_name = "backup_".date("Y_m_d",time()).".zip";
// HENRI
define('FTP_SERVER', 'xxxxxx');
define('FTP_USER_NAME', 'xxxxxxx');
define('FTP_USER_PASS', 'xxxxxxxxx');
define('FTP_PATH', ''); // the path to the folder where backup files will be stored. e.g. '/my/folder' (no slash at the end)
// leave it empty to store backup files in the root folder of the FTP account
define('FTP_DAYS', 20); // the script will keep FTP backups this number of days. Min value is 1.
// set old_backup_file_name
$old_time = mktime(0, 0, 0, date('m'), date('d') - FTP_DAYS, date('Y'));
$old_backup_file_name = 'backup_'.date('Y_m_d', $old_time).'.zip';
//~HENRI
// [...]
// Delete temp file
exec("rm -rf $tmp_dir");
// HENRI Send file to FTP server
send_backup($web_id, $backup_dir);
//~HENRI
}
// All web site
$webs = $mod->db->queryAllRecords("SELECT * FROM isp_isp_web");
if(!empty($webs)){
foreach($webs as $web){
do_backup($web['doc_id']);
}
}
// HENRI
function send_backup($web_id, $backup_dir) {
global $backup_file_name, $old_backup_file_name;
// Connect and login to FTP server
$conn_id = @ftp_connect(FTP_SERVER);
$login_result = @ftp_login($conn_id, FTP_USER_NAME, FTP_USER_PASS);
if (!$conn_id || !$login_result) {
echo "FTP connection failed for ".FTP_USER_NAME."!\n";
return false;
}
else {
echo FTP_USER_NAME." connected\n";
}
// Create web_dir if necessary
$web_dir = FTP_PATH.'/web'.$web_id;
if (@ftp_mkdir($conn_id, $web_dir)) {
echo "Created $web_dir\n";
}
// Upload backup
$destination_file = $web_dir.'/'.$backup_file_name;
$source_file = $backup_dir.'/'.$backup_file_name;
$uploaded = @ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// Display result
if (!$uploaded) {
echo "Failed sending $destination_file\n";
}
else {
echo "Successed sending $destination_file\n";
// Remove old backup
$destination_file = $web_dir.'/'.$old_backup_file_name;
if (@ftp_delete($conn_id, $destination_file)) {
echo "Removed old backup: $destination_file\n";
}
}
// Close FTP connection
@ftp_close($conn_id);
return $uploaded;
}
//~HENRI