1. Colin Copeland
  2. dbbu

Commits

Colin Copeland  committed 460067f

allow database specification; fix fmod configuration default

  • Participants
  • Parent commits be1875f
  • Branches default

Comments (0)

Files changed (2)

File dbbu.py

View file
 )
 
 
-DATABASES_TO_IGNORE = ('template0', )
+DATABASES_TO_IGNORE = set(['template0'])
 logging.basicConfig(stream=sys.stdout,
                     level=logging.DEBUG)
 
 class Backup(object):
     """ Base backup class to handle common remote commands """
 
-    def __init__(self, host, dest, sudo='', compression='gzip', fmod=0600):
+    def __init__(self, host, dest, **kwargs):
         self.host = host
-        self.sudo_user = sudo
-        self.compression = compression
         self.dest = os.path.join(dest, self.host)
-        self.fmod = fmod
+        self.compression = kwargs.pop('compression', 'gzip')
+        self.sudo_user = kwargs.pop('sudo_user', '')
+        self.fmod = kwargs.pop('fmod', 0600)
+        databases = kwargs.pop('databases', [])
+        self.databases = set(databases)
         if not os.path.exists(self.dest):
             os.makedirs(self.dest)
 
 
     def run(self):
         self.backup_postgres_globals()
-        databases = filter(lambda x: x not in DATABASES_TO_IGNORE,
-                           self.get_postgres_databases())
+        databases = set(self.get_postgres_databases())
+        if self.databases:
+            databases = self.databases
+        databases -= DATABASES_TO_IGNORE
         logging.info('databases: %s', databases)
         for database in databases:
             logging.info('backing up %s' % database)

File scripts/dbbu-run.py

View file
 
 def main():
     (options, cfg_path) = parser.parse_args()
-    defaults = {'fmod': 0600}
+    defaults = {'fmod': '0600'}
     cfg = ConfigParser.RawConfigParser(defaults)
     cfg.read(cfg_path)
     shared = {
             data['host'] = '%s@%s' % (cfg.get(host, 'user'), host)
         data.update(shared)
         if cfg.has_option(host, 'postgres'):
+            databases = cfg.get(host, 'postgres')
+            if databases != 'ALL':
+                data['databases'] = databases.split(',')
             engines.append(dbbu.PostgreSQL(**data))
         if cfg.has_option(host, 'mysql'):
             engines.append(dbbu.MySQL(**data))