Nextcloud Pi, wanting to add second HDD for backup

Hi All

I have what I think must be quite a common issue. I setup my Nextcloud instance using Nextcloud Pi OS image for the raspberry Pi back in 2019. It has been running mostly without hiccup since, but only on a single USB drive. Which is a glaring red siren flashing beacon of an issue when it comes to backup strategy and I now need to do something about it. (I previously posed about the in 2021 and then life gets in the way so I really, really need to sort it now)

Im currently up to date on Nextcouldpi version V1.51.0 running nextcloud 23.0.6.1 (I think my version of PHP is stopping me going further but that’s for another day).

I have a second USB drive to use as a backup and followed this guide (How to periodically backup to a second USB drive with NextCloudPi) to format it by taking the old drive out and putting the new one in to get next cloud to format it properly for me. I gave it the mybackup label using nc-format-usb tool so that the new drive is /media/mybackup.

However as when I originally setup everything I don’t believe I added a label to the original drive and just relied on Automount. So this is what is seen for my existing drive.

NCP System info lists my datadir as /media/USBdrive/ncdata
NC settings page shows it as /media/myCloudDrive

When I plug in my new drive that I want to use as a backup it all gets confused as ncp seems to forget my original drive and it can’t find my datadir. When I unplug the backup drive and restart with only my original drive, all is back and working, so I think it is a label issue with my original drive.

Previously I have been pointed to using UUID and fstab but that seems more like for moving the datadir to a new disk.

I have also seen mention of manually editing the config.php file to add the label of the datadir so it is set on the right drive which would be /media/myCloudDrive (I think from what is shown in NC settings) and not relying on automount and there only being 1 drive in the system. But I don’t know how to go about it.

However, I will freely admit (much to my annoyance) I am not greatly linux literate, but I can follow instructions and learn from them. However, whilst I have read posts on this forum and generally, online there are bits of information that are relevant to what I need to do, but not a guide or complete post that does it all and the last thing I want to do is in attempting to secure my data with a backup strategy, screw it up as Im getting a command wrong.

I was wondering if it is as simple as using nc-datadir in the NCP panel and just putting /media/myCloudDrive in there rather than /media/USBdrive/ncdata? but I don’t want to move the directory just set it where it is on that drive.

So I humbly ask for the collective help and guidance this forum has on tap, with an idiots guide…
Please. Thanks in advance.

I hope that it is as simple as editing the config.php in a terminal (I can plug in keyboard etc and work directly on the Pi rather than SSH) but its how I go about it on a Pi install based on the SD image rather than snappy or docker etc.

Equally, if there is already an exact guide for this, link it and call me an even bigger idiot but I couldn’t find what I needed, maybe I’m not asking the right question though.

Cheers.

1 Like

Fstab is used for mounting disks. Try using it to mount the disk to your preferred location. Sounds like you never followed through on it.

Search the forum or internet for many examples and guides.

Hi Just,

I had looked at the instructions given at Mounting an external drive using UUID and fstab | Linux admin junior

But that talks about making a data dir for nextcloud and using UUID rather than a label, which is where I got confused. Fell at the first hurdle as it were. I already have the datadir on the disk. I just need to set the label of the drive I believe so that it is fixed, rather than simply relying on it being the only HDD there. So when I plug the other drive in and it auto mounts, nextcloud doesn’t look at that expecting to find the datadir there.

The guide here How to periodically backup to a second USB drive with NextCloudPi

Taht Says to:
Important: make sure you use the drive label in nc-datadir and other configuration options. Use names such as /media/myCloudDrive, instead of /media/USBdrive, or otherwise the system will not be able to guess which drive holds the data and which one holds the backups.

But it doesn’t say what to do with the original drive. I don’t know how to set the label for the original one to be I assume /media/myCloudDrive/ncdata rather than /media/USBdrive/ncdata. Do I just input it in the ncp panel under nc-datadir? Or would that make it think I was moving the data dir and fail as its already there. That what lead me to another article I cant find right now which raised editing the config.php to just put the actual datadir location in there rather than /media/USBdrive/ncdata.
But I guess I’m not really sure where to start.
I will have another trawl through the forum.

