Migrate Nextcloud snap installation from one VPS to another

I have my personal Nextcloud server installed on a DigitalOcean Droplet. I use the official snap package from snapcraft.io/nextcloud (sources in https://github.com/nextcloud/nextcloud-snap/) by @kyrofa (thanks as always :grinning: :blue_heart:). I mean, the whole installation process was snap install nextcloud and a few other commands (configuring Let’s Encrypt and installing a TURN server (coturn) via apt).

For various reasons, I want to migrate my Nextcloud installation to a new VPS, I mean a completely new hosting provider. How can I achieve that as seamless as possible?

I haven’t been able to find a guide to migrate a server snap from one host to the other, neither for Nextcloud snap specifically, nor generally for any snap. Can anyone please help me or point me to a relevant documentation?

Honestly, the answer is “it depends.” I know, terrible answer.

It depends on how your data is stored. If you haven’t moved your data from the default location, you should try using the nextcloud.export and nextcloud.import commands. If you have, those commands will export your database and stuff, but you’ll need to migrate the Nextcloud data dir by hand. That doesn’t include SSL certs and whatnot, you’ll need to configure those again, but it should cover most things. Don’t get rid of your existing install until you’ve verified everything looks good, of course.

1 Like

Perfect. Thank you dear Kyle! I was not aware of the import and export commands. No, I haven’t changed anything related to data location. So I guess it should work as you say. I will try it and will report my experience here. Let’s see how it goes :grinning:

Please do. They’re not new commands, but they haven’t gotten a ton of mileage, so do please double check that everything looks okay, and please do let me know how it works!

1 Like

Sorry, i do not like Snap. Without Snap you easily could use the backup/restore-documentation from Nextcloud.

Hi again.

I tried it and still I have no success. First of all, there is the space problem. One of the reasons I am migrating to a new VPS is because I have run out of space in the current one. I cannot use nextcloud.export -abcd because my stored data is huge and I do not have enough space for another backup copy on the same machine. Therefore, I copied the data directory manually to the new server, and I only ran nextcloud.export -abc (without d). This worked.

However, after I copy the backup directory to the new VPS, and when I run nextcloud.import -abc, I get this error:

$ sudo nextcloud.import -abc backups/20200712-201609/
WARNING: This functionality is still experimental and under
development, use at your own risk. Note that the CLI interface is
unstable, so beware if using from within scripts.

Clearing existing non-default apps... done
Importing apps...
rsync: change_dir "/home/mabkenar//backups/20200712-201609/apps" failed: Permission denied (13)
              0 100%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/0)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]
Unable to import apps
Disabling maintenance mode... done

I have tried sudo chown -R mabkenar:mabkenar backups/ to make sure permissions are done right. But it still gives the same error message.

I appreciate any help.

No idea. Perhaps you can ask in an Snap-forum.

The importer doesn’t have permission to access your home directory (due to confinement). Try putting your backups in /media somewhere and make sure the removable-media interface is connected.

1 Like

Yes. It finally worked :grinning:

What I did on the old server:

sudo apt autoremove #free up a little space for the backup
sudo apt clean #free up a little more!
sudo nextcloud.export -abc #backup apps, databse, and configs, but not files (since there was no space left on the server for duplicating all the files)

What I did on the new server:

sudo snap install nextcloud
scp -pr <username>@<old_VPS_IP_address>:/var/snap/nextcloud/common/ /var/snap/nextcloud/common/ #copy files directly from the old server to the new one
sudo scp -pr <username>@<old_VPS_IP_address>:/var/snap/nextcloud/common/backups /media/ #copy the backup (apps, database, and config) to the new server as well
sudo chown -R root:root /media/backups/ #make sure files belong to root
sudo snap connect nextcloud:removable-media :removable-media #give nextcloud permission to read /media directory
sudo nextcloud.import -abc /media/backups/<backup-date>/ #import the backup

And after all that, of course on the new server:

sudo nextcloud.enable-https lets-encrypt

That helped me alot! Thanks for sharing!

1 Like