Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Added PostgreSQL support.
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Hudson <rob@tastybrew.com>
  • Loading branch information
brosner authored and Rob Hudson committed Apr 8, 2009
1 parent 5e5b40a commit c6433c7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -41,7 +41,7 @@ The following is an idea of what the configuration file, located at
path = /opt/local/lib/mysql5/bin/mysqldump path = /opt/local/lib/mysql5/bin/mysqldump
flags = -Q --opt --compact flags = -Q --opt --compact
[pgdump options] [pg_dump options]
path = /opt/local/lib/postgresql83/bin/pg_dump path = /opt/local/lib/postgresql83/bin/pg_dump
[TimestampRename options] [TimestampRename options]
Expand Down
50 changes: 47 additions & 3 deletions dumpy/dumper.py
Expand Up @@ -81,6 +81,10 @@ class BackupBase(DumpyBase):
""" """
Base class for database backups. Base class for database backups.
""" """

def __init__(self, db):
self.db = db

def backup(self): def backup(self):
raise NotImplementedError raise NotImplementedError


Expand Down Expand Up @@ -113,12 +117,11 @@ def backup(self):
self.parse_config() self.parse_config()
if self.type == 'mysql': if self.type == 'mysql':
return MysqlBackup(self.database).backup() return MysqlBackup(self.database).backup()
elif self.type == 'postgresql':
return PostgresqlBackup(self.database).backup()


class MysqlBackup(BackupBase): class MysqlBackup(BackupBase):


def __init__(self, db):
self.db = db

def parse_config(self): def parse_config(self):
super(MysqlBackup, self).parse_config() super(MysqlBackup, self).parse_config()


Expand Down Expand Up @@ -159,6 +162,47 @@ def backup(self):


return tmp_file return tmp_file


class PostgresqlBackup(BackupBase):

def parse_config(self):
super(PostgresqlBackup, self).parse_config()

section = 'database %s' % self.db
self.name = self._get_option_value(self.config, section, 'name')
self.user = self._get_option_value(self.config, section, 'user')
self.host = self._get_option_value(self.config, section, 'host')
self.port = self._get_option_value(self.config, section, 'port', 'int')

self.binary = self._get_option_value(self.config, 'pg_dump options', 'path')
self.flags = self._get_option_value(self.config, 'pg_dump options', 'flags')

def get_flags(self):
# @@@ ugh. i don't like this.
if self.flags is None:
flags = ''
else:
flags = '%s' % self.flags
if self.user:
flags += ' -U %s' % self.user
if self.host:
flags += ' -h %s' % self.host
if self.port:
flags += ' -p %d' % self.port
return flags

def backup(self):
self.parse_config()
tmp_file = tempfile.NamedTemporaryFile()
cmd = '%(binary)s %(flags)s %(database)s > %(file)s' % {
'binary': self.binary,
'flags': self.get_flags(),
'database': self.name,
'file': tmp_file.name,
}
print cmd # FIXME
os.system(cmd)
return tmp_file

class PostProcess(PostProcessBase): class PostProcess(PostProcessBase):
""" """
This classes loads the specified database `postprocessing` config option This classes loads the specified database `postprocessing` config option
Expand Down

0 comments on commit c6433c7

Please sign in to comment.