示例#1
0
    def dump(self):
        #TODO: Finish implementing the Windows Dump exe path issue. (In docs for now)
        logging.info('Dumping database to file: [{}]'.format(self.dump_file))
        cmd = 'pg_dump.exe -h {host} -p {port} -U {user} -f {file} ' \
              '-F c --oids --verbose {dbname}'.format(host=self.db_host, port=self.db_port,
                                                      user=self.db_user, dbname=self.db_name, file=self.dump_file)

        assert_command(cmd)
示例#2
0
    def drop_db(self):
        """
        BEWARE DATA WILL GO BYE BYE

        drop the database. This is meant for the clone feature that is coming. (you cant clone into a DB that already
        exists.)
        """
        Database.drop_db(self)
        cmd = 'dropdb --host {h} -p {p} -U {u} {db} --if-exists'.format(
            h=self.db_host, p=self.db_port, u=self.db_user, db=self.db_name)
        assert_command(cmd)
示例#3
0
    def dump(self):
        """
        Implementation of postgresql dump command.

        /usr/bin/pg_dump -h <host> -U <user>  -f <filename> <database_name> -F c --oids
        """
        logging.info('Dumping database to file: [{}]'.format(self.dump_file))
        cmd = '/usr/bin/pg_dump -h {host} -p {port} -U {user} {dbname} -f {file} ' \
              '-F c --oids'.format(host=self.db_host, port=self.db_port,
                                   user=self.db_user, dbname=self.db_name, file=self.dump_file)

        assert_command(cmd)
示例#4
0
    def dump(self, single_transaction=False):
        args = ''
        logging.info('Dumping database to file: [{}]'.format(self.dump_file))
        if single_transaction:
            args += ' --single-transaction '
        if self.db_pass:
            args += '-p{}'.format(self.db_pass)
        cmd = 'mysqldump.exe --single-transaction -h {host} -P {port} -u {user} {args} {dbname} > {file}'.format(
            host=self.db_host, port=self.db_port,
            args=args, user=self.db_user,
            dbname=self.db_name, file=self.dump_file)

        assert_command(cmd)
示例#5
0
    def dump(self, single_transaction=False):
        args = ''
        logging.info('Dumping database to file: [{}]'.format(self.dump_file))
        if single_transaction:
            args += ' --single-transaction '
        if self.db_pass:
            args += '-p{}'.format(self.db_pass)
        cmd = '/usr/bin/mysqldump -h {host} -P {port} -u {user} {args} {dbname} > {file}'.format(
            host=self.db_host,
            port=self.db_port,
            args=args,
            user=self.db_user,
            dbname=self.db_name,
            file=self.dump_file)

        assert_command(cmd)
示例#6
0
    def restore(self, database_object, latest_file=False):
        """
        Restores the dump file from another database objects dump file.
        This can be the same database with a different DB name.

        @param database_object A postgres database object that has a dump file.
        @type database_object PostgresDatabase
        """
        Database.restore(self, database_object, latest_file)
        if latest_file:
            self.dump_file = self.find_latest_dump()
        logging.info('Restoring {} to database {}'.format(database_object.dump_file, database_object.db_name))
        cmd = '/usr/bin/pg_restore --host {h} --port {p} --username ' \
              '"{u}" --dbname "{db}" --no-password ' \
              '"{dump_file}"'.format(h=database_object.db_host, p=database_object.db_port, u=database_object.db_user,
                                     db=database_object.db_name, dump_file=self.dump_file)
        assert_command(cmd)
示例#7
0
 def create_empty_database(self, new_database_name):
     Database.create_empty_database(self, new_database_name)
     cmd = 'createdb -U {} {}'.format('postgres', new_database_name)
     assert_command(cmd)