[NextcloudPi]Power outage broke Nextcloud configuration. Cannot set data folder

I had a power outage and it messed up my server/external hdd.
Had to run fsck and it seems to have “fixed” it.
However, my nextcloud configuration got messed up.
My datadir is pointing to a folder on my server (not my external HDD) and I cannot select a new one.
I tried to change my datadir using ncp-config, but it tells me it doesn’t have the necessary permissions:

Running nc-datadir
ERROR: the user www-data does not have access permissions over /media/root/<my hdd UUID>/ncdata

However, when I check the permissions:

sudo ls -la /media/root/<my hdd UUID>
total 20
drwxr-xr-x  1 www-data www-data   90 May 28  2020 .
drwxr-x---+ 3 root     root     4096 Nov 25 17:16 ..
drwxr-xr-x  1 www-data www-data  426 Nov  6 16:37 ncdata

It clearly DOES have access permissions.

Am I missing something?

Check/share ourput of

sudo ncp-report

Do you have a backup? if so use ncp-config>backups>nc-restore to restore previous config.
or can manually edit datadir path in config.php
and check permissions inside ncdata and/or run ncp-config>tools>nc-fix-permisions.

Hi!
First of all, thanks for replying! Any kind of help is welcome.

I’ll go over everything you said:

  1. share output of ncp-report (I removed everything I considered was sensitive, in addition to what the tool already hides):
NextCloudPi diagnostics

NextCloudPi version  v1.44.4
OS                   Debian GNU/Linux 10. 4.19.0-18-amd64 (x86_64)
automount            yes
USB devices          sda 
datadir              /media/55913678-bb92-45e3-b176-6fbaae768158/ncdata
data in SD           yes
data filesystem      ext2/ext3
data disk usage      249G/454G
rootfs usage         249G/454G
swapfile             /var/swap
dbdir                /var/lib/mysql
Nextcloud check      ok
Nextcloud version    21.0.4.1
HTTPD service        up
PHP service          up
MariaDB service      up
Redis service        up
HPB service          up
Postfix service      down
internet check       ok
port check 80        closed
port check 443       open
IP                   ***REMOVED SENSITIVE VALUE***
gateway              ***REMOVED SENSITIVE VALUE***
interface            enp3s0f0
certificates         ***REMOVED SENSITIVE VALUE***
NAT loopback         no
uptime               1min

Nextcloud configuration

{
    "system": {
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": {
            "0": "192.168.100.14",
            "1": "192.168.100.14",
            "11": "***REMOVED SENSITIVE VALUE***",
            "20": "***REMOVED SENSITIVE VALUE***",
            "12": "***REMOVED SENSITIVE VALUE***",
            "14": "***REMOVED SENSITIVE VALUE***",
            "": "***REMOVED SENSITIVE VALUE***"
        },
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "21.0.4.1",
        "overwrite.cli.url": "https:\/\/***REMOVED SENSITIVE VALUE***\/",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "memcache.local": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "timeout": 0,
            "password": "***REMOVED SENSITIVE VALUE***"
        },
        "tempdirectory": "\/var\/www\/tmp",
        "mail_smtpmode": "sendmail",
        "mail_smtpauthtype": "LOGIN",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "preview_max_x": "2048",
        "preview_max_y": "2048",
        "jpeg_quality": "60",
        "overwriteprotocol": "https",
        "htaccess.RewriteBase": "\/",
        "maintenance": false,
        "logfile": "\/media\/55913678-bb92-45e3-b176-6fbaae768158\/ncdata\/nextcloud.log",
        "data-fingerprint": "***REMOVED SENSITIVE VALUE***",
        "theme": "",
        "loglevel": 2,
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***"
    }
}

HTTPd logs

[Fri Nov 26 00:00:03.766156 2021] [ssl:warn] [pid 1050] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Fri Nov 26 00:00:03.766296 2021] [ssl:error] [pid 1050] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=***REMOVED SENSITIVE VALUE*** / issuer: CN=***REMOVED SENSITIVE VALUE*** / serial: ***REMOVED SENSITIVE VALUE*** / notbefore: Apr 20 18:58:39 2020 GMT / notafter: Apr 18 18:58:39 2030 GMT]
[Fri Nov 26 00:00:03.766306 2021] [ssl:error] [pid 1050] AH02604: Unable to configure certificate localhost:4443:0 for stapling
[Fri Nov 26 00:00:03.766355 2021] [http2:warn] [pid 1050] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Fri Nov 26 00:00:03.786718 2021] [mpm_prefork:notice] [pid 1050] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1j configured -- resuming normal operations
[Fri Nov 26 00:00:03.786735 2021] [core:notice] [pid 1050] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 26 11:22:27.753795 2021] [ssl:warn] [pid 841] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Fri Nov 26 11:22:27.941270 2021] [ssl:error] [pid 841] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=***REMOVED SENSITIVE VALUE*** / issuer: CN=***REMOVED SENSITIVE VALUE*** / serial: ***REMOVED SENSITIVE VALUE*** / notbefore: Apr 20 18:58:39 2020 GMT / notafter: Apr 18 18:58:39 2030 GMT]
[Fri Nov 26 11:22:27.941298 2021] [ssl:error] [pid 841] AH02604: Unable to configure certificate localhost:4443:0 for stapling
[Fri Nov 26 11:22:28.563829 2021] [ssl:warn] [pid 1059] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Fri Nov 26 11:22:28.563907 2021] [ssl:error] [pid 1059] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=***REMOVED SENSITIVE VALUE*** / issuer: CN=***REMOVED SENSITIVE VALUE*** / serial: ***REMOVED SENSITIVE VALUE*** / notbefore: Apr 20 18:58:39 2020 GMT / notafter: Apr 18 18:58:39 2030 GMT]
[Fri Nov 26 11:22:28.563913 2021] [ssl:error] [pid 1059] AH02604: Unable to configure certificate localhost:4443:0 for stapling
[Fri Nov 26 11:22:28.563947 2021] [http2:warn] [pid 1059] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Fri Nov 26 11:22:31.291196 2021] [mpm_prefork:notice] [pid 1059] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1j configured -- resuming normal operations
[Fri Nov 26 11:22:31.291266 2021] [core:notice] [pid 1059] AH00094: Command line: '/usr/sbin/apache2'

Database logs

2021-11-26 11:22:35 0 [Note] InnoDB: Uses event mutexes
2021-11-26 11:22:35 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-11-26 11:22:35 0 [Note] InnoDB: Number of pools: 1
2021-11-26 11:22:35 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-11-26 11:22:35 0 [Note] InnoDB: Initializing buffer pool, total size = 1G, instances = 1, chunk size = 128M
2021-11-26 11:22:35 0 [Note] InnoDB: Completed initialization of buffer pool
2021-11-26 11:22:35 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-11-26 11:22:35 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2021-11-26 11:22:35 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-11-26 11:22:35 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-11-26 11:22:35 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-11-26 11:22:35 0 [Note] InnoDB: 10.3.31 started; log sequence number 11595106116; transaction id 37912304
2021-11-26 11:22:35 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-11-26 11:22:35 0 [Note] InnoDB: Buffer pool(s) load completed at 211126 11:22:35 (/var/lib/mysql/ib_buffer_pool was empty)
2021-11-26 11:22:35 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-11-26 11:22:36 0 [Note] Server socket created on IP: '127.0.0.1'.
2021-11-26 11:22:36 0 [Note] Reading of all Master_info entries succeeded
2021-11-26 11:22:36 0 [Note] Added new Master_info '' to hash table
2021-11-26 11:22:36 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.3.31-MariaDB-0+deb10u1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Debian 10

  1. manually edit datadir path in config.php
    and check permissions inside ncdata and/or run ncp-config>tools>nc-fix-permisions.

I changed it manually from config.php and tried running nc-fix-permissions and I get this:

Running nc-fix-permissions
data directory not found
Done. Press any key...

I changed it back to what it was before (the datadir that’s on my machine, not on my external hdd) and tried running nc-fix-permissions again, just to see if anything is different:

Running nc-fix-permissions
fixing permissions in /media/55913678-bb92-45e3-b176-6fbaae768158/ncdata... chown: cannot access '/media/55913678-bb92-45e3-b176-6fbaae768158/ncdata/*/files': No such file or directory
chmod: cannot access '/media/55913678-bb92-45e3-b176-6fbaae768158/ncdata/*/files': No such file or directory
done
Done. Press any key...

Something is fishy…

  1. Do you have a backup? if so use ncp-config>backups>nc-restore to restore previous config.
    I do have a backup, thankfully. That’s actually my last hope :sweat_smile:

I tried running nc-restore and I get this:

Running nc-restore
check free space...

It just stays like this. I left it for about 10 minutes, but nothing seems to happen.
I’m not sure if it’s actually doing anything.
I think it might be trying to restore my backup using the current datadir. But that won’t work, because my server machine only has about 500 GB of space and the data I had before things got messed up had well over 1TB.
I think I have to manage to set the new datadir location first, then try and restore.
But I haven’t managed to do that, yet.
I think it’s a permission issue, but I just can’t figure it out…

Anyway, let me know if you have any other ideas that could help.

Thanks!

Double check for typos in datadir path
Check /var/log/ncp.log
Looks like not enough space to unpack and restore, but still having access right issue,
so maybe look at your /etc/fstab make sure the drive is mounted correctly.

1 Like
  1. Double check for typos in datadir path
'datadirectory' => '/media/root/1fb832f6-8dbe-4299-9ae2-016581e7c893/ncdata',
macmini:~$ sudo ls -la /media/root/1fb832f6-8dbe-4299-9ae2-016581e7c893/ncdata
total 72
drwxrwx--- 1 www-data www-data    94 Nov 25 18:23 .
drwxr-xr-x 1 www-data www-data   126 Nov 25 22:44 ..
-rw-r--r-- 1 www-data www-data     0 Nov 25 17:10 .ocdata
drwxr-xr-x 1 www-data www-data    42 Nov 25 17:45 appdata_ocomyabaa85q
-rw-r----- 1 www-data www-data 53713 Nov 25 22:08 nextcloud.log

The path seems to be ok. No typos apparently.

  1. Check /var/log/ncp.log
[ nc-fix-permissions ] (Fri Nov 26 11:34:13 EET 2021)
data directory not found

[ nc-fix-permissions ] (Fri Nov 26 11:36:34 EET 2021)
fixing permissions in /media/55913678-bb92-45e3-b176-6fbaae768158/ncdata... chown: cannot access '/media/55913678-bb92-45e3-b176-6fbaae768158/ncdata/*/files': No such file or directory
chmod: cannot access '/media/55913678-bb92-45e3-b176-6fbaae768158/ncdata/*/files': No such file or directory
done

[ nc-restore ] (Fri Nov 26 11:37:41 EET 2021)
check free space...

[ nc-fix-permissions ] (Fri Nov 26 13:48:21 EET 2021)
data directory not found

Nothing special, as far as I can see. Only the messages that I already saw after running each command.

  1. maybe look at your /etc/fstab make sure the drive is mounted correctly

Not sure exactly what I should be looking for.
Here’s the output:

macmini:~$ sudo cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=16362642-2325-45ca-a911-5ab1ff052734 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=AC32-BF0E  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/sda3 during installation
UUID=1a088192-6208-45de-a736-83ee8a57e954 none            swap    sw              0       0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

Looks like your /ncdata is not mounted

What’s the output of:

sudo df -hT

Sorry for the late reply.

macmini:~$ sudo df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     383M   11M  372M   3% /run
/dev/sdb2      ext4      454G  249G  182G  58% /
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sdb1      vfat      511M  3.3M  508M   1% /boot/efi
/dev/sda2      btrfs     7.3T  3.5T  3.9T  48% /media/root/1fb832f6-8dbe-4299-9ae2-016581e7c893
tmpfs          tmpfs     383M     0  383M   0% /run/user/1000

I dont see that in your fstab, so how is mounted?
If you did a fsck after power outage, it may be mounted read only?
Can try creating a btrfs subvolume in there.

I used ncp’s automount option to have it mounted automatically.
It worked fine up until now, so I’m not sure what went wrong.

Then probably got mixed up after reboot, check

ls -lh /media/

It is better to use LABEL’s or UUID in fstab to mount, if you have more then 1 usb drive.

Quote from docs:

nc-automount

IMPORTANT

The order of the “automount” is by the label (alphabetical order).
Example of backup disk label: “zBackup”

““WARNING If you want add a second drive later, make sure you have added a LABEL to the first and all other drives to be mounted when formating, as they will then be mounted at /media/LABEL instead of /media/USBdrive”” (alphabetical order). /media/USBdrive is a symbolic link generated on the fly by nc-automount, pointing to /media/zBackup. This is why when you add a drive later without having set LABEL’s, your data drive may turn up under /media/USBdrve1 while NC’s config.php is pointing to /media/USBdrive .

1 Like
macmini:~$ ls -lh /media/
total 8.0K
drwxr-xr-x  4 root root 4.0K Nov 25 22:09 55913678-bb92-45e3-b176-6fbaae768158
lrwxrwxrwx  1 root root   43 Nov 28 18:47 USBdrive -> /media/55913678-bb92-45e3-b176-6fbaae768158
lrwxrwxrwx  1 root root   11 Nov 28 18:47 USBdrive1 -> /media/root
drwxr-x---+ 3 root root 4.0K Nov 30 13:11 root

Should I try to redo the “automount setup”? (i.e. manually unmount my externall hdd, uncheck the auto-mount option and then recheck it and select the external hdd for auto-mounting?)

Is there any risk of losing the data from my hdd if I do this? (maybe some automatic hdd formating?)

I would use UUID to mount in fstab, I like to have full control over mounting :wink: .
So I never use automount, but it should be safe to use. If and when you follow instructions; like adding a label to drives before adding a 2nd one.
And also; It is always best to have backups, better safe then sorry.

1 Like

Ok, I managed to fix it!
I added an entry into fstab and it seems to be ok.
I was able to select a new folder as a datadir. Well, actually the nc-datadir didn’t work. I had to manually edit config.php (and nc-fix-permissions still doesn’t work), but now I’m able to use a folder on my external hdd as a datadir.

I tried restoring a backup, but after 5 HOURS, it failed and said that there was no space left. Somehow, it tried restoring on my machine’s hdd instead of the external hdd. Not sure why.
Anyway, I then manually edited config.php, specified the “good” ncdata folder that was on my external hdd, ran nc-fix-permissions, restarted apache and voila!
Everything is working now!

Thank you very much for your help!

To summarize:

  1. I added an entry in fstab for my external hdd, using the UUID. (apparently, nc-automount doesn’t do that)
  2. I manually added the correct path to my ncdata folder (on my external hdd) in config.php
  3. I ran nc-fix-permissions
  4. I restarted the apache server
  5. I checked that everything is back to normal
1 Like