Alex Lourie has uploaded a new change for review.

Change subject: packaging: Updated all utilities to use backup.sh instead of 
pg_dump
......................................................................

packaging: Updated all utilities to use backup.sh instead of pg_dump

* Previously, the setup utilities used pg_dump command to backup the
database. The more appropriate way is to use the backup.sh utility,
that runs the dump of the database in a more correct and way. This
also has the added benifit in that changes in DB mechanisms or parameters
for dumping the data would be handled by the external script, and
changes to the setup code would not be required.

Change-Id: I011bc64d989cfba602977fd3f9522ea2c329aedc
Signed-off-by: Alex Lourie <alou...@redhat.com>
---
M packaging/fedora/setup/basedefs.py
M packaging/fedora/setup/common_utils.py
M packaging/fedora/setup/engine-cleanup.py
M packaging/fedora/setup/engine-upgrade.py
4 files changed, 39 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/10548/1

diff --git a/packaging/fedora/setup/basedefs.py 
b/packaging/fedora/setup/basedefs.py
index 6f574f7..75398ec 100644
--- a/packaging/fedora/setup/basedefs.py
+++ b/packaging/fedora/setup/basedefs.py
@@ -74,6 +74,7 @@
 FILE_JBOSSAS_CONF="/etc/%s/%s.conf" % (ENGINE_SERVICE_NAME, 
ENGINE_SERVICE_NAME)
 FILE_DB_INSTALL_SCRIPT="engine-db-install.sh"
 FILE_DB_UPGRADE_SCRIPT="upgrade.sh"
+FILE_DB_BACKUP_SCRIPT="backup.sh"
 FILE_DB_ASYNC_TASKS="%s/scripts/add_fn_db_get_async_tasks_function.sql" % 
DIR_ENGINE
 FILE_ENGINE_CONFIG_BIN="/usr/bin/engine-config"
 FILE_ENGINE_CONFIG_PROPS="engine-config-install.properties"
diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index 2507d28..7d20bb2 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -799,32 +799,33 @@
 
     return False
 
-def backupDB(db, user, backupFile, host="localhost", port="5432"):
+
+def backupDB(db, backup_file, env, user, host="localhost", port="5432"):
     """
     Backup postgres db
-    using pgdump
+    using backup.sh
     Args:  file - a target file to backup to
            db - db name to backup
            user - db user to use for backup
            host - db host where postgresql server runs
            port - db connection port
     """
-    logging.debug("%s DB Backup started"%(db))
+    logging.debug("%s DB Backup started", db)
+
+    # Run backup
+    db_backup = os.path.join(basedefs.DIR_DB_SCRIPTS,
+                             basedefs.FILE_DB_BACKUP_SCRIPT)
     cmd = [
-        basedefs.EXEC_PGDUMP,
-        "-C", "-E",
-        "UTF8",
-        "--disable-dollar-quoting",
-        "--disable-triggers",
-        "--format=p",
-        "-f", backupFile,
-        "-U", user,
-        "-h", host,
+        db_backup,
+        "-u", user,
+        "-s", host,
         "-p", port,
-        db,
+        "-d", db,
+        "-f", backup_file,
     ]
-    output, rc = execCmd(cmdList=cmd, failOnError=True, 
msg=output_messages.ERR_DB_BACKUP, envDict=getPgPassEnv())
-    logging.debug("%s DB Backup completed successfully"%(db))
+    execCmd(cmdList=cmd, cwd=basedefs.DIR_DB_SCRIPTS, failOnError=True, 
msg=output_messages.ERR_DB_BACKUP, envDict=env)
+    logging.debug("%s DB Backup completed successfully", db)
+
 
 def restoreDB(user, host, port, backupFile):
     """
diff --git a/packaging/fedora/setup/engine-cleanup.py 
b/packaging/fedora/setup/engine-cleanup.py
index cfe24a0..fc02ecb 100755
--- a/packaging/fedora/setup/engine-cleanup.py
+++ b/packaging/fedora/setup/engine-cleanup.py
@@ -276,26 +276,17 @@
 
     def backup(self):
         """
-        Backup db using pg_dump
+        Backup db using backup.sh
         """
-        # pg_dump -C -E UTF8  --column-inserts --disable-dollar-quoting  
--disable-triggers -U postgres --format=p -f $dir/$file  dbname
-        logging.debug("DB Backup started")
-
-        # .pgpass update
-        cmd = [
-            basedefs.EXEC_PGDUMP,
-            "-C", "-E", "UTF8",
-            "--disable-dollar-quoting",
-            "--disable-triggers",
-            "-U", DB_ADMIN,
-            "-h", DB_HOST,
-            "-p", DB_PORT,
-            "--format=p",
-            "-f", self.sqlfile,
-            basedefs.DB_NAME,
-        ]
-        utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_BACKUP_DB, 
envDict=self.env)
-        logging.debug("DB Backup completed successfully")
+        # backup.sh -u postgres -f $file -d dbname -s server -p port
+        utils.backupDB(
+            db=basedefs.DB_NAME,
+            backup_file=self.sqlfile,
+            env=self.env,
+            user=DB_ADMIN,
+            host=DB_HOST,
+            port=DB_PORT,
+        )
 
     def drop(self):
         """
diff --git a/packaging/fedora/setup/engine-upgrade.py 
b/packaging/fedora/setup/engine-upgrade.py
index 3b7c097..9383305 100755
--- a/packaging/fedora/setup/engine-upgrade.py
+++ b/packaging/fedora/setup/engine-upgrade.py
@@ -351,23 +351,18 @@
             print "* %s %s" % (MSG_INFO_DB_BACKUP_FILE, self.sqlfile)
 
     def backup(self):
-        logging.debug("DB Backup started")
-        #cmd = "%s -C -E UTF8 --column-inserts --disable-dollar-quoting  
--disable-triggers -U %s -h %s -p %s --format=p -f %s %s"\
-            #%(basedefs.EXEC_PGDUMP, SERVER_ADMIN, SERVER_HOST, SERVER_PORT, 
self.sqlfile, basedefs.DB_NAME)
-        cmd = [
-            basedefs.EXEC_PGDUMP,
-            "-C", "-E", "UTF8",
-            "--disable-dollar-quoting",
-            "--disable-triggers",
-            "-U", SERVER_ADMIN,
-            "-h", SERVER_NAME,
-            "-p", SERVER_PORT,
-            "--format=p",
-            "-f", self.sqlfile,
-            basedefs.DB_NAME,
-        ]
-        output, rc = utils.execCmd(cmdList=cmd, failOnError=True, 
msg=MSG_ERROR_BACKUP_DB, envDict=utils.getPgPassEnv())
-        logging.debug("DB Backup completed successfully")
+        """
+        Backup db using backup.sh
+        """
+        # backup.sh -u postgres -f $file -d dbname -s server -p port
+        utils.backupDB(
+            db=basedefs.DB_NAME,
+            backup_file=self.sqlfile,
+            env=utils.getPgPassEnv(),
+            user=SERVER_ADMIN,
+            host=SERVER_NAME,
+            port=SERVER_PORT,
+        )
 
     def restore(self):
         # run psql -U engine -h host -p port -d template1 -f <backup 
directory>/<backup_file>


--
To view, visit http://gerrit.ovirt.org/10548
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I011bc64d989cfba602977fd3f9522ea2c329aedc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alex Lourie <alou...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to