Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: Allow restore to different db location
......................................................................

packaging: Allow restore to different db location

Change the engine-backup.sh utility to be able to restore a backup so
that the database will have credentials (name/host/password/etc)
different from the ones used when doing the backup.

Also other fixes to this utility.

Change-Id: Ie2c84111808c638a1c589cf3c14c271184a0a7c2
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M packaging/bin/engine-backup.sh
1 file changed, 103 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/20258/1

diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh
index a2b7b09..68fa0f9 100755
--- a/packaging/bin/engine-backup.sh
+++ b/packaging/bin/engine-backup.sh
@@ -23,7 +23,14 @@
 BACKUP_FOLDERS="/etc/ovirt-engine
 /etc/pki/ovirt-engine
 /etc/ovirt-engine-setup.conf.d
-/var/lib/ovirt-engine"
+/var/lib/ovirt-engine
+/etc/httpd/conf.d/ovirt-engine-root-redirect.conf
+/etc/httpd/conf.d/ssl.conf
+/etc/httpd/conf.d/z-ovirt-engine-proxy.conf
+/etc/yum/pluginconf.d/versionlock.list
+/etc/firewalld/services/ovirt-https.xml
+/etc/firewalld/services/ovirt-http.xml
+/etc/firewalld/services/ovirt-postgres.xml"
 MYPGPASS=""
 TEMP_FOLDER=""
 FILE=""
@@ -45,16 +52,25 @@
     backup        backup system into FILE
     restore       restore system from FILE
  SCOPE is one of the following:
-    all           complete backup/restore
+    all           complete backup/restore (default)
     db            database only
  --file=FILE      file to use during backup or restore
  --log=FILE       log file to use
+
+ The following options might be used to restore the database to a different 
location:
+ --db-host=host   set database host
+ --db-port=port   set database port
+ --db-user=user   set database user
+ --db-pass=file   set database password - read from file
+ --db-name=name   set database name
+ --db-secured=sec True if connection should be secured, else False
+ --db-sec-validation=valid True if db hostname should be validated, else False
 __EOF__
        return 0
 }
 
 MODE=
-SCOPE=
+SCOPE=all
 
 parseArgs() {
        while [ -n "$1" ]; do
@@ -72,7 +88,7 @@
                        --scope=*)
                                SCOPE="${v}"
                                case "${SCOPE}" in
-                                       all|dbonly) ;;
+                                       all|db) ;;
                                        *) die "invalid scope '${SCOPE}'"
                                esac
                        ;;
@@ -81,6 +97,39 @@
                        ;;
                        --log=*)
                                LOG="${v}"
+                       ;;
+                       --db-host=*)
+                               DB_HOST="${v}"
+                       ;;
+                       --db-port=*)
+                               DB_PORT="${v}"
+                       ;;
+                       --db-user=*)
+                               DB_USER="${v}"
+                       ;;
+                       --db-pass=*)
+                               DB_PASSFILE="${v}"
+                               if ! [ -r "${DB_PASSFILE}" ]; then
+                                       die "Can not read password file 
${DB_PASSFILE}"
+                               fi
+                               read DB_PASSWORD < "${DB_PASSFILE}"
+                       ;;
+                       --db-name=*)
+                               DB_NAME="${v}"
+                       ;;
+                       --db-secured=*)
+                               DB_SECURED="${v}"
+                               case "${DB_SECURED}" in
+                                       True|False) ;;
+                                       *) die "invalid 'sec' value 
'${DB_SECURED}' for --db-secured"
+                               esac
+                       ;;
+                       --db-sec-validation=*)
+                               DB_SEC_VALIDATION="${v}"
+                               case "${DB_SEC_VALIDATION}" in
+                                       True|False) ;;
+                                       *) die "invalid 'valid' value 
'${DB_SEC_VALIDATION}' for --db-sec-validation"
+                               esac
                        ;;
                        --help)
                                usage
@@ -115,7 +164,7 @@
        mkdir "${tardir}/${FILES}" || logdie "Cannot create '${tardir}/files'"
        mkdir "${tardir}/db" || logdie "Cannot create '${tardir}/db'"
 
