Migrating NCP from pi to NCP docker

Hi all,

I have a raspberry pi with the NCP image for myself and 6 other users, all data is stored on a external usb disk (BTRFS) /media/drive/ncdata. Now I would like to migrate to nextcloudpi docker on a new server with ubuntu server and docker. I think I got it work, see below the steps I have executed so far.

First try:

  1. I ran nc-export with all data
  2. started the docker container (with volume /media/ncdata, EXT4)
  3. I ran nc-restore on the docker but got an error about BTRFS
  4. I ran nc-export without all data
  5. I added a new partition with filesystem BTRFS and mounted the partition on /media/ncdata
  6. I ran nc-restore and got errors about missing data directories
  7. Tried all kinds of different things like changing datadirectory in config.php file but it did not work

Second try:

  1. preserve database and nextcloud folder on pi:
    rsync -Aavx /var/www/nextcloud/ /media/drive/backup/nextcloud-dirbkp/
    mysqldump --single-transaction -u ncadmin nextcloud > nextcloud-sqlbkp_date +"%Y%m%d".bak

  2. transfer files from pit to new server
    sudo /usr/bin/rsync -aAx -e --delete “/media/drive/backup/” “user@IP:location/”

  3. transfer data from myself to new server

  4. file permissions changed during transfer so I executed a chown www-data:www-data *

  5. on server maintenance mode on:
    docker exec -it nextcloudpi sudo -u www-data php /data/nextcloud/occ maintenance:mode --on

  6. drop and create database
    docker exec -it nextcloudpi sudo mysql -u ncadmin -e “DROP DATABASE nextcloud”
    docker exec -it nextcloudpi sudo mysql -u ncadmin -e “CREATE DATABASE nextcloud”

  7. import database (argument -t gave some TTY error)
    sudo docker exec -i nextcloudpi sudo mysql -u ncadmin nextcloud < nextcloud-sqlbkp_20200417.bak

  8. moved nextcloud folder in place
    rsync -Aax nextcloud-dirbkp/ /media/ncdata/nextcloud/

  9. in config file I change datadirectory and trusted domains

  10. I moved all data into the new datadirectory

  11. restart apache
    docker exec -it nextcloudpi service apache2 reload

  12. turn maintenance mode off
    docker exec -it nextcloudpi sudo -u www-data php /data/nextcloud/occ maintenance:mode –off

Now I received an error:

An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user ‘ncadmin’@‘localhost’ (using password: YES) in /data/nextcloud/lib/private/DB/Connection.php:68

  1. Stop and start the container and try again
    Another error

An unhandled exception has been thrown:

RuntimeException: Could not get appdata folder in /data/nextcloud/lib/private/Files/AppData/AppData.php:95

  1. Another restart of apache
    docker exec -it nextcloudpi service apache2 reload

  2. And finally I was able to turn the maintenance mode off
    docker exec -it nextcloudpi sudo -u www-data php /data/nextcloud/occ maintenance:mode –off

  3. still to do: migrate all data to new server

My questions:

  • Did I miss something somewhere?
  • Do I still need the BTRFS filesystem with the second method?
  • Why did the first attempt fail? Is it even possible what I was trying to do?
  • What should be the steps after step 10 in the second attempt, I have no idea why I got these errors.
  • and what would be the best backup strategy from now on?

Thanks in advance!

1 Like