Changing Nextcloud's HDD
Hello, it's me, the incompetent one.
Actually, if you're hosting on the cloud, changing the data storage location due to disk corruption would probably only happen during an environment migration, but since I was storing NextCloud data on a failing HDD, I decided to specify a different HDD as the destination.
My usage of NextCloud is limited to a media player for local environments, or temporary and simple file sharing between different OSes, so there are no important files. It stores data from some machine in my house, for example, BIOS files for an EEPROM extraction machine that isn't always on, or notes I've made. Also, I just dump PDFs there that accumulate without me realizing it.
Actually, it would be enough to just change the mount point, so it might not even be necessary to do this, but since I'm specifying a different mount point for an already mounted HDD, I feel it might affect other shell scripts, so I'll create it separately for a cleaner feeling.
Frankly, even without changing the datadirectory path in NextCloud's config/config.php settings file, I could just create a symbolic link to the original specified location, but that feels a bit off, so I'll properly create a separate NextCloud data directory on a different HDD and specify it.
※This article is not about data migration, but rather about changing the disk.
Creating the Data Directory
We will create a NextCloud data directory on an already mounted HDD.
And it seems NextCloud complains if .ocdata isn't created, so I'll create it with touch. I forgot that even with the -R option, it doesn't recursively look at .files.
sudo mkdir /media/3t/ncdata
sudo touch /media/3t/ncdata/.ocdata
sudo chown www-data:www-data /media/3t/ncdata
sudo chown www-data:www-data /media/3t/ncdata/.ocdata
sudo chmod 750 /media/3t/ncdata
Editing config.php
And if the datadirectory no longer exists, it won't even enter maintenance mode, so I'll first edit the config/php file to change the settings, and then proceed with a state that includes operational verification.
cd /your/nextcloud/dir
sudo vim config/config.php
Then, specify the following setting to the directory created earlier.
'datadirectory' => '/media/3t/ncdata',
Now, if it doesn't complain after turning maintenance mode on, I'll turn it off again.
cd /your/nextcloud/dir
$ sudo -u www-data php ./occ maintenance:mode --on
Maintenance mode enabled
$ sudo -u www-data php ./occ maintenance:mode --off
Maintenance mode disabled
OK.
Running File Scan Again
Perhaps because I have plugins installed, if there's a directory specified by a plugin that no longer exists, NextCloud complained after I logged in, preventing me from seeing the content.
I'll enter maintenance mode again, perform a file scan, and re-acquire the file index.
cd /your/nextcloud/dir
$ sudo -u www-data php ./occ maintenance:mode --on
Maintenance mode enabled
$ sudo -u www-data php ./occ files:scan --all
Starting scan for user 1 out of 2 (Fox)
Path not found: User folder /media/3t/ncdata/Fox/ exists in cache but not on disk
Starting scan for user 2 out of 2 (nextcloud)
Path not found: User folder /media/3t/ncdata/nextcloud/files exists in cache but not on disk
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 0 | 0 | 0 | 0 | 0 | 2 | 00:00:00 |
+---------+-------+-----+---------+---------+--------+--------------+
$ sudo -u www-data php ./occ maintenance:mode --off
Maintenance mode disabled
Oh... it's complaining about something...
So, I'll create the directories it's complaining are missing.
sudo mkdir /media/3t/ncdata/Fox/files
sudo mkdir /media/3t/ncdata/nextcloud/files
sudo chown -R www-data:www-data /media/3t/ncdata
sudo chmod -R 750 /media/3t/ncdata
This completes it.
Scan again
cd /your/nextcloud/dir
sudo -u www-data php ./occ files:scan --all
If this passes, it's successfully completed.
Now that this has been confirmed, I'll strip down the permissions for NextCloud's data files, specifically for the files only.
cd /media/3t
sudo find ./ncdata -type f -exec chmod 640 {} \;
Last time, I connected my Android device using my WireGuard VPN, so now I can access NextCloud while connected to the VPN.
Until now, I was using a free DNS I casually borrowed from MyDNS via an Nginx reverse proxy, and there was a phenomenon where the seek bar wouldn't function during media playback only in environments using the reverse proxy, but that has also been resolved.
From a security perspective, I'm also thinking it might be okay to no longer allow access via the domain I'm using with MyDNS.
By the way, the reason I don't set up RAID is that I often see stories of people experiencing hell when a RAID controller breaks, and I want to avoid that hassle. If I were to do it, it would be ZFS, but I'd only consider it if my desired data storage area started exceeding 5TB.
Personally, I'd like to keep an eye out for SSDs that are likely to be mass-released from data centers and acquire them when they become available.
So that's all for now. See you next time.