Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions nextcloud_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -906,15 +906,34 @@ fi
if is_this_installed postgresql-common
then
cd /tmp
if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCDB'" | grep "1 row" > /dev/null
# Test connection to PostgreSQL
if ! sudo -u postgres psql -c "\q"
then
print_text_in_color "$ICyan" "Doing pgdump of $NCDB..."
check_command sudo -u postgres pg_dump -Fc "$NCDB" > "$BACKUP"/nextclouddb.dump
# Import:
# sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ncadmin -d nextcloud_db "$BACKUP"/nextclouddb.dump
# If it fails, trust the 'postgres' user to be able to perform backup
sed -i "s|local all postgres .*|local all postgres trust|g" /etc/post>
systemctl restart postgresql.service
if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCDB'" | grep "1 row" > /dev/null
then
print_text_in_color "$ICyan" "Doing pgdump of $NCDB..."
check_command sudo -u postgres pg_dump -Fc "$NCDB" > "$BACKUP"/nextclouddb.dump
# Import:
# sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ncadmin -d nextcloud_db "$BACKUP"/nextclouddb.dump
else
print_text_in_color "$ICyan" "Doing pgdump of all databases..."
check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.dump
fi
else
print_text_in_color "$ICyan" "Doing pgdump of all databases..."
check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.dump
# If there's no issues, then continue as normal
if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCDB'" | grep "1 row" > /dev/null
then
print_text_in_color "$ICyan" "Doing pgdump of $NCDB..."
check_command sudo -u postgres pg_dump -Fc "$NCDB" > "$BACKUP"/nextclouddb.dump
# Import:
# sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ncadmin -d nextcloud_db "$BACKUP"/nextclouddb.dump
else
print_text_in_color "$ICyan" "Doing pgdump of all databases..."
check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.dump
fi
fi
fi

Expand Down