You can simply choose from a set of three default implementations which are: rsync, rsyncssh and direct.
To sync a local directory using the default rsync behavior, just add this to a config file:
The order of the arguments is of no importance. If target is a local directory, take care that it is an absolute pathname. You can add multiple syncs that way. The source directories may be identical or differ without problems. source
is an universal parameter that must be given for every sync. All other sync
parameters can differ depending on the behavior selected. Optionally you can override the default or settings values maxDelays
or maxProcesses
per Sync.
One can also skip the initial rsync process by setting the default init
function to false:
This is an optimization which can be dangerous; so, please use it only if you are sure that source and target are synchronized when Lsyncd is started.
The default behaviors you can select from are following:
Following settings are shared between all defaults:
Name | Description |
---|---|
source | Source directory |
crontab | See section Periodic Full-Sync |
The default rsync configuration will aggregate events up to delay
seconds or 1000 separate uncollapsible events, which ever happens first. Then it will spawn one Rsync with a filter of all files that changed. The filter list is transmitted to Rsync trough a pipe. A call from Lsyncd to Rsync will thus look like this:
You can change the options Rsync is called and the Rsync binary that is call with the rsync
parameter.
Example:
Additional settings:
Name | Description |
---|---|
batchSizeLimit | Files larger then this limit should not be batched into on transfer. Only makes sense with processes > 1 which prevents rsyncssh |
Below is a table of options for the rsync
parameter. Please have a look at the Rsync documentation for an in depth explanation.
parameter | = | TYPE | default value | comment |
acls | = | BOOL | false | |
append | = | BOOL | false | (Lsyncd >= 2.2.0) |
append-verify | = | BOOL | false | (Lsyncd >= 2.2.0) |
archive | = | BOOL | false | |
backup | = | BOOL | false | (Lsyncd >= 2.2.0) |
backup_dir | = | DIR | false | (Lsyncd >= 2.2.0) |
binary | = | FILENAME | "/usr/bin/rsync" | Lsyncd calls this binary as rsync |
checksum | = | BOOL | false | |
chmod | = | STRING | (Lsyncd >= 2.2.0) | |
chown | = | USER:GROUP | (Lsyncd >= 2.2.0) | |
compress | = | BOOL | false | |
copy_dirlinks | = | BOOL | false | (Lsyncd >= 2.2.0) |
copy_links | = | BOOL | false | |
cvs_exclude | = | BOOL | ||
dry_run | = | BOOL | false | |
exclude | = | PATTERN | TABLE of PATTERNs also allowed | |
excludeFrom | = | FILENAME | ||
executability | = | BOOL | false | |
existing | = | BOOL | false | (Lsyncd >= 2.2.0) |
filter | = | TABLE of STRINGS | (Lsyncd >= 2.2.3) | |
group | = | BOOL | false | |
groupmap | = | STRING | (Lsyncd >= 2.2.0) | |
hard_links | = | BOOL | false | |
ignore_times | = | BOOL | false | |
inplace | = | BOOL | false | (Lsyncd >= 2.1.6) |
ipv4 | = | BOOL | false | |
ipv6 | = | BOOL | false | |
links | = | BOOL | true | |
one_file_system | = | BOOL | false | |
owner | = | BOOL | false | |
password_file | = | FILENAME | (Lsyncd >= 2.1.2) | |
perms | = | BOOL | false | |
protect_args | = | BOOL | true | |
prune_empty_dirs | = | BOOL | false | |
quiet | = | BOOL | false | |
rsh | = | COMMAND | ||
rsync_path | = | PATH | (path to rsync on remote host) | |
sparse | = | BOOL | false | |
suffix | = | SUFFIX | (Lsyncd >= 2.2.0) | |
temp_dir | = | DIR | ||
times | = | BOOL | true | |
update | = | BOOL | false | |
usermap | = | STRING | (Lsyncd >= 2.2.0) | |
verbose | = | BOOL | false | |
whole_file | = | BOOL | false | |
xattrs | = | BOOL | false | |
_extra | = | TABLE of STRINGS. | If absolutely needed, additional arguments can be specified as a TABLE of STRINGS(example: { "--omit-dir-times", "--omit-link-times" }). Note that the underscore highlights this as workaround. If you need something that is not covered by the above options, please request it via a feature request on the project website. Most notably, do not add -r for recursive or -a which implies recursive, since Lsyncd will handle that by itself. Additionally do not add -R for relative, which will ruin Lsyncd <-> Rsync communication. |
This configuration differs from the standard rsync configuration in that it uses ssh commands to move files or directories locally at the target host instead of deleting and transferring again. This configuration does spawn Rsync processes like default.rsync but additionally will spawn /usr/bin/ssh HOST mv ORIGIN DESTINATION
commands.
Different to default.rsync it does not take an uniform target
parameter, but needs host
and targetdir
separated.
Rsync’s options can be changed with the rsync
parameter like in default.rsync described above.
Additional to that ssh can be configured via the ssh
parameter.
binary | = | FILENAME | Lsyncd calls this binary as ssh (default: /usr/bin/ssh) |
identityFile | = | FILE | Uses this file to identify for public key authentication. |
options | = | TABLE | A table of addition extended options to pass to ssh's -o option. |
port | = | PORT | Adds --port=PORT to the ssh call. |
_extra | = | STRING TABLE | Similar to rsync._extra this can be used as quick workaround if absolutely needed. |
Example:
Please note the comma between the rsync
parameter set and the ssh
parameter set.
Caution
If you are upgrading from 2.0.x, please notice that settings
became a function from a variable, so you MUST delete the equal sign ‘=’ between settings
and the {
.
Lsyncd will call xargs
on the remote host to handle multiple tasks in a single connection. Xargs options can be specified by the xargs parameter.
binary | = | FILENAME | Lsyncd calls this binary as xargs on the remote host (default: /usr/bin/xargs) |
delimiter | = | DELIMITER | delimiting character to separate filenames. By default the 0 character is used. Very old holds may need newline instead. |
_extra | = | STRING TABLE | By default { '-0', 'rm -rf' }. Remove the -0 if you chose newline delimiter instead. Otherwise leave it as is. |
Example:
Default.direct can be used to keep two local directories in sync with better performance than using default.rsync. Default.direct uses (just like default.rsync) rsync on startup to initially synchronize the target directory with the source directory. However, during normal operation default.direct uses /bin/cp, /bin/rm and /bin/mv to keep the synchronization. All parameters are just like default.rsync.
Example:
Two additional parameters can be specified to sync{}:
excludeFrom | = | FILENAME | loads exclusion rules from this file, on rule per line |
exclude | = | LIST | loads exclusion rules from this list of strings |
Exclusion rules are modeled after rsync’s exclusion patterns but are a bit simpler. Lsyncd supports these features:
*
matches zero or more characters that are not a slash**
matches zero or more characters, this can be slashes.Example:
By default Lsyncd will delete files on the target that are not present at the source since this is a fundamental part of the idea of keeping the target in sync with the source. However, many users requested exceptions for this, for various reasons, so all default implementations take delete
as an additional parameter.
Valid values for delete
are:
delete | = | true | Default. Lsyncd will delete on the target whatever is not in the source. At startup and what's being deleted during normal operation. |
delete | = | false | Lsyncd will not delete any files on the target. Not on startup nor on normal operation. (Overwrites are possible though) |
delete | = | 'startup' | Lsyncd will delete files on the target when it starts up but not on normal operation. |
delete | = | 'running' | Lsyncd will not delete files on the target when it starts up but will delete those that are removed during normal operation. |
New in: 2.3.0
Lsyncd is able to start and manage external programs to provide a tunnel for data transfer.
Additionally it can spawn multiple connections and load-balance connections among them. A tunnel is created through the tunnel
function.
You can then set the shell for the tunnel user to /bin/false
and configure the rsyncd server side appropriately.
Valid arguments for tunnel
are:
Argument | Description | Default | Valid values |
---|---|---|---|
mode | Mode in which the tunnel is run | command | command, pool |
command | Required Command to run | nil | Table of arguments |
parallel | How many connections to run. Only for pool mode | 1 | 1+ |
retryDelay | Seconds to wait until tunnel is restarted | 10 | Number |
readyDelay | Seconds after program start to consider tunnel up | 5 | Number |
localhost | Name of the local host variable | localhost | String |
In pool mode, lsyncd allocates a new local port which is then passed as variable to the host command.
All variables can be substituded by ^variable
syntax.
See ../../../../examples/lrsyncssh-tunnel.lua for a extended configuration.
Name | Description |
---|---|
localport | Port allocated for the selected connection |
localhost | Local hostname used. Default localhost |
Run 2 tunnel ssh processes and 4 rsync processes at the same time. Use extra transfers for all files larger 30 MB.
sync {
default.rsync,
tunnel = tunnel {
command = {"ssh", "-N", "-L", "localhost:^localport:localhost:873", "user@testmachine"},
mode = "pool",
parallel = 2,
},
source = "/data/projects",
target = "rsync://localhost:^localport/projects",
delay = 5,
batchSizeLimit = 1024 * 1024 * 30,
maxProcesses = 4
}
This example will open 2 ssh connections for port forwarding and load balance 4 parallel rsync processes in a round roubin fashion.
When a sync with a tunnel parameter is started, all events are queued until the tunnel reaches the
UP
state, which is when one successful tunnel process exists for at least readyDelay
seconds.
Dead tunnel processes are automatically restarted. When the tunnel process count drops to 0, tunnel falls back to the
CONNECTING
state. There is a retryDelay
seconds delay between each attempt to restart the tunnel.
Once the tunnel is UP, a full transfer is initiated. Subsequent transfers are then load balanced over multiple connections.
rsync
backend, since there is no way to prevent multiple transfers to the same file in a relieable way, the rsync backend only supports maxProcesses = 1
which renders pool mode useless. Since the remote side rsync daemon can prevent file trashing, the rsync backend is safe.New in: 2.3.0
It is possible to trigger a full sync command from within lsync with the crontab feature. This requires that lua-crontab is installed on the system. The crontab configuration accepts a list of crontab
patterns to which a full sync will be triggered.
sync {
...
crontab = {
-- does a full sync once a day at 3:00:01
"1 0 3 * * *",
},
...
}
Each field is seperated by " "
and can contain multiple values seperated by ,
.
FIELD | VALUES | SPECIAL CHARACTERS |
---|---|---|
Seconds | 0-59 | , - * |
Minutes | 0-59 | , - * |
Hours | 0-23 | , - * |
Day of month | 1-31 | , - * |
Month | 1-12 or JAN-DEC | , - * |
Day of week | 0-6 or SUN-SAT | , - * |