Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: engine-backup: Restore: Cleanup temp tables
......................................................................

packaging: engine-backup: Restore: Cleanup temp tables

Change-Id: I0dd296b9eea7f1ba25bab024321b09b214508511
Bug-Url: https://bugzilla.redhat.com/1188130
Signed-off-by: Yedidyah Bar David <[email protected]>
---
M packaging/bin/engine-backup.sh
1 file changed, 40 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/39792/1

diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh
index ba1f677..8fee6cf 100755
--- a/packaging/bin/engine-backup.sh
+++ b/packaging/bin/engine-backup.sh
@@ -120,6 +120,13 @@
 ${p}"
 done
 
+ENGINE_TABLES_TO_CLEAN_ON_RESTORE="async_tasks
+async_tasks_entities
+business_entity_snapshot
+command_entities
+job
+step"
+
 MYPGPASS=""
 TEMP_FOLDER=""
 FILE=""
@@ -149,6 +156,7 @@
     reportsdb                       reports database only
  --file=FILE                        file to use during backup or restore
  --log=FILE                         log file to use
+ --keep-temporary-data              Do not cleanup temporary data on restore
  --change-db-credentials            activate the following options, to restore
                                     the Engine database to a different location
                                    etc. If used, existing credentials are 
ignored.
@@ -232,6 +240,7 @@
 SCOPE_ENGINE_DB=
 SCOPE_DWH_DB=
 SCOPE_REPORTS_DB=
+KEEP_TEMPORARY_DATA=
 CHANGE_DB_CREDENTIALS=
 MY_DB_HOST=
 MY_DB_PORT=5432
@@ -290,6 +299,9 @@
                        ;;
                        --log=*)
                                LOG="${v}"
+                       ;;
+                       --keep-temporary-data)
+                               KEEP_TEMPORARY_DATA=1
                        ;;
                        --change-db-credentials)
                                CHANGE_DB_CREDENTIALS=1
@@ -613,6 +625,10 @@
                output "- Engine database '"${ENGINE_DB_DATABASE}"'"
                log "Restoring engine database backup at 
${TEMP_FOLDER}/db/${DB_BACKUP_FILE_NAME}"
                restoreDB "${TEMP_FOLDER}/db/${DB_BACKUP_FILE_NAME}" 
"${ENGINE_DB_USER}" "${ENGINE_DB_HOST}" "${ENGINE_DB_PORT}" 
"${ENGINE_DB_DATABASE}" "${ORIG_DB_USER}"
+               if [ -z "${KEEP_TEMPORARY_DATA}" ]; then
+                       output "Cleaning up temporary tables in engine database 
'${ENGINE_DB_DATABASE}':"
+                       cleanDbTempData "${ENGINE_DB_USER}" "${ENGINE_DB_HOST}" 
"${ENGINE_DB_PORT}" "${ENGINE_DB_DATABASE}" 
"${ENGINE_TABLES_TO_CLEAN_ON_RESTORE}"
+               fi
        fi
        if [ -n "${SCOPE_DWH_DB}" -a -n "${DWH_DB_USER}" ]; then
                output "- DWH database '"${DWH_DB_DATABASE}"'"
@@ -741,6 +757,30 @@
        [ ${numerrors} -ne 0 ] && logdie "Errors while restoring database 
${database}"
 }
 
+cleanDbTempData() {
+       local user="$1"
+       local host="$2"
+       local port="$3"
+       local database="$4"
+       local tables_to_clean="$5"
+       local psqllog="${TEMP_FOLDER}/psql-cleanup-log"
+       echo "${tables_to_clean}" | while read -r table; do
+               output "- ${table}"
+               PGPASSFILE="${MYPGPASS}" psql \
+                       -w \
+                       -t \
+                       -U "${user}" \
+                       -h "${host}" \
+                       -p "${port}" \
+                       -d "${database}" \
+                       -c "TRUNCATE TABLE ${table} cascade" \
+                       > "${psqllog}"  2>&1 \
+                       || logdie "Failed cleaning up ${table}"
+                       cat "${psqllog}" >> "${LOG}"  2>&1 \
+                               || logdie "Failed to append psql log to restore 
log"
+       done
+}
+
 restoreFiles() {
        local paths="$1"
        echo "${paths}" | while read -r path; do


-- 
To view, visit https://gerrit.ovirt.org/39792
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0dd296b9eea7f1ba25bab024321b09b214508511
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yedidyah Bar David <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to