Nextcloud Postgres Backup

Hello,

i want to backup the Database of the Nextcloud-App which runs on docker but i don´t find the right user or password.
With "PGPASSWORD=“Password from /var/lib/univention-appcenter/apps/nextcloud/conf/admin.secret " pg_dump nextcloud -h localhost -U nc_admin -f nextcloud-sqlbkp_date +"%Y%m%d".bak” I get "FATAL: Passwort-Authentifizierung für Benutzer nc_admin fehlgeschlagen.
Can anybody give me a hint?

regards Ari

Hi,

I think that that admin does not (and should not?) have rights to the database. This account is a user in the application and usually an account with another name is used for the database.
If you look into the config.php you will notice dbuser (most likely nextcloud) and dbpassword which might be a better choice.
The password is also stored in the file /etc/postgresql-nextcloud.secret.

hth,
Dirk

You certainly don’t need the password. Instead simply run the pg_dump command as the Linux user postgres. PostgreSQL is configured to accept connections from that user without a password; the user has superuser privileges:

sudo -i -u postgres pg_dump nextcloud > /wherever/nextcloud-$(date '+%Y%m%d').sql
2 Likes

Thank you guys! sudo -i -u postgres pg_dump nextcloud > /wherever/nextcloud-$(date '+%Y%m%d').sql was the solution.

Just as an addition: The default plaintext sql dump that pg_dump creates is not compatible with pg_restore (been there and surprised - we’d need to utilize psql in this case). That’s why I’d recommend to also use --format=custom or --format=directory with pg_dump. Those can be used with pg_restore and are compressed by default.

https://www.postgresql.org/docs/9.6/app-pgdump.html
https://www.postgresql.org/docs/9.6/app-pgrestore.html

Ok. Can you give me a hint how I can restore the Backup as i made above? I am not so familiar with psql.

Thank you

Mastodon