1. lakin.wecker
  2. baste

Commits

lakin.wecker  committed 4d257fa

adding a way to load gzipped mysql backups."

  • Participants
  • Parent commits 9894d15
  • Branches default

Comments (0)

Files changed (1)

File baste/__init__.py

View file
  • Ignore whitespace
     'PgShell',
     'PgLoadPlain',
     'MysqlLoadPlain',
+    'MysqlLoadGzip',
     'project_relative',
     'python_dependency',
     'Repository',
 #-------------------------------------------------------------------------------
 class MysqlLoadPlain(object):
     #--------------------------------------------------------------------------- 
-    def __init__(self, file, db, user):
+    def __init__(self, file, db, user, password=None):
         self.file = file
         self.db = db
         self.user = user
+        self.password = password
 
     #---------------------------------------------------------------------------
     def __call__(self):
         """Uses mysql command line client to load a plain dump format."""
-        baste_env.run(
-            "mysql -h localhost -u %s -p %s < %s" % (self.user, self.db, self.file)
-        )
+        if not self.password:
+            baste_env.run(
+                "mysql -h localhost -u %s -p %s < %s" % (self.user, self.db, self.file)
+            )
+        else:
+            baste_env.run(
+                "mysql -h localhost -u %s -p%s %s < %s" % (self.user, self.password, self.db, self.file)
+            )
+
+#-------------------------------------------------------------------------------
+class MysqlLoadGzip(object):
+    #--------------------------------------------------------------------------- 
+    def __init__(self, file, db, user, password=None):
+        self.file = file
+        self.db = db
+        self.user = user
+        self.password = password
+
+    #---------------------------------------------------------------------------
+    def __call__(self):
+        """Uses mysql command line client to load a plain dump format."""
+        if not self.password:
+            baste_env.run(
+                "gunzip --stdout %s | mysql -h localhost -u %s -p %s" % (self.file, self.user, self.db)
+            )
+        else:
+            baste_env.run(
+                "gunzip --stdout %s | mysql -h localhost -u %s -p%s %s" % (self.file, self.user, self.password, self.db)
+            )
 
 #-------------------------------------------------------------------------------
 class RsyncMedia(object):