src/Webiny/BackupService/Lib/BackupMongo.php
private function createExport($db)
    {
        Service::$log->msg(sprintf('Mongodb: exporting "%s" database.', $db['Database']));

        $cmd = 'mongodump';

        if (!isset($db['Database'])) {
            throw new \Exception(sprintf('Missing "Database" parameter for one of the MongoDatabases'));
        }

        $cmd .= ' --db ' . $db['Database'];

        if (!isset($db['Host'])) {
            throw new \Exception(sprintf('Missing "Host" parameter for "%s" database', $db['Database']));
        }

        $host = explode(':', $db['Host']);

        $cmd .= ' --host ' . $host[0];

        if (isset($host[1])) {
            $cmd .= ' --port ' . $host[1];
        }

        if (isset($db['Username']) && !empty($db['Username'])) {
            $cmd .= ' --username ' . $db['Username'];
        }

        if (isset($db['Password']) && !empty($db['Password'])) {
            $cmd .= ' --password ' . $db['Password'];

            if(!isset($db['AuthenticationDatabase'])){
                $cmd .= ' --authenticationDatabase admin';
            }else{
                $cmd .= ' --authenticationDatabase '.$db['AuthenticationDatabase'];
            }
        }

        // create a folder for this database export
        $folderName = $this->tempFolder . $db['Database'] . '-' . date('Y-m-d');
        $cmd .= ' --out ' . $folderName;

        // mask password from log command
        if(isset($db['Password'])){
            $logCommand = str_replace(' --password ' . $db['Password'], ' --password xxxxxx', $cmd);
        }else{
            $logCommand = $cmd;
        }


        Service::$log->msg(sprintf('Mongodb: export command ' . $logCommand));

        $return = system($cmd);

        Service::$log->msg(sprintf('Mongodb: '.$return));
        Service::$log->msg(sprintf('Mongodb: database export done'));

        Cleanup::addToQueue($folderName, Cleanup::TYPE_DIR);

        return $folderName;
    }
private function createExport($db)
    {
        Service::$log->msg(sprintf('Mongodb: exporting "%s" database.', $db['Database']));

        $cmd = 'mongodump';

        if (!isset($db['Database'])) {
            throw new \Exception(sprintf('Missing "Database" parameter for one of the MongoDatabases'));
        }

        $cmd .= ' --db ' . $db['Database'];

        if (!isset($db['Host'])) {
            throw new \Exception(sprintf('Missing "Host" parameter for "%s" database', $db['Database']));
        }

        $host = explode(':', $db['Host']);

        $cmd .= ' --host ' . $host[0];

        if (isset($host[1])) {
            $cmd .= ' --port ' . $host[1];
        }

        if (isset($db['Username']) && !empty($db['Username'])) {
            $cmd .= ' --username ' . $db['Username'];
        }

        if (isset($db['Password']) && !empty($db['Password'])) {
            $cmd .= ' --password ' . $db['Password'];

            if(!isset($db['AuthenticationDatabase'])){
                $cmd .= ' --authenticationDatabase admin';
            }else{
                $cmd .= ' --authenticationDatabase '.$db['AuthenticationDatabase'];
            }
        }

        // create a folder for this database export
        $folderName = $this->tempFolder . $db['Database'] . '-' . date('Y-m-d');
        $cmd .= ' --out ' . $folderName;

        // mask password from log command
        if(isset($db['Password'])){
            $logCommand = str_replace(' --password ' . $db['Password'], ' --password xxxxxx', $cmd);
        }else{
            $logCommand = $cmd;
        }


        Service::$log->msg(sprintf('Mongodb: export command ' . $logCommand));

        $return = system($cmd);

        Service::$log->msg(sprintf('Mongodb: '.$return));
        Service::$log->msg(sprintf('Mongodb: database export done'));

        Cleanup::addToQueue($folderName, Cleanup::TYPE_DIR);

        return $folderName;
    }
private function createExport ( $ db ) { Service :: $ log -> msg ( sprintf ( 'Mongodb: exporting "%s" database.' , $ db [ 'Database' ] ) ) ; $ cmd = 'mongodump' ; if ( ! isset ( $ db [ 'Database' ] ) ) { throw new \ Exception ( sprintf ( 'Missing "Database" parameter for one of the MongoDatabases' ) ) ; } $ cmd .= ' --db ' . $ db [ 'Database' ] ; if ( ! isset ( $ db [ 'Host' ] ) ) { throw new \ Exception ( sprintf ( 'Missing "Host" parameter for "%s" database' , $ db [ 'Database' ] ) ) ; } $ host = explode ( ':' , $ db [ 'Host' ] ) ; $ cmd .= ' --host ' . $ host [ 0 ] ; if ( isset ( $ host [ 1 ] ) ) { $ cmd .= ' --port ' . $ host [ 1 ] ; } if ( isset ( $ db [ 'Username' ] ) && ! empty ( $ db [ 'Username' ] ) ) { $ cmd .= ' --username ' . $ db [ 'Username' ] ; } if ( isset ( $ db [ 'Password' ] ) && ! empty ( $ db [ 'Password' ] ) ) { $ cmd .= ' --password ' . $ db [ 'Password' ] ; if ( ! isset ( $ db [ 'AuthenticationDatabase' ] ) ) { $ cmd .= ' --authenticationDatabase admin' ; } else { $ cmd .= ' --authenticationDatabase ' . $ db [ 'AuthenticationDatabase' ] ; } } // create a folder for this database export $ folderName = $ this -> tempFolder . $ db [ 'Database' ] . '-' . date ( 'Y-m-d' ) ; $ cmd .= ' --out ' . $ folderName ; // mask password from log command if ( isset ( $ db [ 'Password' ] ) ) { $ logCommand = str_replace ( ' --password ' . $ db [ 'Password' ] , ' --password xxxxxx' , $ cmd ) ; } else { $ logCommand = $ cmd ; } Service :: $ log -> msg ( sprintf ( 'Mongodb: export command ' . $ logCommand ) ) ; $ return = system ( $ cmd ) ; Service :: $ log -> msg ( sprintf ( 'Mongodb: ' . $ return ) ) ; Service :: $ log -> msg ( sprintf ( 'Mongodb: database export done' ) ) ; Cleanup :: addToQueue ( $ folderName , Cleanup :: TYPE_DIR ) ; return $ folderName ; }
Private method that does the actual database export.

@param array $db Database entry configuration.

@return string Path to the created database export.
@throws \Exception
Private method that does the actual database export .