Rclone daemonized

Hi!

I run a headless Linux server.

Is there a way to run rclone in daemon mode, in order to keep a certain portion of the filesystem syncronized with a remote cloud storage?

Thanks.
Regards.

make a sync script and run it in crontab

1 Like

Hi!

That’s an approach, but I was thinking about something running in the background, like Lsyncd, for example, but for rclone.

Thanks.
Regards.

As far as i know there is no other way to do it.

Run it in a crontab. Or run it on a “screen”, then you can ssh and see what’s happening.
That’s a better choice than cron.

screen -dmS rclone-sync bash -c ‘cd /home/myusername;rclone sync sourcedir amazon:destdir; exec bash’

Something like that.

Not currently.

There is an issue about it: https://github.com/ncw/rclone/issues/249 which you may find interesting.

A bit of screen + shell as suggested above will work though

2 Likes

Just to give another option, you can use systemd to achieve crontab-like functionality and on most systems that would be the more modern way to do it.

/etc/systemd/system/rclone-sync.service:
[Unit]
Description=Sync files between different remotes via rclone
[Service]
Type=simple
ExecStart=/usr/bin/rclone-sync

/etc/systemd/system/rclone-sync.timer:
[Unit]
Description=Perform an rclone sync periodically.
[Timer]
OnBootSec=1h
OnUnitActiveSec=3h
[Install]
WantedBy=timers.target

/usr/bin/rclone-sync:
rclone sync acd: gdrive:

In this simple example you could just replace ExecStart=/usr/bin/rclone-sync with ExecStart=/usr/bin/rclone sync acd: gdrive:
But since the rclone command can get pretty convoluted, or you might want to do some pre- and post-processing, i personally prefer to just call a script.

Enable with
systemctl enable rclone-sync.timer
systemctl start rclone-sync.timer

Monitor via the usual systemd commands, e.g.:
systemctl list-timers
journalctl -u rclone-sync -a

You can configure the timer so that the service will be continuously running but i don’t think that’s the best idea. just set the timer to a couple of minutes, if you really need high frequency updates.

this solution works for me but note that the service does not run in your user’s account but with the system account. System will not be able to find your rclone config.

i changed this be adding a su - to /usr/bin/rclone-sync:

su - myusername -c “rclone sync -v gdrive: /var/gdrive_rclone --drive-alternate-export”

You can set the user in the systemd config

[Service]
User=www-data
Group=www-data

Which might be easier

1 Like