Permalink
Browse files

Added PostgreSQL support.

Signed-off-by: Rob Hudson <rob@tastybrew.com>
  • Loading branch information...
1 parent 5e5b40a commit c6433c74820f778b9a27325d57e842337b63b8ed @brosner brosner committed with Apr 8, 2009
Showing with 48 additions and 4 deletions.
  1. +1 −1 README.rst
  2. +47 −3 dumpy/dumper.py
View
@@ -41,7 +41,7 @@ The following is an idea of what the configuration file, located at
path = /opt/local/lib/mysql5/bin/mysqldump
flags = -Q --opt --compact
- [pgdump options]
+ [pg_dump options]
path = /opt/local/lib/postgresql83/bin/pg_dump
[TimestampRename options]
View
@@ -81,6 +81,10 @@ class BackupBase(DumpyBase):
"""
Base class for database backups.
"""
+
+ def __init__(self, db):
+ self.db = db
+
def backup(self):
raise NotImplementedError
@@ -113,12 +117,11 @@ def backup(self):
self.parse_config()
if self.type == 'mysql':
return MysqlBackup(self.database).backup()
+ elif self.type == 'postgresql':
+ return PostgresqlBackup(self.database).backup()
class MysqlBackup(BackupBase):
- def __init__(self, db):
- self.db = db
-
def parse_config(self):
super(MysqlBackup, self).parse_config()
@@ -159,6 +162,47 @@ def backup(self):
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):
"""
This classes loads the specified database `postprocessing` config option

0 comments on commit c6433c7

Please sign in to comment.