How to migrate Nextcloud & OpenProject to new server?

Hey, thanks for answering and sorry for the late reply…

I had been looking at the guides for doing it previously and gave up because I got confused about some things… But somehow my brain must have been working better yesterday, because I spent the evening and a bit of the night on it (mostly on watching the loading screen of the VMs installing… :slight_smile: ) and it worked like a charm…

So because of my previous confusion and in an attempt to take notes for future me and future they, I will here document the process for both NextCloud and OpenProject …

OpenProject Procedure

The backup process of OpenProject in UCS is pretty well documented here:

Except for the fact that it (actually just like OpenProjects own documentation, Backing up your OpenProject installation) recommends making the db dump like this:

PGPASSWORD="$(cat /etc/postgres-openproject.secret)"  pg_dump -U openproject -h localhost -d openproject -c -x -O > /var/backup/openproject.sql

Which makes it dump the db as a raw text dump, which the command pg_restore (as referenced here: Restoring an OpenProject backup) can’t work with…

I just inserted an F flag in front of the c flag but upon reinspecting the man page today it seems that it should have been a flag on it’s own to keep the --clean option, like this:

PGPASSWORD="$(cat /etc/postgres-openproject.secret)"  pg_dump -U openproject -h localhost -d openproject -Fc -c -x -O > openproject.sqldump

The restore is quite trivial from here:

docker stop $(ucr get appcenter/apps/openproject/container) && \
tar -xf /path/to/openproject_files.tar -C /var/lib/univention-appcenter/apps/openproject/ && \
PGPASSWORD="$(cat /etc/postgres-openproject.secret)" pg_restore -U openproject -h localhost -d openproject --clean --if-exists openproject.sqldump && \
docker start $(ucr get appcenter/apps/openproject/container) 

All from root account, ofc…

NextCloud procedure:
The NextCloud procedure was a bit more involved, but also pretty straight forward after reading and understanding several blog/manual pages…

First the backup procedure as described here:
Backup — Nextcloud latest Administration Manual latest documentation

The occ command in the NextCloud container can be accessed, as per this blog post How To Edit config.php in Nextcloud App

So first we turn on maintenance mode

univention-app shell nextcloud sudo -u www-data php /var/www/html/occ maintenance:mode --on

Then we do the same file backup procedure as for OpenProject:

tar -cvf nextcloud_files.tar /var/lib/univention-appcenter/apps/nextcloud/

Then we dump the db via this (as described here Backup — Nextcloud latest Administration Manual latest documentation):

PGPASSWORD="dbpassword" pg_dump nextcloud -h localhost -U nextcloud -f nextcloud-sqlbkp_`date +"%Y%m%d"`.bak

and we can choose to take the instance out of maintenance mode again if we so wish/need

univention-app shell nextcloud sudo -u www-data php /var/www/html/occ maintenance:mode --off

Then on to the restore…

First thing we must before maintenance mode is to take a copy of the current LDAP config for later reference

univention-app shell nextcloud sudo -u www-data php /var/www/html/occ ldap:show-config --show-password > nextcloud.ldap

Maintenance mode then restore files via tar and then on to the db:

First we must delete the whole DB as described here Restoring backup — Nextcloud latest Administration Manual latest documentation

PGPASSWORD="$(cat /etc/postgresql-nextcloud.secret)" psql -h localhost -U nextcloud -d template1 -c "DROP DATABASE \"nextcloud\";"

Then to be able to create the new db we must first give the psql user nextcloud permission to do so…

So first we need to enter the psql prompt as the postgres user:

su - postgres -c psql

Then from the postgres prompt:

alter user nextcloud createdb;

Then we can exit the psql prompt and make the new db

PGPASSWORD="$(cat /etc/postgresql-nextcloud.secret)" psql -h localhost -U nextcloud -d template1 -c "CREATE DATABASE \"nextcloud\";"

and to be nice to our circadian rhythm we shall revoke the the previously given psql role from the nextcloud user via

su - postgres -c psql

Then from the postgres prompt:

alter user nextcloud nocreatedb;

and then again exit…

restore the db

PGPASSWORD="$(cat /etc/postgresql-nextcloud.secret)" psql -h localhost -U nextcloud -d nextcloud -f nextcloud-sqlbkp.bak

Watch some text fly by and take her out of maintenance mode once again and i had to also run this:

univention-app shell nextcloud sudo -u www-data php /var/www/html/occ upgrade

Then we have to fix the ldap update the ldap settings with the values from the nextcloud.ldap file… So first

cat nextcloud.ldap

Then we have somewhere to copy paste from … (please feel free to cantact me on how to do this with some “fancy” awk “magic”)

univention-app shell nextcloud sudo -u www-data php /var/www/html/occ ldap:set-config s01 ldapAgentName pasteYourAgentName
univention-app shell nextcloud sudo -u www-data php /var/www/html/occ ldap:set-config s01 ldapAgentPassword pasteYourAgentPassword
univention-app shell nextcloud sudo -u www-data php /var/www/html/occ ldap:set-config s01 ldapHost pasteYourHost
univention-app shell nextcloud sudo -u www-data php /var/www/html/occ ldap:test-config s01

gl hf <3

4 Likes