NextCloud Back for migration

I am looking to migrate from my current instance of NextCloud and have a pretty good idea on how to backup my Data and Themes folders but cant seem to figure out how to get a copy of my postgress database. I assume it would be a command like “sudo docker exec ix-nextcloud-postgres-1 pg_dump -c -U admin nextcloud > nextcloud-sqlbkp_date +"%Y%m%d".bak” although this returns an error of permission denied. Does anyone know how to get a backup of the postgress DB from NextCloud?

How I backed up postgress…

  1. I turned on ssh logins, then remote ssh’d into truenas… (this just made my lifer much easier for this)
  2. Put NextCloud into maint mode by editing “Nextcloud AppData Storage”/config/config.php
"maintenance" => true,
  1. Made sure I had a share/dataset with write permissions on it then cd into that (/mnt/Pool1/backup)
  2. list your containers to make sure you get the name of your postgress one (mine was ix-nextcloud-postgres-1)
sudo docker ps
  1. Once you have the name lets go ahead and double check the name and owner of that DB
  2. Log into the the postgress DB container using the following command
sudo docker exec -it ix-nextcloud-postgres-1 psql -U nextcloud
  1. Now lets list the DB’s with the /l command
  2. you should get a list of DB’s that include a nextcloud one owned by nextcloud (those were the names of mine, will probably be the same for you)
  3. now we know the container name, the database name and the db owner name lets go ahead and exit the postgress container by using the /q command
  4. lets use that info to now construct our backup command
sudo docker exec {{ nextcloud_container } pg_dump -c -U {{ nextcloud_db_user }} {{ nextcloud_db_name }} > {{ nextcloud_database_dump_dir }}/nextcloud.sql
  1. My command looked like this
sudo docker exec ix-nextcloud-postgres-1 pg_dump -c -U nextcloud nextcloud > /mnt/Pool1/backup/nextcloud.sql
  1. Be sure to turn off main mode when you are done

Hope this helps someone later… My next plan is to backup the themes and users folder and see if I can perform a restore to a NextCloud AIO instance I will stand up just to see if I can do a full restore in case I completely lose or break truenas etc. If there is any interest in how I do that when I am succesful please let me know and I will create a new thread with instructions etc.