From cab7ea5faaa2f3510c8488e7d19d083fc05ac6ca Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Wed, 18 Sep 2013 04:17:27 -0400
Subject: [PATCH] - Fixed missing global $app in new _decode function
---
server/plugins-available/backup_plugin.inc.php | 74 +++++++++++++++++++++++++-----------
1 files changed, 51 insertions(+), 23 deletions(-)
diff --git a/server/plugins-available/backup_plugin.inc.php b/server/plugins-available/backup_plugin.inc.php
index dfe3ddd..bc91a91 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->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = $backup_id");
-
+ $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,15 +80,43 @@
$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];
+ //$parts = explode('_',$backup['filename']);
+ //$db_name = $parts[1];
+ preg_match('@^db_(.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.sql\.gz$@', $backup['filename'], $matches);
+ $db_name = $matches[1];
$command = "gunzip --stdout ".escapeshellarg($backup_dir.'/'.$backup['filename'])." | mysql -h '".escapeshellcmd($clientdb_host)."' -u '".escapeshellcmd($clientdb_user)."' -p'".escapeshellcmd($clientdb_password)."' '".$db_name."'";
exec($command);
}
@@ -97,7 +125,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') {
@@ -121,11 +149,11 @@
}
}
}
-
+
} else {
$app->log('No backup with ID '.$backup_id.' found.',LOGLEVEL_DEBUG);
}
-
+
return 'ok';
}
--
Gitblit v1.9.1