From f58d4439ab399d3c13e6919386ae441f7e6c6ed4 Mon Sep 17 00:00:00 2001 From: BadPixxel Date: Fri, 17 Nov 2017 02:01:33 +0100 Subject: [PATCH 1/4] Add of MongoDb Restore Feature --- DependencyInjection/Configuration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b4edb2c..4745097 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -108,6 +108,7 @@ public function getConfigTreeBuilder() ->scalarNode('db_port')->defaultValue(27017)->end() ->scalarNode('db_user')->defaultValue(null)->end() ->scalarNode('db_password')->defaultValue(null)->end() + ->booleanNode('restore')->defaultFalse()->end() ->end() ->end() ->arrayNode('mysql') From 8e7f9696f518c6218f635d3da74e400c36018e19 Mon Sep 17 00:00:00 2001 From: BadPixxel Date: Fri, 17 Nov 2017 02:02:46 +0100 Subject: [PATCH 2/4] Add of MongoDb Restore Feature --- Resources/config/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 33b738b..1683ae5 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -70,6 +70,7 @@ services: arguments: - '%dizda_cloud_backup.databases%' - '%dizda_cloud_backup.output_folder%' + - '%dizda_cloud_backup.restore_folder%' calls: - [ setTimeout, [ '%dizda_cloud_backup.timeout%' ] ] tags: From 67dc211eb0e736bca479e8d003448fc6713fdf4a Mon Sep 17 00:00:00 2001 From: BadPixxel Date: Fri, 17 Nov 2017 02:03:22 +0100 Subject: [PATCH 3/4] Add of MongoDb Restore Feature --- Database/MongoDB.php | 51 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/Database/MongoDB.php b/Database/MongoDB.php index ea265a8..a3ec992 100644 --- a/Database/MongoDB.php +++ b/Database/MongoDB.php @@ -1,31 +1,46 @@ */ -class MongoDB extends BaseDatabase +class MongoDB extends BaseDatabase implements RestorableDatabaseInterface { const DB_PATH = 'mongo'; private $database; private $auth = ''; + /** + * @var string + */ + private $restoreFolder; + + /** + * @var string + */ + private $doRestore; + /** * DB Auth. * * @param array $params * @param string $basePath + * @param string $restoreFolder */ - public function __construct($params, $basePath) + public function __construct($params, $basePath, $restoreFolder = null) { parent::__construct($basePath); - $params = $params['mongodb']; - $this->database = $params['database']; - $this->auth = ''; + $this->restoreFolder = $restoreFolder; + $params = $params['mongodb']; + $this->doRestore = $params['restore']; + $this->database = $params['database']; + $this->auth = ''; if ($params['all_databases']) { $this->database = ''; @@ -55,6 +70,7 @@ public function dump() $this->execute($this->getCommand()); } + /** * {@inheritdoc} */ @@ -73,4 +89,29 @@ public function getName() { return 'MongoDB'; } + + /** + * {@inheritdoc} + */ + public function restore() + { + if ($this->doRestore) { + $this->execute($this->getRestoreCommand()); + } + } + + /** + * {@inheritdoc} + */ + protected function getRestoreCommand() + { + if (!$this->restoreFolder) { + throw InvalidConfigurationException::create('$restoreFolder'); + } + + return sprintf('mongorestore %s %s', + $this->auth, + $this->restoreFolder . self::DB_PATH); + } + } From 1c887af862114c1a243c91f79e2ad58bb0f2434c Mon Sep 17 00:00:00 2001 From: BadPixxel Date: Fri, 17 Nov 2017 02:05:47 +0100 Subject: [PATCH 4/4] Add of MongoDb Restore Feature --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b03d6a0..c158f32 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ dizda_cloud_backup: database: ~ # Required if all_databases is false db_user: ~ # Not required, leave empty if no auth is required db_password: ~ # Not required + restore: false # Required to Enable Restore of MongoDb mysql: all_databases: false # Only required when no database is set