Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

integrated pgsql support into tklbam

  • Loading branch information...
commit 70e169bf38ab3fed615fb0de6c92bd879d9f4817 1 parent ef89872
@lirazsiri lirazsiri authored
View
10 backup.py
@@ -23,6 +23,7 @@
from pkgman import Packages
import mysql
+import pgsql
from utils import AttrDict
@@ -40,7 +41,7 @@ def __init__(self, path=None):
def __new__(cls, path=None):
return str.__new__(cls, path)
- files = [ 'backup-conf', 'fsdelta', 'fsdelta-olist', 'newpkgs', 'myfs', 'etc', 'etc/mysql' ]
+ files = [ 'backup-conf', 'fsdelta', 'fsdelta-olist', 'newpkgs', 'pgfs', 'myfs', 'etc', 'etc/mysql' ]
def _rmdir(path):
if exists(path):
@@ -132,10 +133,15 @@ def _create_extras(cls, extras, profile, conf):
if not conf.skip_database:
try:
mysql.backup(extras.myfs, extras.etc.mysql,
- limits=conf.overrides.db)
+ limits=conf.overrides.mydb)
except mysql.Error:
pass
+ try:
+ pgsql.backup(extras.pgfs, conf.overrides.pgdb)
+ except pgsql.Error:
+ pass
+
def __init__(self, profile, overrides,
skip_files=False, skip_packages=False, skip_database=False, resume=False, verbose=True):
View
8 cmd_internals/cmd_pgsql2fs.py
@@ -40,13 +40,7 @@ def main():
outdir = args[0]
limits = args[1:]
- if isdir(outdir):
- shutil.rmtree(outdir)
-
- if not exists(outdir):
- os.mkdir(outdir)
-
- pgsql.pgsql2fs(outdir, limits)
+ pgsql.backup(outdir, limits)
if __name__ == "__main__":
main()
View
28 pgsql.py
@@ -37,7 +37,7 @@ def list_databases():
name = m.group(1)
yield name
-def dumpdb(outdir, name, tlimits):
+def dumpdb(outdir, name, tlimits=[]):
path = join(outdir, name)
if isdir(path):
shutil.rmtree(path)
@@ -55,7 +55,7 @@ def dumpdb(outdir, name, tlimits):
manifest = getoutput(su(pg_dump) + " | tar xvC %s" % path)
file(join(path, FNAME_MANIFEST), "w").write(manifest + "\n")
-def restoredb(dbdump, dbname, tlimits):
+def restoredb(dbdump, dbname, tlimits=[]):
manifest = file(join(dbdump, FNAME_MANIFEST)).read().splitlines()
try:
@@ -78,7 +78,7 @@ def restoredb(dbdump, dbname, tlimits):
finally:
os.chdir(orig_cwd)
-def pgsql2fs(outdir, limits):
+def pgsql2fs(outdir, limits=[]):
limits = DBLimits(limits)
for dbname in list_databases():
@@ -90,7 +90,7 @@ def pgsql2fs(outdir, limits):
globals = getoutput(su("pg_dumpall --globals"))
file(join(outdir, FNAME_GLOBALS), "w").write(globals)
-def fs2pgsql(outdir, limits):
+def fs2pgsql(outdir, limits=[]):
limits = DBLimits(limits)
for (database, table) in limits.tables:
if (database, table) not in limits:
@@ -106,3 +106,23 @@ def fs2pgsql(outdir, limits):
continue
restoredb(fpath, dbname, limits[dbname])
+
+def backup(outdir, limits=[]):
+ if isdir(outdir):
+ shutil.rmtree(outdir)
+
+ if not exists(outdir):
+ os.makedirs(outdir)
+
+ try:
+ pgsql2fs(outdir, limits)
+ except Exception, e:
+ if isdir(outdir):
+ shutil.rmtree(outdir)
+ raise Error("pgsql backup failed: " + str(e))
+
+def restore(path, limits=[]):
+ try:
+ fs2pgsql(path, limits)
+ except Exception, e:
+ raise Error("pgsql restore failed: " + str(e))
View
27 restore.py
@@ -24,6 +24,7 @@
import backup
import conf
import mysql
+import pgsql
from temp import TempFile
@@ -59,7 +60,7 @@ def __init__(self, backup_extract_path, limits=[], rollback=True, simulate=False
self.backup_extract_path = backup_extract_path
def database(self):
- if not exists(self.extras.myfs):
+ if not exists(self.extras.myfs) and not exists(self.extras.pgfs):
return
if self.rollback:
@@ -67,12 +68,26 @@ def database(self):
print "\n" + self._title("Restoring databases")
- try:
- mysql.restore(self.extras.myfs, self.extras.etc.mysql,
- limits=self.limits.db, callback=mysql.cb_print(), simulate=self.simulate)
+ if exists(self.extras.myfs):
+ try:
+ mysql.restore(self.extras.myfs, self.extras.etc.mysql,
+ limits=self.limits.mydb, callback=mysql.cb_print(), simulate=self.simulate)
+
+ except mysql.Error, e:
+ print "SKIPPING MYSQL DATABASE RESTORE: " + str(e)
+
+ if exists(self.extras.pgfs):
+
+ if self.simulate:
+ print "CAN't SIMULATE PGSQL RESTORE, SKIPPING"
+ return
+
+ try:
+ pgsql.restore(self.extras.pgfs, self.limits.pgdb)
+
+ except pgsql.Error, e:
+ print "SKIPPING PGSQL DATABASE RESTORE: " + str(e)
- except mysql.Error, e:
- print "SKIPPING MYSQL DATABASE RESTORE: " + str(e)
def packages(self):
newpkgs_file = self.extras.newpkgs
View
17 rollback.py
@@ -16,9 +16,11 @@
import shutil
from datetime import datetime
-from paths import Paths
+from paths import Paths as _Paths
import mysql
+import pgsql
+
from changes import Changes
from dirindex import DirIndex
from pkgman import Packages
@@ -33,10 +35,10 @@ class Rollback:
Error = Error
PATH = "/var/backups/tklbam-rollback"
- class Paths(Paths):
+ class Paths(_Paths):
files = [ 'etc', 'etc/mysql',
'fsdelta', 'dirindex', 'originals',
- 'newpkgs', 'myfs' ]
+ 'newpkgs', 'myfs', 'pgfs' ]
@classmethod
def create(cls, path=PATH):
@@ -138,6 +140,9 @@ def rollback_database(self):
mysql.restore(self.paths.myfs, self.paths.etc.mysql,
add_drop_database=True)
+ if exists(self.paths.pgfs):
+ pgsql.restore(self.paths.pgfs)
+
def rollback(self):
exceptions = 0
for method in (self.rollback_database, self.rollback_files, self.rollback_new_packages):
@@ -181,3 +186,9 @@ def save_database(self):
mysql.backup(self.paths.myfs, self.paths.etc.mysql)
except mysql.Error:
pass
+
+ try:
+ pgsql.backup(self.paths.pgfs)
+ except pgsql.Error:
+ pass
+
Please sign in to comment.
Something went wrong with that request. Please try again.