Update with commands in array for calls, logging for single file restore
All commands are now run through a single array variable All logs are in logs folder for the restore which is a sub folder to where the SQL file is located On restore abort if the basic database creation failed or skip to the next database in block restore
This commit is contained in:
@@ -344,7 +344,8 @@ fi;
|
||||
# check if we can connect to template1 table, if not we abort here
|
||||
_PG_PARAMS_SELECT=("${PG_PARAMS_SELECT[@]}");
|
||||
_PG_PARAMS_SELECT+=("SELECT datname FROM pg_catalog.pg_database WHERE datname = 'template1';");
|
||||
connect=$(${PG_PSQL} "${_PG_PARAMS_SELECT[@]}") || echo "[!] pgsql connect error";
|
||||
PG_COMMAND=("${PG_PSQL}" "${_PG_PARAMS_SELECT[@]}");
|
||||
connect=$("${PG_COMMAND[@]}") || echo "[!] pgsql connect error";
|
||||
if [ "${connect}" != "template1" ]; then
|
||||
echo "Failed to connect to template1 with user '${DB_USER}' at host '${DB_HOST}' on port '${DB_PORT}'";
|
||||
exit 0;
|
||||
@@ -491,7 +492,8 @@ function get_dump_databases
|
||||
fi;
|
||||
_PG_PARAMS_SELECT=("${PG_PARAMS_SELECT[@]}");
|
||||
_PG_PARAMS_SELECT+=("SELECT pg_catalog.pg_get_userbyid(datdba) AS owner, datname, pg_catalog.pg_encoding_to_char(encoding) FROM pg_catalog.pg_database WHERE datname !~ 'template(0|1)';");
|
||||
for owner_db in $(${PG_PSQL} "${_PG_PARAMS_SELECT[@]}"); do
|
||||
PG_COMMAND=("${PG_PSQL}" "${_PG_PARAMS_SELECT[@]}");
|
||||
for owner_db in $("${PG_COMMAND[@]}"); do
|
||||
db=$(echo "${owner_db}" | cut -d "," -f 2);
|
||||
# check if we exclude this db
|
||||
exclude=0;
|
||||
@@ -615,10 +617,11 @@ if [ ${GLOBALS} -eq 1 ]; then
|
||||
# build dump parms
|
||||
_PG_PARAMS_DUMP=("${PG_PARAMS[@]}");
|
||||
_PG_PARAMS_DUMP+=("--globals-only")
|
||||
PG_COMMAND=("${PG_DUMPALL}" "${_PG_PARAMS_DUMP[@]}");
|
||||
if [ ${TEST} -eq 0 ]; then
|
||||
${PG_DUMPALL} "${_PG_PARAMS_DUMP[@]}" > "${filename}";
|
||||
"${PG_COMMAND[@]}" > "${filename}";
|
||||
else
|
||||
echo "${PG_DUMPALL} ${_PG_PARAMS_DUMP[*]} > ${filename}";
|
||||
echo "${PG_COMMAND[*]} > ${filename}";
|
||||
fi;
|
||||
echo "done";
|
||||
else
|
||||
@@ -641,7 +644,8 @@ fi;
|
||||
filesize_sum=0;
|
||||
_PG_PARAMS_SELECT=("${PG_PARAMS_SELECT[@]}");
|
||||
_PG_PARAMS_SELECT+=("SELECT pg_catalog.pg_get_userbyid(datdba) AS owner, datname, pg_catalog.pg_encoding_to_char(encoding) AS encoding FROM pg_catalog.pg_database WHERE datname !~ 'template(0|1)' ORDER BY datname;");
|
||||
for owner_db in $(${PG_PSQL} "${_PG_PARAMS_SELECT[@]}"); do
|
||||
PG_COMMAND=("${PG_PSQL}" "${_PG_PARAMS_SELECT[@]}");
|
||||
for owner_db in $("${PG_COMMAND[@]}"); do
|
||||
# get the user who owns the DB too
|
||||
owner=$(echo "${owner_db}" | cut -d "," -f 1);
|
||||
db=$(echo "${owner_db}" | cut -d "," -f 2);
|
||||
@@ -673,10 +677,11 @@ for owner_db in $(${PG_PSQL} "${_PG_PARAMS_SELECT[@]}"); do
|
||||
# build dump parms
|
||||
_PG_PARAMS_DUMP=("${PG_PARAMS[@]}");
|
||||
_PG_PARAMS_DUMP+=("-c" "--format=c" "${db}")
|
||||
PG_COMMAND=("${PG_DUMP}" "${_PG_PARAMS_DUMP[@]}");
|
||||
if [ ${TEST} -eq 0 ]; then
|
||||
${PG_DUMP} "${_PG_PARAMS_DUMP[@]}" > "${filename}";
|
||||
"${PG_COMMAND[@]}" > "${filename}";
|
||||
else
|
||||
echo "${PG_DUMP} ${_PG_PARAMS_DUMP[*]} > ${filename}";
|
||||
echo "${PG_COMMAND[*]} > ${filename}";
|
||||
fi;
|
||||
# get the file size for the dumped file and convert it to a human readable format
|
||||
filesize=0;
|
||||
|
||||
Reference in New Issue
Block a user