[Guide/Hack] Automatic Nextcloud file sync when directory contents change

Yeah, that is a limitation/design decision of systemd .path units.

Of course, one could probably make a .path unit which creates more .path units :wink:

Or, one might use incrond (package currently not widely available, though I have a build on OBS) which predates systemd and can do similar things when file locations change - and I think incrond can watch directories recursively.

I’ve got it running for photos and video now; that’s the most important for me :slight_smile: Thanks for the solution.

1 Like

Hi @nephros,

thanks for sharing your job.
Is this script still working?

On y XA2 , I’m on SFOS 4.4.0.58, with SailSync 0.9.2 working like a charm.

But directory ~/.config/harbour-io.edin.projects.sailsync-owncloud/ doesn’t. Instead, I can found ~/.config/io.edin/harbour-io.edin.projects.sailsync-owncloud/ directory, but unfortunately, it is empty, with no config.db file.
Can you help?

Have you successfully configured account and folders in sailsync itself?

yes for sure. I have 4 path configured in Sailsync, and it works.

Hmmm, just checked, and both folders exist here (4.4.0.64/aarch64), the former having the .db file as usual…

$ ls -l /home/nemo/.config/harbour-io.edin.projects.sailsync-owncloud
total 12
-rw-r--r--    1 nemo     nemo          8192 Jun 23 22:27 config.db
-rw-r--r--    1 nemo     nemo           127 Jun 23 22:58 config.ini

You are totally right, maybe I made a typo…
Sorry for that.

Addendum: the incredibly powerful tool rclone has support for many cloud storages, including WebDAV/Nextcloud and can be used as a replacement for Sailsync Owncloud or any other tools.
It also handles authentication much more securely, so obsoletes the .netrc stuff.

Set up the cloud target using rclone config, add a local or alias configuration for your local dirs, and call rclone from either a wrapper or directly from the systemd service.

rclone is not available from any repo (except from some ancient, dangerous Openrepos ones like Schtuhrman’s), but you can download and install the binary directly from the rclone web site. It’s just a single binary, so rather safe to install.


Here is an example config. Do not copy-paste this, use the command rclone config to set it up!):

[home]
type = alias
remote = /home

[my-home]
type = alias
remote = home:/nemo

[my-pics]
type = alias
remote = my-home:/Pictures

[nextcloud]
type = webdav
url = https://nextcloud.example.org/remote.php/webdav/
vendor = nextcloud
user = nextclouduser
pass = mYVeryS3cr3TP@assKeY

[nc-pics]
type = alias
remote = nextcloud:/Sailfish-Pictures

You would call this as:

rclone -q sync my-pics: nc-pics:  

Or interactively (recommended for testing the first few tries):

rclone -i sync my-pics: nc-pics:  

There is also an experimental ‘bisync’ mode which may or may not be what you want to try.

Do read the extensive rclone documentation before implementing any of this though.

2 Likes

I’m using the old standard inotify + curl approach. But systemd is already there, and user units as I understand it live in user’s home, so I don’t recommend my method :slight_smile: I just had recipes on hand for inotify (which is a sign of my age).

Would it be possible to advise me on how to install RClone from binaries? This will assist for other programs.

Thank you

I might had done it, download package for arm64 and click install.

https://downloads.rclone.org/v1.60.0/rclone-v1.60.0-windows-arm64.zip

What would be the command in terminal?

Thanx

You mean how to install from terminal? Something like

curl -LO <url>
unzip !$:t   # ;)

If it’s the zip file. For an RPM it’s either

pkcon install-local <filename>

or

 xdg-open <filename>

If you mean how to use rclone, a rough guide is about three comments up.

2 Likes

I thank you @nephros, indeed, these commands what I was looking for, and you added more… much appreciated…

So is mounting a WebDAV-Resource with rclone better in terms of easier configuration and performance when compared to davfs2?

Just set up rclone. It’s really nice. Thanks a lot!

@nephros, you didn’t by any chance set up automatic syncing of contact and calendars? I’ve gotten so far that I can dump contacts or calendars and split them and sync em via vdirsync. Or maybe that works for you with the given tools.

contacts and calendar works with just the built in account

Really? How? I spent 6 hours debugging this yesterday and it most certainly does not just work. Under some circumstances. Could you specify whether you had a ‘Personal’ calendar in your nc before setting up the phone? Are you using ‘Deck’ and or ‘Tasks’?

Testing another phone, account, now.

Using one of the calendars (the Personal that is default on nextcloud) from NC with a second account and other phone I have the same behaviour. None of my events from the phone’s default account get synced. But I’m debugging in another thread.

I dunno, it just works ™
https://i.imgur.com/OqujOlc.png
https://i.imgur.com/dEFpjP9.png

I havnt added to the calendar from the phone, i just add stuff in nextcloud web interface and see them appear on the phone. As you can see, it synced nextcloud contact birthdays, personal calendar and deck calendar

Ah, that’s what I meant. Stuff from the Phone Calendar and Contacts from the phone have to come from the nextcloud instance to sync. So, you’re in the same boat as I, I just made a false assumption. I’ve already synced contacts and calendars using vdirsync, so it looks like I need to ‘empty’ my phones and then sync. It’s a bit odd that sync on the phone won’t try to add the local calendars or contacts. Works fine from the phone with vdirsync.