Tinysync is a simple tool for keeping a directory synchronized between multiple computers. Its primary design goal is to be small, lightweight, and not to require additional software to accomplish this task.
Tinysync is based on Bash and rsync — it is known to run on Linux and FreeBSD, but should work on any Unix-compatible operating system. The tool requires a central server to synchronize data with, but in fact does not require installation of any software on this server. The required packages are typically installed as part of the base operating system.
- A single user, working on different computers during different times of the day
- A single user, working on different computers simultaneously
- Multiple users sharing files with each other
Tinysync does not implement logic for locking files or resolving conflicts. If files are modified on different clients simultaneously then some of these changes will get lost!
File | Description |
---|---|
sync.conf.sample | Sample configuration file which needs to be copied and modified according to your setup |
sync.conf | The configuration file which includes information about your setup, such as server address and user name |
sync.sh | The main executable script which synchronizes the directory with the server |
systemd/sync@.service, systemd/sync@.timer | Optional systemd timer which can be used to periodically run sync.sh |
sync.desktop | Optional desktop entry which can be used to manually run sync.sh |
autosync.sh | Optional executable script which will enable automatic synchronization when the directory is modified |
systemd/autosync@.service | Optional systemd service which can be used to automatically run autosync.sh upon startup |
autosync.desktop | Optional desktop entry which can be used to automatically run autosync.sh upon startup |
The preferred method for setting up the Tinysync server is by running a container from the pre-built Docker image acch/tinysync. You will need to supply your public SSH key when running the container.
Using plain Docker:
docker run --rm \
--name tinysync \
-p 2222:22 \
-v tinysync_ssh:/etc/ssh \
-v tinysync_data:/home/tinysync \
-e AUTHORIZED_KEYS="$(cat ~/.ssh/id_rsa_tinysync.pub)" \
acch/tinysync
Using Docker-Compose:
version: '2'
services:
tinysync:
image: acch/tinysync
container_name: tinysync
ports:
- "2222:22"
volumes:
- ssh:/etc/ssh
- data:/home/tinysync
environment:
- AUTHORIZED_KEYS=...
restart: always
volumes:
ssh:
driver: local
data:
driver: local
Note that the Docker image has a pre-defined (fixed) user named tinysync. The actual data volume should always be mounted to /home/tinysync
.
To manually install the Tinysync server component ensure that you have openssh
and rsync
installed on that system.
Tinysync relies on SSH Public-Key Authentication (a.k.a. password-less logins) to be set up so that a client can connect to the server without being prompted for a password. Ensure that SSH Public-Key Authentication is enabled on your server:
/etc/ssh/sshd_config:
...
PubkeyAuthentication yes
...
In addition, you will need to add your public SSH key to the file ~/.ssh/authorized_keys
on your server. The easiest way to achieve this is by running the following command from one of your clients:
ssh-copy-id -i ~/.ssh/id_rsa_tinysync.pub REMOTE_USER@YOUR_SERVER
The preferred method for installing Tinysync on clients is by using the install.sh
script. Alternatively, you can follow the Manual Installation procedure below.
-
There are several options for downloading the software:
- Download the latest release
- Clone the repo:
git clone https://github.com/acch/tinysync.git
Download the software to a client, extract the archive (if applicable), and run the automatic installer script:
tinysync/install.sh
-
Modify the sample configuration according to your setup:
vi /usr/local/bin/sync.conf
-
Manually run
sync.sh
from a terminal to verify that your configuration parameters are correct. When connecting to a server for the first time, ensure that the directory does not exist on the server (it will be uploaded). When adding more clients later, ensure that the directory does not exist on the client (it will be downloaded). -
Once manual synchronization of the directory works well you can enable automatic synchronization for your user account with the following commands :
sudo systemctl enable sync@YOUR_USER.timer sudo systemctl start sync@YOUR_USER.timer sudo systemctl enable autosync@YOUR_USER sudo systemctl start autosync@YOUR_USER
-
Download the software to a client, extract the archive (if applicable), and place the executable files and configuration sample in a directory of your choice (such as
/usr/local/bin
).git clone https://github.com/acch/tinysync.git cp tinysync/sync.sh tinysync/autosync.sh tinysync/*.sample /usr/local/bin/
-
Copy the sample configuration file and modify it according to your setup:
cd /usr/local/bin cp sync.conf.sample sync.conf vi sync.conf
-
Tinysync relies on SSH Public-Key Authentication (a.k.a. password-less logins) to be set up so that a client can connect to the server without being prompted for a password. Ensure that
rsync
is installed on both, client and server. -
Manually run
sync.sh
from a terminal to verify that your configuration parameters are correct. When connecting to a server for the first time, ensure that the directory does not exist on the server (it will be uploaded). When adding more clients later, ensure that the directory does not exist on the client (it will be downloaded). -
In a typical usage scenario you will want to repeatedly synchronize the directory, e.g. via cron. Add something like the following to your crontab (
crontab -e
) to enable scheduled synchronization:*/10 * * * * /usr/local/bin/sync.sh &>> /var/log/sync.err
Alternatively, you can use systemd timers to periodically synchronize the directory on systemd-based distributions. Simply copy the
systemd/sync@.service
andsystemd/sync@.timer
files to the folder/etc/systemd/system
and enable it for your user account:sudo systemctl daemon-reload sudo systemctl enable sync@YOUR_USER.timer sudo systemctl start sync@YOUR_USER.timer
-
In addition to scheduled replication, you can manually run
sync.sh
to synchronize the directory with the server. Copy thesync.desktop
file to the folder~/.local/share/applications/
to add an appropriate menu entry. You may need to edit the desktop entry so that is contains the appropriate path tosync.sh
:... Exec=/usr/local/bin/sync.sh ...
-
You can also enable automatic synchronization using
autosync.sh
. It requires the installation of inotify-tools, as well as an inotify-compatible filesystem.Note that automatic synchronization using
autosync.sh
is optional. Even if you enable automatic synchronization you should still configure scheduled replication (via cron or systemd) in addition to that.To enable automatic synchronization, run
autosync.sh
upon startup. There are numerous mechanisms you can use:The preferred way of running
autosync.sh
is via systemd. In addition to enabling automatic synchronization, the systemd service will delay system shutdown so that a running synchronization is not interrupted.For systemd-based distributions copy the
systemd/autosync@.service
file to the folder/etc/systemd/system
and enable it for your user account:sudo systemctl daemon-reload sudo systemctl enable autosync@YOUR_USER sudo systemctl start autosync@YOUR_USER
For Gnome on Linux copy the
autosync.desktop
file to the folder~/.config/autostart/
. You may need to edit the desktop entry so that is contains the appropriate path toautosync.sh
:... Exec=/usr/local/bin/autosync.sh ...
For KDE on Linux create a symbolic link to
autosync.sh
in the folder~/.kde/Autostart/
.
Q: Automatic synchronization doesn't work, what can I do?
A: First of all, ensure that you have the inotifywait
binary installed. On most distributions it is provided by a package inotify-tools.
If inotifywait
is indeed installed but you are attempting to synchronize a large directory you may need to adapt the kernel parameter fs.inotify.max_user_watches. In such case you will encounter the following error message when trying to run autosync.sh
:
Failed to watch ...; upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.
To increase the amount of inotify watches, simply create a new file /etc/sysctl.d/inotify.conf
:
fs.inotify.max_user_watches = 16384
Copyright Achim Christ, released under the MIT license.