Skip to main content
  1. Posts/

How to Sync a Headless Server with Your Nextcloud Files

·451 words·3 mins·
System Administration
Table of Contents

When it comes to keeping your headless server synchronized with your Nextcloud server, setting up a reliable automated process is crucial. This guide will walk you through syncing top-level directories on an Ubuntu server. While this explanation uses Ubuntu, be aware that some commands, such as package installation, may vary on other Linux distributions.

Step 1: Install the Nextcloud Command-Line Client
#

First, you’ll need to install the Nextcloud command-line client to manage the synchronization:

sudo apt install nextcloud-desktop-cmd

Ensure the package installs successfully so that you can proceed with setting up automated sync tasks.

Configure Credentials
#

To enable authentication for nextcloudcmd, add your credentials to the ~/.netrc file with the following format:

machine your-next-cloud-domain.org
login your-username
password your-password

Replace your-username and your-password with your actual Nextcloud login details. This file ensures that the command-line client can authenticate without manual input.

Step 2: Choose Directories to Sync
#

For simplicity, I prefer syncing only the top-level directories that are important to me, such as src and similar folders. This approach keeps the sync process efficient and focused.

Step 3: Create the systemd Service File
#

To automate the syncing process, create a systemd service file that defines how the sync should be executed. Save the following content as ~/.config/systemd/user/nextcloud-sync-src.service:

[Unit]
Description=Nextcloud Sync Src

[Service]
Type=simple
ExecStart=/usr/bin/nextcloudcmd -n --non-interactive --path /src /home/mauro/src https://your-next-cloud-domain.org
TimeoutStartSec=300
Slice=nextcloud-sync.slice

[Install]
WantedBy=default.target

Step 4: Create the systemd Timer File
#

The systemd timer will trigger the service at regular intervals. Save the following as ~/.config/systemd/user/nextcloud-sync-src.timer:

[Unit]
Description=Run Nextcloud Sync Src every 5 minutes
Requires=nextcloud-sync-src.service

[Timer]
Unit=nextcloud-sync-src.service
OnUnitInactiveSec=5m
RandomizedDelaySec=5m
AccuracySec=1s

[Install]
WantedBy=timers.target

This configuration ensures that the service runs every 5 minutes with a randomized delay for slight variability.

Step 5: Create a systemd Slice File
#

To limit resource usage, create a slice file to manage CPU and memory allocation. Save this content as ~/.config/systemd/user/nextcloud-sync.slice:

[Unit]
Description=Nextcloud Sync Slice
DefaultDependencies=no
Before=slices.target

[Slice]
CPUQuota=30%
MemoryMax=2G

This configuration will limit the sync process to 30% of the CPU and a maximum of 2 GB of memory.

Step 6: Load and Enable the Timer
#

To activate the service and timer, reload the systemd user daemon and enable the timer:

systemctl --user daemon-reload
systemctl --user enable nextcloud-sync-src.timer
systemctl --user start nextcloud-sync-src.timer

Step 7: Monitor the Service and Timer
#

To check the logs for the service, use:

journalctl --user -u nextcloud-sync-src

To list active timers and see when they last ran or are scheduled to run next, use:

systemctl --user list-timers

Conclusion
#

With this setup, your headless server will automatically sync the specified directories with your Nextcloud server every 5 minutes. This approach keeps your essential files up-to-date without manual intervention, optimizing the workflow for your headless environment.

Reply by Email

Related

Remote Setup with EdgeVPN
·208 words·1 min
System Administration

Last week I started using my old 13" laptop and left the bulky 15" workstation permanently at my desk. This setup gives me portability without loosing power when I’m connected to my home network. Today, I decided to configure EdgeVPN on both devices to also have this setup while on the road.

Running Multiple Instances of a Service
·679 words·4 mins
System Administration

This article will teach you how to run one or more Redis instances on a Linux server using systemd to spawn copies of a service.

Epomaker Tide75 Keyboard Review
·1732 words·9 mins
Hardware

You know that feeling when you are trying not to buy new mechanical keyboards and still one manages to find its way to your desk? Well, that’s precisely how I felt last week when a package from Epomaker arrived! For about a fortnight, I’ve been putting the Tide75 to the test, let me tell you what I found!

How Does a Raspberry Pi 5 Boot an image?
·1054 words·5 mins
System Architecture

When the Raspberry Pi5 is turned on, it will check on which device it is configured to boot. By default, this is the SD card, but you can change it to boot from an NVMe or USB drive while still fallback to SD. In my case, I’m using a USB SSD. Let’s take a look at how the disk is partitioned.

A New Dawn for Secure Linux in Untrusted Environments
·490 words·3 mins
System Architecture

Linux has become the default operating system for running web applications. However, like any system connected to the internet, it is exposed to remote attacks. While public cloud environments and private datacenters offer some security from physical tampering, edge computing presents unique challenges.

Running a Patched Ruby on Heroku
·660 words·4 mins
Plataforms

You use a PaaS because you want all the underlying infrastructure and configuration of your application to be hidden from you. However, there are times when you are forced to look deeper into the stack. In this article I want to share how simple it is to run a patched version of Ruby on Heroku.