POSTS

Using lsyncd for Continuous Data Protection

The lsyncd program is a simple program which will synchronize your local file system with a remote version.

Setup

Basically you install lsyncd, create a simple configuration file like the one below in ~/.config/lsyncd.conf or wherever you would like to store config files, and then start lsyncd via something like

lsyncd ~/.config/lsyncd.conf

After that, lsyncd should continually reflect changes in your source directory to your target.

Configuration file

Below is an example configuration file:

-- lsyncd configuration file
-- Text after a double hyphen (--) are comments ignored by lsyncd

settings {
   logfile    = "/tmp/lsyncd.log",
   statusFile = "/tmp/lsyncd.status",
--
-- Running with nodaemon = false (i.e., as a daemon) has lsyncd in
-- the background so that it will restart on most errors. This is
-- generally more robust. But you can set this to true if you want
-- to see messages in the foreground.
-- You can find the process id to kill via 'pgrep lsyncd' if desired
   nodaemon   = false,
}

sync {
    default.direct,
    source  = "DIRECTORY_TO_BACKUP",
    target  = "PLACE_TO_BACKUP_TO",
-- Beware: elements of excludeFrom must be relative to source path above.
    excludeFrom = "PATH_TO_EXCLUDE_FILE"
}

You should replace the following in the above file with your own parameters:

  • DIRECTORY_TO_BACKUP
    • This is the path to the directory you want to backup. For example, it could be something like /home/me if your username is me.
  • PLACE_TO_BACKUP_TO
    • This is the directory you want the backup saved to. For example, it could be something like /mnt/external/backups.
  • PATH_TO_EXCLUDE_FILE
    • Path to a text file with patterns to exclude. These patterns must be relative to DIRECTORY_TO_BACKUP. For example, if you put .cache in your exclude file then you would not backup the .cache directory.

Additional Ideas

Once you are comfortable Using rclone for remote storage, you can setup lsyncd for continuous data protection into an rclone_mount which does things like:

  • connect you to a cloud storage system like Dropbox, pCloud, or Google Drive
  • use rclone crypt to encrypt your data before it goes into the cloud

The end result is a relatively configurable, cheap, robust system to continuously backup your data into an encrypted cloud storage system.