Nextcloud snap: how to use nextcloud.export when data is on external drive?

The wording here (How to backup your instance · nextcloud-snap/nextcloud-snap Wiki · GitHub) is a little ambiguous:

Q. Can exporting specify the data directory?
A. Not directly, but you should be able to use a symlink. For example, creating a symlink from the data directory to /var/snap/nextcloud/common/nextcloud/data

I am running Nextcloud snap with all my data on an external drive. In the event of a crash, could I rebuild my server with files and directories created by using:

nextcloud.export
and making a backup of my entire data drive?

On reading the tips & tricks instructions, I feel like it should be possible to include the external data drive in the backup file by creating a symlink between the external data directory and /var/snap/nextcloud/common/nextcloud/data, but then the backup file would become too large for the server PC. The reason I have my data on an external drive is because there isn’t all that much space on the PC that’s running Nextcloud snap.

Hi [carlier74] as your data folder is on an external storage you need to back up your settings so if you happen to have an error in your snap installation you can easily restore the settings and the files remain unchanged on your external storage

In my scenario I follow the following script

  1. ->> Remove the Default Backups Directory.

rm -rf /var/snap/nextcloud/common/backups

2 ->> I create a folder called Backups on the external drive where the nextcloud data folder is.

mkdir /mnt/Nextcloud/Backups

  1. ->> I create a symbolic link pointing to the folder that was created in the previous step.

ln -s /mnt/Nextcloud/Backups /var/snap/nextcloud/common/backups

  1. ->> I export the Settings

nextcloud.export -abc

5 Backup the drive with Borg or rsync

Restoration

  1. ->> install snap

sudo snap install nextcloud

  1. ->> Remove the default backups directory

rm -rf /var/snap/nextcloud/common/backups

  1. ->> Symbolic link to the backups folder on the external storage

ln -s /mnt/Nextcloud/Backups /var/snap/nextcloud/common/backups

  1. ->> Restore Settings

nextcloud.import -abc /var/snap/nextcloud/common/backups/20221002-1200

  1. ->> Activate the option for snap to recognize external storage media.

sudo snap connect nextcloud:removable-media

Ready!! Your nextcloud instance will already be restored

2 Likes

If you are interested, there are these two scripts that I use to backup my nexcloud snap instance

Borg

Rsync + Tar

1 Like

Thanks for this detailed and clear explanation! I’ve just gone through the first five steps. I’m copying your instructions for future use.

Also thanks for the scripts. I need to learn about scripts, though I get the basic idea. I currently just have a few notes for manually syncing the data folder with rsync. (I also clone the whole PC everyone couple of months so there’s always that as a plan B).

It would be good to have this information in the Nextcloud snap wiki.

I guess there is no way to test the Restoration part to see if it works without wiping my current setup. I wonder what would happen if I installed Nextcloud on a different computer and tried to restore a copy of the server.

One question: how will I be able to see the file name of the latest backup?

Oh, I guess this works:
sudo ls -l /mnt/Nextcloud/Backups

I’m glad it worked for you the command you mentioned is correct.

As for scripts, just follow the instructions that are described and you will get it in the past, I used to do the same as you, but after a failure in restoring the disk image, I started to back up another method.

1 Like

I want to suggest having this info added to the wiki on github. Can I just ask this:

Why do you first remove the default backups directory, and then recreate it with the symlink? Why not just create a symlink between the external backup drive directory and the existing default backup folder? Thanks!

I do this procedure because it is not possible to create the symbolic link without deleting the default directory it gives an error that the destination already exists such a directory

Ok, thanks.