From 1139530fbf3fb0fdce1bf5cfee311cd6f0fbf816 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Mon, 14 Oct 2013 10:04:06 -0400
Subject: [PATCH] Merge remote-tracking branch 'origin/stable-3.0.5'
---
server/plugins-available/backup_plugin.inc.php | 66 ++++++++++-----------------------
1 files changed, 20 insertions(+), 46 deletions(-)
diff --git a/server/plugins-available/backup_plugin.inc.php b/server/plugins-available/backup_plugin.inc.php
index bc91a91..78be959 100644
--- a/server/plugins-available/backup_plugin.inc.php
+++ b/server/plugins-available/backup_plugin.inc.php
@@ -29,48 +29,48 @@
*/
class backup_plugin {
-
+
var $plugin_name = 'backup_plugin';
var $class_name = 'backup_plugin';
-
+
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
public function onInstall() {
global $conf;
-
+
return true;
-
+
}
-
-
+
+
/*
This function is called when the plugin is loaded
*/
-
+
public function onLoad() {
global $app;
-
+
//* Register for actions
$app->plugins->registerAction('backup_download',$this->plugin_name,'backup_action');
$app->plugins->registerAction('backup_restore',$this->plugin_name,'backup_action');
-
+
}
-
+
//* Do a backup action
public function backup_action($action_name,$data) {
global $app,$conf;
-
+
$backup_id = intval($data);
$backup = $app->dbmaster->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = $backup_id");
-
+
if(is_array($backup)) {
-
+
$app->uses('ini_parser,file,getconf');
-
+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']);
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'].'/web'.$web['domain_id'];
-
+
//* Make backup available for download
if($action_name == 'backup_download') {
//* Copy the backup file to the backup folder of the website
@@ -80,38 +80,12 @@
$app->log('cp '.$backup_dir.'/'.$backup['filename'].' '.$web['document_root'].'/backup/'.$backup['filename'],LOGLEVEL_DEBUG);
}
}
-
- //* Restore a MongoDB backup
- if($action_name == 'backup_restore' && $backup['backup_type'] == 'mongodb') {
- if(file_exists($backup_dir.'/'.$backup['filename'])) {
- //$parts = explode('_',$backup['filename']);
- //$db_name = $parts[1];
- preg_match('@^db_(.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.tar\.gz$@', $backup['filename'], $matches);
- $db_name = $matches[1];
-
- // extract tar.gz archive
- $dump_directory = str_replace(".tar.gz", "", $backup['filename']);
- $extracted = "/usr/local/ispconfig/server/temp";
- exec("tar -xzvf ".escapeshellarg($backup_dir.'/'.$backup['filename'])." --directory=".escapeshellarg($extracted));
- $restore_directory = $extracted."/".$dump_directory."/".$db_name;
-
- // mongorestore -h 127.0.0.1 -u root -p 123456 --authenticationDatabase admin -d c1debug --drop ./toRestore
- $command = "mongorestore -h 127.0.0.1 --port 27017 -u root -p 123456 --authenticationDatabase admin -d ".$db_name." --drop ".escapeshellarg($restore_directory);
- exec($command);
- exec("rm -rf ".escapeshellarg($extracted."/".$dump_directory));
- }
-
- unset($clientdb_host);
- unset($clientdb_user);
- unset($clientdb_password);
- $app->log('Restored MongoDB backup '.$backup_dir.'/'.$backup['filename'],LOGLEVEL_DEBUG);
- }
-
+
//* Restore a mysql backup
if($action_name == 'backup_restore' && $backup['backup_type'] == 'mysql') {
//* Load sql dump into db
include('lib/mysql_clientdb.conf');
-
+
if(file_exists($backup_dir.'/'.$backup['filename'])) {
//$parts = explode('_',$backup['filename']);
//$db_name = $parts[1];
@@ -125,7 +99,7 @@
unset($clientdb_password);
$app->log('Restored MySQL backup '.$backup_dir.'/'.$backup['filename'],LOGLEVEL_DEBUG);
}
-
+
//* Restore a web backup
if($action_name == 'backup_restore' && $backup['backup_type'] == 'web') {
if($backup['backup_mode'] == 'userzip') {
@@ -149,11 +123,11 @@
}
}
}
-
+
} else {
$app->log('No backup with ID '.$backup_id.' found.',LOGLEVEL_DEBUG);
}
-
+
return 'ok';
}
--
Gitblit v1.9.1