Eli Mesika has uploaded a new change for review. Change subject: [WIP] core: 3.1 backup fix tool. ......................................................................
[WIP] core: 3.1 backup fix tool. backup files created with LogCollector on 3.1 will fail to restore. This is due to the fact that LogCollector is using PG pg_dump utility with the TAR format in order to backup the database. Unfortunately, there is a bug (Tom Lane claims that this is a feature,) that in case that TAR format is used the -c flag of pg_dump is not honoured and will create always DROP statements for all database objects in the generated restore.sql script. (See http://www.postgresql.org/message-id/[email protected]) The DROP statements caused DB errors when attempting to restore the backup by 1) dropping existing DB 2) re creating a new blank db with the same name 3) using pg_restore to restore database from the backup file This tool enables to fix a backup TAR file created by the LogCollector by extracting the restore.sql file from it and fixing all the problems. Then this file may be used by pg_restore to restore the database. Change-Id: Id17f718d5acf7a4df00092875d308f52e6dd7e3f Signed-off-by: Eli Mesika <[email protected]> --- A backend/manager/tools/dbutils/backupfixtool.sh A backend/manager/tools/dbutils/plpgsql.sql 2 files changed, 99 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/15068/1 diff --git a/backend/manager/tools/dbutils/backupfixtool.sh b/backend/manager/tools/dbutils/backupfixtool.sh new file mode 100755 index 0000000..991545c --- /dev/null +++ b/backend/manager/tools/dbutils/backupfixtool.sh @@ -0,0 +1,81 @@ +#!/bin/bash +############################################################################################################### +# The purpose of this utility is to fix backups done by the log collector in version 3.1 in order to use +# those backup files to create a 3.1 database before upgrading from 3.1 to 3.2 +# the log collector used to backup files in the TAR format, however , Postgres has a bug in pg_dump that +# does not honour the -c flag if TAR format is used for the backup. +# Since our restore procedure actually: +# 1)drops the database using dropdb +# 2)creates a new database using createdb +# 3)tries to restore the database schema & data from the backup file +# We end up with lot of errors generated by redundant "DROP" statements in the restore.sql file that were +# generated by pg_dump +# In addition, this tool provides a cleanup of the Postgres *uuid* function implementations since we had +# switched to our own implementation. +# +############################################################################################################### + +pushd $(dirname ${0})>/dev/null + + +usage() { + printf "Usage: ${0} [-h] -f FILE \n" + printf "\n" + printf "\t-f FILE - The backup tar file to fix\n" + printf "\t-h - This help text.\n" + printf "\n" + popd>/dev/null + exit $ret +} + + +while getopts hf: option; do + case $option in + f) FILE=$OPTARG;; + h) ret=0 && usage;; + \?) ret=1 && usage;; + esac +done + +caution() { + # Highlight the expected results of selected operation. + echo $(tput smso) $1 $(tput rmso) + echo "Caution, this operation should be used with care. Please contact support prior to running this command" + echo "Are you sure you want to proceed? [y/n]" + read answer + if [ "${answer}" = "n" ]; then + echo "Please contact support for further assistance." + popd>/dev/null + exit 1 + fi +} + +if [[ ! -n "${FILE}" ]]; then + usage + exit 1 +fi + +caution + +echo "validating the ${FILE} file type..." +if file "${FILE}" | grep 'tar'; then + echo "Extracting the restore.sql file ..." + tar -xf "$FILE" restore.sql > /dev/null + + echo "Fixing the restore.sql file..." + sed -i '/^DROP /d' ./restore.sql + sed -i '/^CREATE SCHEMA/d' ./restore.sql + sed -i '/^ALTER TABLE ONLY public\./d' ./restore.sql + sed -i '/^ALTER FUNCTION public\.uuid_/d' ./restore.sql + sed -i '/^CREATE PROCEDURAL LANGUAGE plpgsql/d' ./restore.sql + sed -i 's/^CREATE FUNCTION uuid_/CREATE OR REPLACE FUNCTION uuid_/g' ./restore.sql + echo "replacing the restore.sql file in original tar file..." + tar -rvf ${FILE} ./restore.sql + echo "Operation completed successfully." +else + echo "Error: The file ${FILE} is not a tar file." + usage +fi + +popd>/dev/null +exit ${status} diff --git a/backend/manager/tools/dbutils/plpgsql.sql b/backend/manager/tools/dbutils/plpgsql.sql new file mode 100644 index 0000000..85dc506 --- /dev/null +++ b/backend/manager/tools/dbutils/plpgsql.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE FUNCTION make_plpgsql() +RETURNS VOID +LANGUAGE SQL +AS $$ +CREATE LANGUAGE plpgsql; +$$; + +SELECT + CASE + WHEN EXISTS( + SELECT 1 + FROM pg_catalog.pg_language + WHERE lanname='plpgsql' + ) + THEN NULL + ELSE make_plpgsql() END; + +DROP FUNCTION make_plpgsql(); -- To view, visit http://gerrit.ovirt.org/15068 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id17f718d5acf7a4df00092875d308f52e6dd7e3f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Eli Mesika <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
