Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

New feature - Add of MongoDb Restore Feature #132

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions Database/MongoDB.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
<?php
namespace Dizda\CloudBackupBundle\Database;

use Dizda\CloudBackupBundle\Exception\InvalidConfigurationException;

/**
* Class MongoDB.
*
* @author Jonathan Dizdarevic <[email protected]>
*/
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 = '';
Expand Down Expand Up @@ -55,6 +70,7 @@ public function dump()
$this->execute($this->getCommand());
}


/**
* {@inheritdoc}
*/
Expand All @@ -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);
}

}
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down