Esempio n. 1
0
 def run_command(self, *args, **kwargs):
     if self.settings.get('PASSWORD'):
         env = kwargs.get('env', {})
         env['PGPASSWORD'] = utils.get_escaped_command_arg(
             self.settings['PASSWORD'])
         kwargs['env'] = env
     return super(PgDumpConnector, self).run_command(*args, **kwargs)
 def _create_dump(self):
     cmd = '{} --db {}'.format(self.dump_cmd, self.settings['NAME'])
     host = self.settings.get('HOST') or 'localhost'
     port = self.settings.get('PORT') or 27017
     cmd += ' --host {}:{}'.format(host, port)
     if self.settings.get('USER'):
         cmd += ' --username {}'.format(self.settings['USER'])
     if self.settings.get('PASSWORD'):
         cmd += ' --password {}'.format(
             utils.get_escaped_command_arg(self.settings['PASSWORD']))
     for collection in self.exclude:
         cmd += ' --excludeCollection {}'.format(collection)
     cmd += ' --archive'
     cmd = '{} {} {}'.format(self.dump_prefix, cmd, self.dump_suffix)
     stdout, stderr = self.run_command(cmd, env=self.dump_env)
     return stdout
 def _restore_dump(self, dump):
     cmd = '{} {}'.format(self.restore_cmd, self.settings['NAME'])
     if self.settings.get('HOST'):
         cmd += ' --host={}'.format(self.settings['HOST'])
     if self.settings.get('PORT'):
         cmd += ' --port={}'.format(self.settings['PORT'])
     if self.settings.get('USER'):
         cmd += ' --user={}'.format(self.settings['USER'])
     if self.settings.get('PASSWORD'):
         cmd += ' --password={}'.format(
             utils.get_escaped_command_arg(self.settings['PASSWORD']))
     cmd = '{} {} {}'.format(self.restore_prefix, cmd, self.restore_suffix)
     stdout, stderr = self.run_command(cmd,
                                       stdin=dump,
                                       env=self.restore_env)
     return stdout, stderr
 def _create_dump(self):
     cmd = '{} {} --quick'.format(self.dump_cmd, self.settings['NAME'])
     if self.settings.get('HOST'):
         cmd += ' --host={}'.format(self.settings['HOST'])
     if self.settings.get('PORT'):
         cmd += ' --port={}'.format(self.settings['PORT'])
     if self.settings.get('USER'):
         cmd += ' --user={}'.format(self.settings['USER'])
     if self.settings.get('PASSWORD'):
         cmd += ' --password={}'.format(
             utils.get_escaped_command_arg(self.settings['PASSWORD']))
     for table in self.exclude:
         cmd += ' --ignore-table={}.{}'.format(self.settings['NAME'], table)
     cmd = '{} {} {}'.format(self.dump_prefix, cmd, self.dump_suffix)
     stdout, stderr = self.run_command(cmd, env=self.dump_env)
     return stdout
 def _restore_dump(self, dump):
     cmd = self.restore_cmd
     host = self.settings.get('HOST') or 'localhost'
     port = self.settings.get('PORT') or 27017
     cmd += ' --host {}:{}'.format(host, port)
     if self.settings.get('USER'):
         cmd += ' --username {}'.format(self.settings['USER'])
     if self.settings.get('PASSWORD'):
         cmd += ' --password {}'.format(
             utils.get_escaped_command_arg(self.settings['PASSWORD']))
     if self.object_check:
         cmd += ' --objcheck'
     if self.drop:
         cmd += ' --drop'
     cmd += ' --archive'
     cmd = '{} {} {}'.format(self.restore_prefix, cmd, self.restore_suffix)
     return self.run_command(cmd, stdin=dump, env=self.restore_env)
Esempio n. 6
0
 def test_arg_with_space(self):
     assert utils.get_escaped_command_arg('foo bar') == '\'foo bar\''