-       if [ "${SCOPE}" != "dbonly" ] ; then
+       if [ "${SCOPE}" != "db" ] ; then
                log "Backing up files to ${tardir}/files"
                backupFiles "${BACKUP_FOLDERS}" "${tardir}/files"
        fi
@@ -153,9 +202,13 @@
        local folders="$1"
        local target="$2"
        echo "${folders}" | while read folder; do
-               local dirname="$(dirname ${folder})"
-               mkdir -p "${tardir}/files/${dirname}" || logdie "Cannot create 
'${tardir}/files/${dirname}"
-               cp -a "${folder}" "${target}/${dirname}" || logdie "Cannot copy 
${folder} to ${target}/${dirname}"
+               if [ -e "${folder}" ]; then
+                       local dirname="$(dirname ${folder})"
+                       mkdir -p "${tardir}/files/${dirname}" || logdie "Cannot 
create '${tardir}/files/${dirname}"
+                       cp -a "${folder}" "${target}/${dirname}" || logdie 
"Cannot copy ${folder} to ${target}/${dirname}"
+               else
+                       echo "Skipping not-existant ${folder}"
+               fi
        done || logdie "Cannot read ${folders}"
 }
 
@@ -184,7 +237,7 @@
        log "Verifying version"
        verifyVersion
 
-       if [ "${SCOPE}" != "dbonly" ] ; then
+       if [ "${SCOPE}" != "db" ] ; then
                log "Restoring files"
                restoreFiles "${BACKUP_FOLDERS}"
        fi
@@ -197,6 +250,10 @@
        verifyConnection
        log "Restoring database backup at 
${TEMP_FOLDER}/db/${DB_BACKUP_FILE_NAME}"
        restoreDB "${TEMP_FOLDER}/db/${DB_BACKUP_FILE_NAME}"
+       output "Starting services:"
+       service ovirt-engine start
+       service httpd restart
+       output "Note: you might need to manually fix firewalld conf and 
autostart of ovirt-engine service"
 }
 
 verifyConnection() {
@@ -236,8 +293,44 @@
        echo "${folders}" | while read folder; do
                local dirname="$(dirname ${folder})"
                local backup="${TEMP_FOLDER}/files/${folder}"
-               cp -a "${backup}" "${dirname}" || logdie "Cannot copy 
'${backup}' to '${dirname}'"
+               if [ -e "${backup}" ]; then
+                       cp -a "${backup}" "${dirname}" || logdie "Cannot copy 
'${backup}' to '${dirname}'"
+                       selinuxenabled && restorecon -R "${folder}"
+               else
+                       echo "Skipping not-existant ${folder}"
+               fi
        done || logdie "Cannot read ${folders}"
+       changeDBConf
+}
+
+changeDBConf() {
+       local conf="/etc/ovirt-engine/engine.conf.d/10-setup-database.conf"
+       [ -f "${conf}" ] || return
+
+       local enabled=0
+       local backup="${conf}.$(date +"%Y%m%d%H%M%S")"
+       local vars="DB_HOST
+       DB_PORT
+       DB_USER
+       DB_PASSWORD
+       DB_NAME
+       DB_SECURED
+       DB_SEC_VALIDATION"
+
+       echo "${vars}" | while read var; do
+               eval "value=\${$var}"
+               if [ -n "${value}" ]; then
+                       if [ "${enabled}" = "0" ]; then
+                               log "Backing up ${conf} to ${backup}"
+                               cp -a "${conf}" "${backup}" || die "Failed to 
backup ${conf}"
+                               output "Editing ${conf}"
+                               enabled=1
+                       fi
+                       value=$(echo "${value}" | sed 's;/;\\/;g')
+                       sed -i -e "s/${var}=.*/${var}=\"${value}\"/" "${conf}" 
|| \
+                               die "Failed to edit ${conf}"
+               fi
+       done
 }
 
 generatePgPass() {


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2c84111808c638a1c589cf3c14c271184a0a7c2
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yedidyah Bar David <d...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to