mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-02-16 10:40:21 +00:00
Merge pull request #1557 from nextcloud/enh/1553/improve-import
improve database import
This commit is contained in:
commit
be6bcfe997
1 changed files with 23 additions and 1 deletions
|
|
@ -20,6 +20,13 @@ if ! [ -w "$DUMP_DIR" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Don't start if import failed
|
||||||
|
if [ -f "$DUMP_DIR/import.failed" ]; then
|
||||||
|
echo "The database import failed. Please restore a backup and try again."
|
||||||
|
echo "For further clues on what went wrong, look at the logs above."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Delete the datadir once (needed for setting the correct credentials on old instances once)
|
# Delete the datadir once (needed for setting the correct credentials on old instances once)
|
||||||
if ! [ -f "$DUMP_DIR/export.failed" ] && ! [ -f "$DUMP_DIR/initial-cleanup-done" ]; then
|
if ! [ -f "$DUMP_DIR/export.failed" ] && ! [ -f "$DUMP_DIR/initial-cleanup-done" ]; then
|
||||||
set -ex
|
set -ex
|
||||||
|
|
@ -45,9 +52,16 @@ if ( [ -f "$DATADIR/PG_VERSION" ] && [ "$PG_MAJOR" != "$(cat "$DATADIR/PG_VERSIO
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Write output to logfile.
|
||||||
|
exec > >(tee -i "$DUMP_DIR/database-import.log")
|
||||||
|
exec 2>&1
|
||||||
|
|
||||||
# Inform
|
# Inform
|
||||||
echo "Restoring from database dump."
|
echo "Restoring from database dump."
|
||||||
|
|
||||||
|
# Add import.failed file
|
||||||
|
touch "$DUMP_DIR/import.failed"
|
||||||
|
|
||||||
# Exit if any command fails
|
# Exit if any command fails
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
|
@ -76,7 +90,12 @@ if ( [ -f "$DATADIR/PG_VERSION" ] && [ "$PG_MAJOR" != "$(cat "$DATADIR/PG_VERSIO
|
||||||
|
|
||||||
# Get the Owner
|
# Get the Owner
|
||||||
DB_OWNER="$(grep "$GREP_STRING" "$DUMP_FILE" | grep -oP 'Owner:.*$' | sed 's|Owner:||;s| ||g')"
|
DB_OWNER="$(grep "$GREP_STRING" "$DUMP_FILE" | grep -oP 'Owner:.*$' | sed 's|Owner:||;s| ||g')"
|
||||||
if [ "$DB_OWNER" != "oc_$POSTGRES_USER" ]; then
|
if [ "$DB_OWNER" = "$POSTGRES_USER" ]; then
|
||||||
|
DIFFERENT_DB_OWNER=1
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
ALTER DATABASE "$POSTGRES_DB" OWNER TO "$POSTGRES_USER";
|
||||||
|
EOSQL
|
||||||
|
elif [ "$DB_OWNER" != "oc_$POSTGRES_USER" ]; then
|
||||||
DIFFERENT_DB_OWNER=1
|
DIFFERENT_DB_OWNER=1
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
CREATE USER "$DB_OWNER" WITH PASSWORD '$POSTGRES_PASSWORD' CREATEDB;
|
CREATE USER "$DB_OWNER" WITH PASSWORD '$POSTGRES_PASSWORD' CREATEDB;
|
||||||
|
|
@ -104,6 +123,9 @@ EOSQL
|
||||||
|
|
||||||
# Don't exit if command fails anymore
|
# Don't exit if command fails anymore
|
||||||
set +ex
|
set +ex
|
||||||
|
|
||||||
|
# Remove import failed file if everything went correctly
|
||||||
|
rm "$DUMP_DIR/import.failed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cover the last case
|
# Cover the last case
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue