My one-line Dropbox client for Linux
- Transfer
I want to talk about my attempt to create a simple one-line Dropbox client for Linux, using only free components with open source, including rclone , entr and systemd .
Recently, the proprietary Dropbox client for Linux has refused to support all Linux file systems, except unencrypted ext4 . And my home directory, "unfortunately", is encrypted.
In early December, the proprietary client stopped working. He logged out and offered to choose another synchronization folder in the “supported file system”.
By the way, I run Ubuntu Bionic on the two-year-old Thinkpad t460s.
I actively use Org mode : I make notes in plain text, and Dropbox continuously backs up notes while typing.
If you also work in the field of storage infrastructure, my use case is very similar to “asynchronous single-master replication”, that is, with one master. All records pass through my Thinkpad, this is the master. The remote Dropbox folder is just a read-only replica, which I sometimes "issue read-only requests" or use as a backup to create a new wizard when the current one fails or is stolen.
However, this replication setting saved my life several times. I still have it before my eyes, as the Thinkpad refused to boot during the second-year session. Since I constantly replicated all the notes in Dropbox, I did not lose any data and was able to view the latest notes on my mom's Macbook. Thanks, mom!
When the Dropbox client stopped working, I focused on finding another similar multifunctional remote client for Linux. In principle, I do not mind switching to another service, such as Google Drive or AWS S3. Some of the options are overGrive and insync .
However, I came to the conclusion that these solutions are too functional and not very suitable for my case .
For example, clients try to connect a remote file system to your PC . They try very hard to abstract remote file systems, making them look like local ones. As a rule, they implement two-way synchronization, automatic mapping of remote file types to Linux file types, etc.
I do not need this level of abstraction. Something simple is required that allows you to constantly create backup copies of notes in the cloud while I type the text. In addition, abstractions make configuration and debugging difficult. Not to mention the fact that most of these multi-functional clients are proprietary.
I came across a utility
For example, it
The following command synchronizes the remote directory
The entr utility uses the inotify API . In fact, it runs commands when changing files without polling the file system.
One common use is to rebuild a project if one of the source files has changed .
Now we have
The final script (
A daemon is just a computer program that runs in the background. Let's make our script a background process so that it constantly synchronizes local changes of files in the background with a remote file system.
systemd provides an interface for managing daemon processes.
I created Dropbox Service in
You can then control the daemon with the following commands:
In this article, we discussed how to apply the UNIX philosophy and use a set of free open source tools to replace the proprietary and outdated Dropbox client. We applied
I want to remind you that the key idea is simplicity. We want simple solutions for simple tasks. My use of Dropbox is very simple. And this is why a single-line script is better than using an unnecessarily functional and proprietary cloud client.
Thanks so much for reading! I really hope that you enjoy this post. If you know the best way to do the same or expand the script for another use case - let us know in the comments!
Context
Recently, the proprietary Dropbox client for Linux has refused to support all Linux file systems, except unencrypted ext4 . And my home directory, "unfortunately", is encrypted.
In early December, the proprietary client stopped working. He logged out and offered to choose another synchronization folder in the “supported file system”.
By the way, I run Ubuntu Bionic on the two-year-old Thinkpad t460s.
Why do I need Dropbox
I actively use Org mode : I make notes in plain text, and Dropbox continuously backs up notes while typing.
If you also work in the field of storage infrastructure, my use case is very similar to “asynchronous single-master replication”, that is, with one master. All records pass through my Thinkpad, this is the master. The remote Dropbox folder is just a read-only replica, which I sometimes "issue read-only requests" or use as a backup to create a new wizard when the current one fails or is stolen.
However, this replication setting saved my life several times. I still have it before my eyes, as the Thinkpad refused to boot during the second-year session. Since I constantly replicated all the notes in Dropbox, I did not lose any data and was able to view the latest notes on my mom's Macbook. Thanks, mom!
Failed attempts
When the Dropbox client stopped working, I focused on finding another similar multifunctional remote client for Linux. In principle, I do not mind switching to another service, such as Google Drive or AWS S3. Some of the options are overGrive and insync .
However, I came to the conclusion that these solutions are too functional and not very suitable for my case .
For example, clients try to connect a remote file system to your PC . They try very hard to abstract remote file systems, making them look like local ones. As a rule, they implement two-way synchronization, automatic mapping of remote file types to Linux file types, etc.
I do not need this level of abstraction. Something simple is required that allows you to constantly create backup copies of notes in the cloud while I type the text. In addition, abstractions make configuration and debugging difficult. Not to mention the fact that most of these multi-functional clients are proprietary.
rclone
I came across a utility
rclone
, and I immediately understood: this is exactly what I was looking for. A simple but powerful program. Very similar to the tool rsync
, only for cloud storage. For example, it
rclone
takes care of fault tolerance (integrity check), has efficient synchronization algorithms and so on, while providing a simple CRUD interface for interacting with popular cloud storage services, including Amazon S3, Google Drive and Dropbox. The following command synchronizes the remote directory
org
with the local directory /home/lpan/org
.ORG_DIR=/home/lpan/org
REMOTE=dropbox
rclone sync $ORG_DIR$REMOTE:org
entr
The entr utility uses the inotify API . In fact, it runs commands when changing files without polling the file system.
One common use is to rebuild a project if one of the source files has changed .
entr
takes a list of absolute paths from stdin
, and then executes the command passed as an argument if any of the monitored files has changed.WORKDIR=/path/to/myproject
find $WORKDIR | grep "\.cpp$" | entr make
Single line script
Now we have
rclone
and entr
. The final script was very simple. Let me remind you that my use of Dropbox is very simple: you only need to constantly replicate local Org files when they change. Therefore, it can be used entr
to monitor files and rclone
to “synchronize” with remote storage. The final script (
/home/lpan/sync_dropbox.sh
) looks like this:#!/bin/bash
ORG_DIR=/home/lpan/org
REMOTE=dropbox
find $ORG_DIR | entr -r rclone sync -v $ORG_DIR$REMOTE:org
Run the demon
A daemon is just a computer program that runs in the background. Let's make our script a background process so that it constantly synchronizes local changes of files in the background with a remote file system.
systemd provides an interface for managing daemon processes.
I created Dropbox Service in
~/.config/systemd/user/dropbox.service
.[Unit]
Description=Dropbox Daemon
[Service]
ExecStart=/home/lpan/sync_dropbox.sh
Restart=always
[Install]
WantedBy=default.target
You can then control the daemon with the following commands:
# reload the service file
systemctl --user daemon-reload
# start the daemon
systemctl --user start dropbox.service
# start the daemon on login
systemctl --user enable dropbox.service
# inspect the status of the daemon
systemctl --user status dropbox.service
Conclusion
In this article, we discussed how to apply the UNIX philosophy and use a set of free open source tools to replace the proprietary and outdated Dropbox client. We applied
rclone
and entr
. I also showed how to make this process a daemon and control it with help systemd
. I want to remind you that the key idea is simplicity. We want simple solutions for simple tasks. My use of Dropbox is very simple. And this is why a single-line script is better than using an unnecessarily functional and proprietary cloud client.
Thanks so much for reading! I really hope that you enjoy this post. If you know the best way to do the same or expand the script for another use case - let us know in the comments!