[Guide] Easy setup to backup files to my OwnCloud server with Rclone on SailfishOS

Setting up Rclone on my Jolla2 to backup my pictures etc. to my Owncloud server.

Even if having used HPUX at work from 1980s I do not have too much experience using shell scripts, services etc. in Linux. In my XperiaX I used GhostCloud and Sailsync, but I did not get it working in my Jolla2. I found some instructions that I tried to follow.

Automated Backup with Rclone and a systemd Timer

However, it took me some time to understand and manage to get the setting to work. Some options in shell scripts did not work or exist in Sailfish (pidof -x), so I left those checks away. (Below Keto explained why.)

So I think, that as difficult as it was for me, this may be of help for someone new to Sailfish.
There may be better ways to do it, but here is how I did it, it is just a basic setup, and it works for me.

Someone with more knowledge may make it more usable and streamlined.

First I created folder where I softlinked Pictures and Videos folders of Sailfish.

mkdir /home/defaultuser/OC

(OC since I use OwnCloud to backup my files :slight_smile: ).

Loaded rclone from

and installed.

Ran config

rclone config

as defaultuser and selected:

e/n/d/r/c/s/q> n (New remote)
name> OC
Storage> 63 (WebDAV)
url> https://myserver.com/owncloud/remote.php/dav/files/heikkiap/
vendor> 3 (Owncloud 10 PHP based WebDAV server)
user> heikkiap
Password> y
Enter the password: “typed my password”
Confirm the password: “typed my password”
bearer_token> “ENTER” to leave empty
Edit advanced config?
y/n> n
Keep this “OC” remote?
y/e/d> y
e/n/d/r/c/s/q> q (selected q to quit)

Now I had rclone.conf file:

/home/defaultuser/.config/rclone/rclone.conf
[owncloud]
type = webdav
url = https://myserver.com/owncloud/remote.php/dav/files/heikkiap/
vendor = owncloud
pass = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
user = heikkiap

I edited rclone.conf file (had to install nano editor to make editing more convenient), added lines at the beginning, so I had:

[my-files]
type = alias
remote = /home/defaultuser/OC

[owncloud]
type = webdav
url = https://myserver.com/owncloud/remote.php/dav/files/heikkiap/
vendor = owncloud
pass = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
user = heikkiap

Then created backup script, guided from instructions:

/usr/local/bin/rclone-backup.sh
#!/bin/bash

#if \[\[ “`pidof -x $(basename $0) -o %PPID`” \]\]; then
#echo “rclone-backup.sh is already running”
#exit;
#fi

rclone copy -v --fast-list --transfers 30 “my-files:” “owncloud:” -L

(had to comment lines for script already running, since pidof -x gave error message. (Again, Keto explained why, but left commands visible as they were in the original link of instructions.)

Created file for service, guided from instructions:

/etc/systemd/user/rclone.service (improved by Keto suggestion)
[Unit]
Description=RClone Backup

[Service]
Type=simple
ExecStart=/usr/local/bin/rclone-backup.sh

Created timer file, guided from instructions:

/etc/systemd/user/rclone.timer (improved by Keto suggestion)
[Unit]
Description=RClone Backup Timer

[Timer]
Unit=rclone.service

#Run 15 minutes after boot, since the timer must run at least once
#before OnUnitInactiveSec will trigger
##OnBootSec=15m

#Run 15 minutes after rclone.service last finished
##OnUnitInactiveSec=15m

#Run once when the timer is first started
##OnActiveSec=1s

#Run on calendar, “WallClock”
#Run every day at 3:00 AM
OnCalendar=*-*-* 03:00:00

[Install]
WantedBy=timers.target

Selected to run the backup just every night at 03:00, not sure if “OnBootSec” or “OnInitInactiveSec” are essential, but for me it works like this.

And as instructions guides I ran (not as root, but as user, by Keto improvements in the file locations):

systemctl -–user daemon-reload
systemctl –-user enable rclone.timer
systemctl –-user start rclone.timer

You can check the timer status with:

systemctl –-user status rclone.timer

You can also check the status of the service with:

systemctl -–user status rclone.service

If you want to manually run a backup at any time, just start the service manually:

systemctl --user start rclone.service
10 Likes

Very nice guide, couple of improvement suggestions though:

The systemd service and timer probably shouldn’t be system level and run as root. So instead put them in /home/defaultuser/.config/systemd/user/ (or /etc/systemd/user/). And then use systemctl --user ... commands as normal user. Also if it’s run as root, I doubt that it works unless you copied the rclone config in /root/.config/...

The systemd service file probably does not need the [Install] section, and shouldn’t be enabled, as it is started by the timer.

Many tools and commands, like pidof come from busybox, and are slightly different. And also the shell is not bash, but busybox ash. So those need to be taken into account when writing scripts. In this case the “already running” check is not necessary as systemd timer does not start the service if it’s already running. If you want to guard against manual runs or such, using flock on some lock file might be better.

Also use code blocks (“preformatted text” button in the tool bar) in your post, to make sure the markdown formatting does not mess up the examples. e.g.

```
some code...
```
16 Likes

Thanks for the suggestions, I tried to include them. Now it worked for me at least when running manually.

And you were right, I had rclone.conf also in /root/.config/...after my unsuccessful trials.

1 Like

My personal preference for creating new systemd units is systemctl edit command. Helps with problems related to remembering the locations of units, and I just find it very convenient.
Use systemctl edit --full --force some-new-unit.sometype for new system units and systemctl edit --full --force --user some-new-unit.sometype for user units.

1 Like

Thank you for correcting the format of the message for a newbie…

I especially appreciate the way you commented and acted by editing my improper formatting: not complaining that “you should know how to use this and that…”.

3 Likes