Intended for linux users who have emacs always open.
Synchronizing important files on two or more computers using
emacs
+ GNUmake
,- some sort of a cloud that can be mounted to a directory, for example, an a. ssh-server, or b. some public cloud service (e.g., Russian Yandex Disk or Swiss pCloud) that can be mounted in linux using standard open-source utilities, and
- symmetric encryption
a. using ImageMagick for
JPEG
andPNG
images or b. using gpg for other (presumably text) files.
Encrypted files saved in the cloud have random names to minimize the amount of information cloud owners can extract by monitoring our cloud directory.
We need
emacs
, GNUmake
,ImageMagick
,gpg
,sed
, andgawk
; in Debian these can be installed as follows:
aptitude install emacs make imagemagick gpg sed gawk
- lisp-goodies: start.el (used by Makefile), and shalaev.el
- (for testing only) el-debug.el
I am running emacs
in daemon mode (in text console) using the following line in ~/.login:
emacs --daemon
Once emacs
was started in the daemon mode, I can use emacsclient -c
to open a new (gui) emacs window.
-
mkdir ~/.emacs.d/local-packages/
. -
Place shalaev.el and cloud.el to
~/.emacs.d/local-packages/
-
Evaluate
cloud.el
inemacs
at start by placing the following lines(require 'cloud) (cloud-start)
into your ~/.emacs file. In emacs, update some of the files , then
M-x cloud-sync
. During the very first(cloud-start)
run, configuration file ~/.emacs.d/cloud/`hostname`/config will be created. -
Mount remote directory. The mounting point may be arbitrary (specified as
cloud-directory
in ~/.emacs.d/cloud/`hostname`/config), the default one is/mnt/cloud/
.
There are several log files; the least informative one is ~/.emacs.d/cloud/`hostname`/log
described in files.org.
- Edit a text file in emacs. Unless it is blacklisted it will automatically be clouded when you save it. (Blacklisted files can be manually clouded using
M-x cloud-add
.) - Run
M-x cloud-sync
to upload the file andtail -f ~/.emacs.d/cloud/`hostname`/log
to see the log. - Now you can move to another host (e.g. from your office desktop to your laptop).
- Using some secure way, copy ~/.emacs.d/cloud/`hostname`/config to another host; launch
cloud.el
there and check the log files. Ensure that updated on your previous host files were downloaded to your current host. - Let me know if something is unclear or does not work.
Every time we M-x cloud-sync
, local files get synchronized with the cloud.
(The same happens when we start/quit emacs.)
For this purpose I have a line in my crontab
:
43 9-21 * * * emacsclient -e "(cloud-sync)" &> /dev/null
Except for M-x cloud-sync
, commands are barely used:
M-x cloud-add
adds one or several files to the list of "clouded" files. This means thatM-x cloud-sync
command will upload these "clouded" files to the remote server if they are updated. Supposed to be used in dired buffer for several (marked) files, or (when no files are marked) for a single file. Files edited in emacs are clouded automatically, but there are exceptions – see sample configuration file and the source code. Works both on files and directories.M-x cloud-forget
is the opposite ofM-x cloud-add
. It is also called automatically when files are removed in dired buffer. Currently works on files only, not on directories.M-x cloud-sync
syncronizes local files with the cloud. Could be regularly called with acrontab
line, e.g.,
43 9-21 * * * emacsclient -e "(cloud-sync)" &> /dev/null
- I use GNU make together with its
--jobs
option to enjoy (unsupported in emacs) multi-threading, and thus I have to suffer from the make restriction: only nicely named files will work.
In particular, no spaces in file names are allowed. (This limitation can probably be circumvented by creating soft links to badly named files.) - Encrypting images is just a toy feature for now; it has to be better developed to become really useful. After encrypting an image file and then decrypting it back, we get the same, but not identical picture (file size is changed).
This code is released under MIT license.