Eli Mesika has posted comments on this change.
Change subject: core: adding utility for db objects owner change
......................................................................
Patch Set 2:
(10 comments)
....................................................
File packaging/setup/dbutils/changedbowner.sh
Line 4: # database from ${FROM_USER} to ${TO_USER}
Line 5: ################################################################
Line 6:
Line 7: #include db general functions
Line 8: pushd $(dirname ${0})>/dev/null
Done
Line 9: source ./common.sh
Line 10:
Line 11: #setting defaults
Line 12: set_defaults
Line 17: printf "\t-s SERVERNAME - The database servername for the database
(def. ${SERVERNAME})\n"
Line 18: printf "\t-p PORT - The database port for the database
(def. ${PORT})\n"
Line 19: printf "\t-d DATABASE - The database name
(def. ${DATABASE})\n"
Line 20: printf "\t-f FROM_USER - The current owner for the database
\n"
Line 21: printf "\t-f TO_USER - The new owner for the database
\n"
Done
Line 22: printf "\t-h - This help text.\n"
Line 23: printf "\n"
Line 24: popd>/dev/null
Line 25: exit $ret
Line 20: printf "\t-f FROM_USER - The current owner for the database
\n"
Line 21: printf "\t-f TO_USER - The new owner for the database
\n"
Line 22: printf "\t-h - This help text.\n"
Line 23: printf "\n"
Line 24: popd>/dev/null
Done
Line 25: exit $ret
Line 26: }
Line 27:
Line 28:
Line 21: printf "\t-f TO_USER - The new owner for the database
\n"
Line 22: printf "\t-h - This help text.\n"
Line 23: printf "\n"
Line 24: popd>/dev/null
Line 25: exit $ret
see below , in the while loop, this is commonly used in our scripts
Line 26: }
Line 27:
Line 28:
Line 29: while getopts hs:p:d:f:t: option; do
Line 43: fi
Line 44:
Line 45: # Change all schema objects ownership
Line 46: echo "Changing database ${DATABASE} objects ownership"
Line 47: pg_dump -s -h "${SERVERNAME}" -p ${PORT} -U postgres "${DATABASE}" |
grep -i 'owner to' | sed "s/OWNER TO ${FROM_USER};/OWNER TO ${TO_USER};/i" |
psql -h "${SERVERNAME}" -p ${PORT} -U ${FROM_USER} "${DATABASE}"
Done
Line 48:
Line 49: if [[ $PIPESTATUS -ne 0 ]]; then
Line 50: echo "Failed to change DB ${DATABASE} objects ownership."
Line 51: popd>/dev/null
Line 45: # Change all schema objects ownership
Line 46: echo "Changing database ${DATABASE} objects ownership"
Line 47: pg_dump -s -h "${SERVERNAME}" -p ${PORT} -U postgres "${DATABASE}" |
grep -i 'owner to' | sed "s/OWNER TO ${FROM_USER};/OWNER TO ${TO_USER};/i" |
psql -h "${SERVERNAME}" -p ${PORT} -U ${FROM_USER} "${DATABASE}"
Line 48:
Line 49: if [[ $PIPESTATUS -ne 0 ]]; then
OK, the status is not good enough , it will show only the last command in the
pipe status , so , I must capture other failures along the piped commands
Line 50: echo "Failed to change DB ${DATABASE} objects ownership."
Line 51: popd>/dev/null
Line 52: exit 1
Line 53: fi
Line 47: pg_dump -s -h "${SERVERNAME}" -p ${PORT} -U postgres "${DATABASE}" |
grep -i 'owner to' | sed "s/OWNER TO ${FROM_USER};/OWNER TO ${TO_USER};/i" |
psql -h "${SERVERNAME}" -p ${PORT} -U ${FROM_USER} "${DATABASE}"
Line 48:
Line 49: if [[ $PIPESTATUS -ne 0 ]]; then
Line 50: echo "Failed to change DB ${DATABASE} objects ownership."
Line 51: popd>/dev/null
Done
Line 52: exit 1
Line 53: fi
Line 54:
Line 55: #change the DB ownership
Line 58: psql -w -h "${SERVERNAME}" -p ${PORT} --pset=tuples_only=on --set
ON_ERROR_STOP=1 -c "${cmd}" -U ${FROM_USER} -d "${DATABASE}"
Line 59:
Line 60: if [ $? -ne 0 ]; then
Line 61: echo "Failed to change DB ${DATABASE} ownership."
Line 62: popd>/dev/null
Done
Line 63: exit 2
Line 64: fi
Line 65:
Line 66: echo "Changing database ${DATABASE} ownership from ${FROM_USER} to
${TO_USER} completed successfully."
Line 63: exit 2
Line 64: fi
Line 65:
Line 66: echo "Changing database ${DATABASE} ownership from ${FROM_USER} to
${TO_USER} completed successfully."
Line 67: popd>/dev/null
Done
Line 68: exit 0
Line 69:
Line 66: echo "Changing database ${DATABASE} ownership from ${FROM_USER} to
${TO_USER} completed successfully."
Line 67: popd>/dev/null
Line 68: exit 0
Line 69:
Line 70:
Done
--
To view, visit http://gerrit.ovirt.org/18682
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I56c59c0fe749389bd110bcd1a39faae74e71174b
Gerrit-PatchSet: 2
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
Gerrit-Reviewer: Alon Bar-Lev <[email protected]>
Gerrit-Reviewer: Eli Mesika <[email protected]>
Gerrit-Reviewer: Yair Zaslavsky <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches