I’m very much a noob to… everything… but amazingly I’ve managed to get NextCloudPi running on my Raspberry Pi exactly how I want it, but for some reason, I can’t get snapshot sync to do anything.
I enable it in either the web ui or TUI, it tells me that it’s enabled, but nothing ever seems to sync.
I’m not sure if it’s not syncing at all or if the snapshots are hidden so well that I can’t find them, and I’d appreciate some help setting it up / troubleshooting.
For reference, I’m running NextCloudPi on a Raspberry Pi 4 with two USB drives attached, one for data and the other for backup. I want to sync the snapshots to the backup drive in case the main drive fails, and I figured snapshots would be better than backups as there would be no downtime on NextCloud.
Both drives were formatted to BTRFS within NextCloudPi. The data drive (myCloudDrive) is working fine, and snapshots are happily being created.
When I enable snapshot sync in either web-ui or tui, it says that it’s enabled.
But, nothing ever seems to happen Nothing appears in the log around snapshot-sync time to indicate that it tried to do anything.
And the snapshots subvolume on my backup drive apparently sits empty
I would appreciate any help or pointers that anyone here can give. Again, complete noob here, and I’m amazed I’ve gotten this far. I saw some posts online suggesting that I don’t use snapshot-sync on ncp and instead use btrbk, but the documentation for that was almost impenetrable for me because, you know, noob
Thank you in advance!
There is a daily cronjob created and a first approach could be to check syslog for btrfs-sync messages. If this looks fine I’d run the statement manually (with sudo). The scripts writes messages to console if some conditions are not met. Hope this helps
Thank you for your help. We might be getting somewhere. I found the following in syslog:
Oct 24 04:30:01 nextcloudpi CRON: (root) CMD ( /usr/local/bin/btrfs-sync -qd “/media/myCloudDrive/ncp-snapshots” “/media/myBackupDrive/ncp-snapshots”)
Oct 24 04:30:01 nextcloudpi CRON: (www-data) CMD (php -f /var/www/nextcloud/cron.php)
And when I tried to run the command, it said that the snapshot directory in the data drive (not the backup drive where I assumed the problem was) is not read only
So I changed it to read only, and the btrfs-sync error went away
Unfortunately, although we might be a step closer, my snapshot directory on the backup drive still appears to be empty
If it’s not too much trouble, do you know what I could try next?
The file manager displays …./ncp-snapshots/ncp-snapshots. That‘s weird because there should only be one ncp-snapshot directory. I‘d start with an empty directory.
If this does not succeed I‘d create a copy of the btrfs-sync script and append -x to first line of the script that defines the interpreter usage (here it‘s bash). This option displays all commands as they are executed. I found this option very useful to get an idea what‘s exactly going on.
It looks like the btrfs-sync command is making that folder, but not populating it with any snapshots
I tried removing the folder and it just went and added it back
That’s strange, because in my script there is no command to create a directory. As I said befor I’d run a copy of the script with “bash -x” in the first line, without quiet option and redirecting the output (stdout as well as stderr) for further analysis.
Oooh, it might be a permissions problem
These are the permissions for the snapshot subvolume and its contents
I meant something like the commands below (there should be no permission issue):
cp -p /usr/local/bin/btrfs-sync /tmp/btrfs-sync
sed -i -e '1,1s/bash/bash -x/' /tmp/btrfs-sync
diff /usr/local/bin/btrfs-sync /tmp/btrfs-sync
sudo /tmp/btrfs-sync -d "/media/myCloudDrive/ncp-snapshots" "/media/myBackupDrive/ncp-snapshots" > /tmp/btrfs-sync.log 2>&1
Thank you. I’m very much a noob here, as you can probably tell
I’ve put the contents of the log file on pastebin
Trying to see if there’s anything funky going on
The log file was very helpful. The script does exactly what it should. ncp-snapshots is the only snapshot and not a directory that contains snapshots. Therefore the backup sync directory named ncp-snapshots contains a snapshot named ncp-snapshots.
I for one have activated automatic snapshots. This creates a directory ncp-snapshots and that contains hourly, daily, weekly and monthly snapshots. These can then be synchronized as intended on a regular basis.
So, I’d delete ncp-snapshots using „btrfs subvolume delete“ command, then enable automatic snapshots and afterwards snapshot sync.
Ok… But I thought I’d already done that. I set up auto-snapshots in NCP and I do have snapshots being automatically created within that directory
They’re all sitting happily on myCloudDrive/ncp-snapshots and they’re up-to-date. I’m not sure why snapshot-sync seems to be just syncing the subvolume and not its contents
Is the suggestion to just delete the whole subvolume and set up auto-snapshots again? If I do that with “btrfs subvolume delete” it doesn’t do it because it’s not empty
When I run on my box the following command I get
pi@nextcloudpi:~ $ sudo btrfs subvolume show /media/myCloudDrive1/ncdata/ncp-snapshots; echo $?
ERROR: Not a Btrfs subvolume: Invalid argument
pi@nextcloudpi:~ $ sudo btrfs subvolume show /media/myCloudDrive1/ncdata/ncp-snapshots/hourly_2023-10-30_091703/; echo $?
Parent UUID: 8bfb72d3-b743-9f45-82a8-e07a821e673e
Received UUID: -
Creation time: 2023-10-30 09:17:03 +0100
Subvolume ID: 4841
Gen at creation: 104834
Parent ID: 5
Top level ID: 5
pi@nextcloudpi:~ $ sudo btrfs subvolume show /media/myCloudDrive1/ncdata/ncp-snapshots/hourly_2023-10-30_091703/ncp; echo $?
ERROR: Not a Btrfs subvolume: Invalid argument
which means, that ncp-snapshots is NOT a subvolume. If you have a look at lines 56-57 in your log you’ll see the following lines:
+++ btrfs subvolume show /media/myCloudDrive/ncp-snapshots
+++ echo '0|/media/myCloudDrive/ncp-snapshots'
which means, that your ncp-snapshots is a subvolume and satisfies the condition to iterate over all subvolumes (line 43).
Which means that ncp-snapshot has to be a regular directory rather than a subvolume.
In some of your screenshots above the command dir in ncp-snapshots did not return any files. So I assumed that automatic snapshots are not configured.
I’d move all files in ncp-snapshots to a new directory ncp-snapshots.new, delete subvolume ncp-snapshots (should be empty) and rename (mv) ncp-snapshots.new to ncp-snapshots.
Look what I’ve got
Snapshot sync is working Thank you so much for your time, help, and being very patient with me
So here’s where it all went wrong… The ncp-snapshots directories were indeed subvolumes instead of normal directories. How that happened? It was probably me, but I’d been following a thousand guides running commands on an OS that I’m not yet familiar with.
And I thought I had it set up right because snapshots were working, but clearly it was set up wrong.
So I deleted the subvolumes, let NCP make the source directory on my data drive and used mkdir to make a directory on the backup drive, and it’s all working as intended.
Thank you again for your support. I really appreciate it