Moving Nextcloud Data to external USB drive

Hello all - I am a newie with Nextcloud on a Banana Pi SBC with Ubuntu 20.04 - I’ve installed Nextcloud using Snap. Now to the problem …

I was wanting to migrate the Nextcloud data from the internal drive on the the Banana Pi to an external 8 TB USB storage drive. The drive currently has one NTFS partition, and I was looking for some admin tools (Nextcloud?) that I could utilize to relocate the Netcloud data.

Been looking at the docs as well as the Snap - no joy.

Can someone direct me to the documentation and tools for doing this?

Thanks in advance for any guidance or help.

Larry

Hello,

I am no expert but from my personal experience, I see Linux doesn’t play well with NTFS with advance apps due to permission errors. Better to use ext4.

How to Change Snap NextCloud user Data Directory?

Step 1 →

Connect the Disk and ensure it is detected and readable by Ubuntu by running command, sudo lsblk. This command should show an output with sdb or sdc (depending on number of drive installed) with your drive total capacity.

Step 2 →

Formatting the drive and mounting it under /media or /mnt (warning → Formatting the drive will erase all present data)

sudo mkdir /media/datadisk

sudo mkfs.ext4 -j -L DataDisk /dev/sdb

then

sudo blkid /dev/sdb → It will generate the disk UUID. Copy it and keep it for the next step.

sudo nano /etc/fstab → It will open up a configuration file under text edititor, don’t change anything just add below line at the end of the file → /dev/disk/by-uuid/4006fe68-879a-41ed-b4da-cc0e6bc6b4bb /media/datadisk auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-name=NewHDD 0 0 (replace the UUID of this command with your own) Now save and exit the file (CTRL+X → SHIFT+Y → ENTER)

sudo mount -a

Step 3 →

Changeing the nextcloud to the new location

sudo snap connect nextcloud:removable-media → This is to allow snap nextcloud access out of the confinement to external file system.

sudo snap stop nextcloud

sudo mv /var/snap/nextcloud/common/nextcloud/data /media/datadisk/ncdata

sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php → Find the line with entry for DataDirectory and change the location to /media/datadisk/ncdata. Save and exit

sudo chown -R root:root /media/datadisk/ncdata & then sudo chmod 0770 /media/datadisk/ncdata

sudo snap start nextcloud

Last Step →

You may now need to reboot the server.

Your installation will now save all user data out to that external or second disk.

Thanks.

1 Like

NaXal - thank-you so much for your guidance - your directions were perfect!

Larry

1 Like

NaXal,
That is an excellent write up. However, I did not install the SNAP version of NextCloud. Instead I installed each NextCloud component individually in what I call the manual installation approach. Additionally, I am trying to move my NextCloud Data folder located on my boot drive over to a secondary internal drive I have setup only for the storage of my personal data. In other words, I do not want to store any of my personal data onto my boot drive which is running Ubuntu Server 22.04.

Have you by chance seen any online documentation that nicely shows in a sequential manner like you do the steps involved in moving a Nextcloud data folder? I need to move my Nextcloud Data folder from the boot drive path shown below:

/var/www/nextcloud/data

Over to the new path shown below which is setup on my new secondary 8TB drive:

/mnt/8TBdata/nextcloud_data

I am having a hard time finding detailed documentation for this task I need to perform. Everything seems to be written for the SNAP version of Nextcloud and for adding new hard drives. But none for moving a Nextcloud data folder from the boot drive over to a secondary data storage drive. If you can provide a link to such documentation it will be much appreciated. Thank you for your time.

2 Likes

@slipstream Have you tried editing the line 'datadirectory' => '/var/www/nextcloud/data' in your configuration file (/var/www/nextcloud/config/config.php I assume)?
Remember to shutdown apache server and disable cron (if you have) before starting your migration. Also you need to move everything to the new folder, set up fstab to mount the new filesystem on system boot, and make sure your new data directory has the correct permission (refer to the old /var/www/nextcloud/data one)

Hello,

Apologies but my knowledge is very limited. I, myself use snap so things that I wrote are the stuff I had to learn and implement for my setup.

Correct me if I am wrong, but in case of your setup, you are not actually moving nextcloud storage, rather you are moving the location of public (web root) folder of Apache or nginx or whatever web server you are using.

Nextcloud stays or gets installed in that location.

Here is an example, → How To Move an Apache Web Root to a New Location on Ubuntu 20.04 | DigitalOcean

This will not move your database though, only nextcloud core files and user data !!

Thanks.

Ubuntu version: 22.04.3

Apache version: 2.4

Nextcloud installation: Manual

Subject: How to safely migrate Nextcloud data from internal hard drive to external hard drive

I am new to Nextcloud and I was confronted with the same issue. This is the solution that worked for me. Cheers!

If you’ve already formatted your external hard drive to a Linux accepted file system proceed to step 9. If not, execute steps 1-8.

  1. Insert your external hard drive into your server.

  2. Open “Disks” from your list of softwares. Select the external hard drive that you wish to format. It is recommended to format it to the -ext4 file system.

  3. Click the “wheel icon” on the hard drive and then on “Format Partition”.

  4. In the “Label” field, type in Cloud1. Note that I will use Cloud1 throughout the remainder of these instructions.

  5. Select -ext4 as the file system.

  6. Erase data? If the external hard drive doesn’t have any data on it, then there is no need to select it. Note that if you select it, it will take a significant amount of time to format the drive.

  7. Encrypt hard drive with LUKS? Your choice.

  8. Now that the formatting is done, open your terminal and type in the following -

Command: blkid

  1. Copy the UUID number associated with the external hard drive “Cloud1” and paste it into a document so that you can refer to it later.

Example: 3e3334ii-jkl5-4cea-8fa6-fdcefce8b08101

  1. Stop the apache2 server.

Command: systemctl stop apache2

  1. Transfer to root user and enter root user account password when prompted.

Command: sudo -i

  1. Create a new data directory for your Nextcloud data.

Command: mkdir /mnt/cloud1

Note that I decided to mount my external hard drive to the /mnt/cloud1/ directory and not the /media/ directory. If I plan to add additional hard drives to my cloud storage, it can be seamlessly achieved. It is also visually appealing)

  1. Copy all files stored in your existing Nextcloud data directory to your new directory. Use the ‘cp -av’ command. This command ensures all permissions are retained during the “copy and paste”. It also displays transfer information.

Command: cp -av /mnt/harddrive/data/ /mnt/cloud1/

Note: “/mnt/harddrive/data” was the name of my existing Nextcloud data directory.

  1. Modify your /etc/fstab file to mount your external hard drive to the newly established Nextcloud data directory during system boot. In my case it is /mnt/cloud1.

Command #1: nano /etc/fstab

Command #2: Insert the 2 lines from below to the bottom of the fstab file

Hash tag/pound sign (to comment out what’s to the right of the parentheses) Additional cloud storage drives are listed here

UUID=63e3334ii-jkl5-4cea-8fa6-fdcefce8b08101 /mnt/cloud1 ext4 defaults 0 0

Command #3: Press Control + X, then Y, then Enter (it saves the files and exits you out of it)

  1. Now you will have to mount the drive again.

Command: mount -a

  1. Update your nextcloud config.php file to reflect the new mount point

Command: nano /var/www/nextcloud/config.config.php

Find the data directory entry and substitute the existing data directory with /mnt/cloud1/data

  1. systemctl start apache2 and verify that your cloud instance is operational.

  2. reboot your system.

  3. Voila!