Use fstab to mount your disk to /wherever/you/want

Has nothing to do with the data directory so ignore that and use fstab to mount a disk to a location. Once you understand the process and can access your disk from a location it’ll make more sense.

I will do my research into fstab so I understand it more… And image the SD card before I mess with anything. Changing the mount point won’t erase any data? I assume once I have done the fstab magic to set a label will I have to tell next cloud where the datadir etc is or will the datadir essentially be in the same place it’s just the mount point I’m setting.

Stop messing with Nextcloud; don’t get ahead of yourself.
Only focus on fstab to mount a disk.
Try with a thumb drive on a different computer or laptop. It should take you editing the fstab file to achieve.

Let us know once you’ve done that.

df -h
Will tell you about your disk

Once mounted you can check your chown permissions. Will need to adjust ownership to www-data for nc to access the location.

Lol ok. I have another pi so I’ll grab that and try with the backup disc and see how I get on.

1 Like

Hi Just,

Sorry for the long delay, work and family commitments leave little time for tinkering.

I have just had a go after watching / reading about the fstab file.

I fired up another pi and plugged in the USB HDD that I formatted with my nextcloudpi.

I used the df-Th command to list drives and formats and found it as sda1 in btrfs format.

I used ls -lh /dev/disk/by-uuid/ to find the UUID for the disk. Got that and then.

I used Sudo nano /etc/fstab to edit the mount point.

I put in UUID=myuuidlongcode /media/mybackup btrfs rw,users, 0 0

Saved the fstab file and ran df -Th again and could see the sda1 disc was mounted where I wanted it.

I had a permission error when I tried to write to it but that’s as expected and I didn’t want to change the permissions on it as this was just a test.

Hopefully that is the theory part done and I would be able to repeat it on my nextcloudpi install.

Previously I want getting the mount point thing (coming from windows) I had my disk partitioned and formatted with the name I wanted why isn’t it working? But I hadn’t grasped that unless I then tell the raspberry pi “hey this disk, please always mount it in this place” it wouldn’t. So when I insert a new USB HDD with automount on then the nextcloudpi just sees two USB HDD’s and doesn’t know where anything is.

So onto the real deal. I assume I should edit the fstab for both USB HDD’s, the existing one with the datadir etc on it and the new one I want to use as a backup. I will do the existing one before plugging the backup in.

Looking at my settings:
NCP System info lists my datadir as /media/USBdrive/ncdata - this is the place it is automatically put.
NC settings page shows it as /media/myCloudDrive - this is the place I want to set the mount point in fstab so that it carries on business as usual.

So assuming I have my head (somewhat) around this now. Once I have done the fstab magic on the original USB HDD with the datadir etc on it I follow Olivers guidance in post Change path of datadir + dbdir from "USBdrive" to drive label - #2 by eehmke and edit the config file so that anything pointing at the old automount location /media/USBdrive/ncdata etc looks at the new set mount point of /media/myCloudDrive/ncdata etc.

Then I can plug in the new external USB HDD that I’m using as a backupdrive and edit fstab to mount it at /media/mybackup.

I will need to give user permissions for nextcloud sudo chown www-data:www-data /media/mybackup.

I can then use the nextcloudpi webUI or the commandline UI to set the backup tasks to look at the /media/mybackup folder.

I hope this is somewhat correct…

1 Like

Not had a chance to try this yet, probably won’t until the weekend now, but just wanted to check the process for editing the config file as I have had a search but am cobbling stuff from various sources? Is it located in var/www/nextcloud/config so I should cd into it from the terminal and the run sudo nano config.php I should then look for any reference to media/USB/… And change them to media/MyCloudDrive which will be the mount point I set in fstab. Ctrl+X out, Y to save and done? Give it a reboot and hey presto?