ownCloud Command Line Sync on Fedora Linux

ownCloud Client normally runs under a graphical enviroment such as Gnome Desktop or Windows. It does however come with a command line utility that allows to perform once off synchronisations on demand. While it doesn’t sync changes automatically like the GUI client daemon it can be used to script periodic syncs of the data between remote host and a local headless clients. Before the client can function setup ownCloud on Shared Web Hosting or local server to act as coud storage service.

 

Install ownCloud Client

Install the client application from official repository.

sudo dnf install owncloud-client

 

Configure netrc

Create netrc file with the relevant credentials.

cat > ~/.netrc << EOF
machine cloud.dominicm.com
login dom
password *********
EOF

The host should be specified with the machine token. It should not contain the protocol part of the URL such as HTTPS:// or trailing slashes. The username and password  of the account are specified with login and password tokens repectively.

 

Change file permissions.

chmod 600 ~/.netrc

Since the password is stored as plain text file permissions should restrict access to the file to provide at least some security. Setting permissions to 600 grants read and write permissions only to the owner of the file.

 

Sync ownCloud Manually

Sync files manually.

owncloudcmd -h -n /mnt/homes/dom/ownCloud/ https://cloud.dominicm.com/

Account username and password are specified with -u or --user and -p or --password respectively. When running from a script using --non-interactive option is advisable to prevent execution blocks with interaction. When using self-signed certificates --trust option may be neccesary to trust all certificates including invalid ones. Hidden files are not synced by default but can be with -h option. Credentials from netrc file will be used when -n option is present. To reduce verbosity -s option can optionally be used. The second last parameters specifies the local sync directory while the last parameter specifies the remote server URL.

 

Run ownCloud Sync

Create systemd service.

sudo bash -c 'cat > /etc/systemd/user/owncloud-sync.service << EOF
[Unit]
Description=ownCloud Sync Service

[Service]
Type=oneshot
ExecStart=/usr/bin/owncloudcmd --non-interactive -h -n /mnt/homes/%u/ownCloud/ https://cloud.dominicm.com/

[Install]
WantedBy=owncloud-sync.timer
EOF'

 

Start the service to perform a single synchronisation.

systemctl --user start owncloud-sync.service

 

Run ownCloud Sync on a Schedule

Create a new systemd timer.

sudo bash -c 'cat > /etc/systemd/user/owncloud-sync.timer << EOF
[Unit]
Description=ownCloud Sync Timer (runs every 1 minute)

[Timer]
OnStartupSec=1m
OnUnitActiveSec=1m
Unit=owncloud-sync.service

[Install]
WantedBy=timers.target
EOF'

The 1 minute timer may be excessive seeing as files are unlikely to change at anywhere near that frequency. High frequency does however allow for a similar experience to that of the GUI client which syncs as soon as file changes are detected. Sync command appears to complete almost instantly when the server and client are in sync so it should not cause issues but only time will tell.

 

Start the systemd timer.

systemctl --user start owncloud-sync.timer

 

Enable timer to run on boot.

systemctl --user enable owncloud-sync.timer