Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added PostgreSQL support.

Signed-off-by: Clint Ecker <clint@arstechnica.com>
  • Loading branch information...
commit 109567cede70adf2703be136107163f3ffe48807 1 parent dd18049
@brosner brosner authored Clint Ecker committed
Showing with 48 additions and 4 deletions.
  1. +1 −1  README.rst
  2. +47 −3 dumpy/dumper.py
View
2  README.rst
@@ -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
50 dumpy/dumper.py
@@ -105,6 +105,10 @@ class BackupBase(DumpyBase):
"""
Base class for database backups.
"""
+
+ def __init__(self, db):
+ self.db = db
+
def backup(self):
raise NotImplementedError
@@ -137,12 +141,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()
@@ -183,6 +186,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
Please sign in to comment.
Something went wrong with that request. Please try again.