2012-02-15 19:10:50 +00:00
|
|
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-02-15 19:00:28 +00:00
|
|
|
-- default-rsync.lua
|
|
|
|
--
|
|
|
|
-- Syncs with rsync ("classic" Lsyncd)
|
|
|
|
-- A (Layer 1) configuration.
|
|
|
|
--
|
|
|
|
-- Note:
|
2012-02-15 19:10:50 +00:00
|
|
|
-- this is infact just a configuration using Layer 1 configuration
|
2012-02-15 19:00:28 +00:00
|
|
|
-- like any other. It only gets compiled into the binary by default.
|
|
|
|
-- You can simply use a modified one, by copying everything into a
|
2012-02-15 19:10:50 +00:00
|
|
|
-- config file of yours and name it differently.
|
2012-02-15 19:00:28 +00:00
|
|
|
--
|
|
|
|
-- License: GPLv2 (see COPYING) or any later version
|
|
|
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
|
|
|
--
|
2012-02-15 19:10:50 +00:00
|
|
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if not default
|
|
|
|
then
|
2012-10-05 07:41:46 +00:00
|
|
|
error( 'default not loaded' )
|
2012-10-02 05:53:13 +00:00
|
|
|
end
|
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if default.rsync
|
|
|
|
then
|
2012-10-05 07:41:46 +00:00
|
|
|
error( 'default-rsync already loaded' )
|
2012-10-02 05:53:13 +00:00
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2012-10-06 11:43:55 +00:00
|
|
|
local rsync = { }
|
2015-10-14 12:39:14 +00:00
|
|
|
|
2012-10-06 11:43:55 +00:00
|
|
|
default.rsync = rsync
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
-- uses default collect
|
|
|
|
|
|
|
|
--
|
|
|
|
-- used to ensure there aren't typos in the keys
|
|
|
|
--
|
|
|
|
rsync.checkgauge = {
|
|
|
|
|
|
|
|
-- unsets default user action handlers
|
2012-11-02 23:32:44 +00:00
|
|
|
onCreate = false,
|
|
|
|
onModify = false,
|
|
|
|
onDelete = false,
|
|
|
|
onStartup = false,
|
|
|
|
onMove = false,
|
|
|
|
|
|
|
|
delete = true,
|
|
|
|
exclude = true,
|
|
|
|
excludeFrom = true,
|
|
|
|
target = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
|
|
|
|
rsync = {
|
2012-11-09 19:15:42 +00:00
|
|
|
acls = true,
|
2016-12-05 14:47:12 +00:00
|
|
|
append = true,
|
|
|
|
append_verify = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
archive = true,
|
2016-12-05 15:38:07 +00:00
|
|
|
backup = true,
|
|
|
|
backup_dir = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
binary = true,
|
2013-06-07 09:11:42 +00:00
|
|
|
bwlimit = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
checksum = true,
|
2016-08-29 11:12:09 +00:00
|
|
|
chown = true,
|
2016-12-01 13:12:56 +00:00
|
|
|
chmod = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
compress = true,
|
2016-12-01 11:35:02 +00:00
|
|
|
copy_dirlinks = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
copy_links = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
cvs_exclude = true,
|
|
|
|
dry_run = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
executability = true,
|
2016-11-28 10:20:12 +00:00
|
|
|
existing = true,
|
2014-02-28 09:15:48 +00:00
|
|
|
group = true,
|
2016-12-05 14:25:58 +00:00
|
|
|
groupmap = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
hard_links = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
ignore_times = true,
|
2015-10-14 12:39:14 +00:00
|
|
|
inplace = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
ipv4 = true,
|
|
|
|
ipv6 = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
keep_dirlinks = true,
|
|
|
|
links = true,
|
|
|
|
one_file_system = true,
|
2016-05-04 09:25:40 +00:00
|
|
|
omit_dir_times = true,
|
|
|
|
omit_link_times = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
owner = true,
|
2012-12-06 09:02:07 +00:00
|
|
|
password_file = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
perms = true,
|
|
|
|
protect_args = true,
|
|
|
|
prune_empty_dirs = true,
|
|
|
|
quiet = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
rsh = true,
|
|
|
|
rsync_path = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
sparse = true,
|
2016-12-05 15:38:07 +00:00
|
|
|
suffix = true,
|
2012-10-23 05:23:58 +00:00
|
|
|
temp_dir = true,
|
2013-03-19 07:25:29 +00:00
|
|
|
timeout = true,
|
2014-02-28 09:15:48 +00:00
|
|
|
times = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
update = true,
|
2016-12-05 14:25:58 +00:00
|
|
|
usermap = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
verbose = true,
|
2014-02-28 09:15:48 +00:00
|
|
|
whole_file = true,
|
2012-11-09 19:15:42 +00:00
|
|
|
xattrs = true,
|
|
|
|
_extra = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Spawns rsync for a list of events
|
|
|
|
--
|
2016-05-24 03:39:10 +00:00
|
|
|
-- Exclusions are already handled by not having
|
2012-10-03 16:34:09 +00:00
|
|
|
-- events for them.
|
|
|
|
--
|
2012-10-05 07:41:46 +00:00
|
|
|
rsync.action = function( inlet )
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- gets all events ready for syncing
|
|
|
|
--
|
|
|
|
local elist = inlet.getEvents(
|
|
|
|
function(event)
|
|
|
|
return event.etype ~= 'Init' and event.etype ~= 'Blanket'
|
2012-02-15 19:00:28 +00:00
|
|
|
end
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Replaces what rsync would consider filter rules by literals
|
|
|
|
--
|
|
|
|
local function sub( p )
|
|
|
|
if not p then
|
|
|
|
return
|
2012-02-15 19:00:28 +00:00
|
|
|
end
|
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
return p:
|
2012-10-05 07:41:46 +00:00
|
|
|
gsub( '%?', '\\?' ):
|
|
|
|
gsub( '%*', '\\*' ):
|
2016-06-27 07:26:45 +00:00
|
|
|
gsub( '%[', '\\[' )
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Gets the list of paths for the event list
|
|
|
|
--
|
|
|
|
-- Deletes create multi match patterns
|
|
|
|
--
|
|
|
|
local paths = elist.getPaths(
|
|
|
|
function( etype, path1, path2 )
|
|
|
|
if string.byte( path1, -1 ) == 47 and etype == 'Delete' then
|
|
|
|
return sub( path1 )..'***', sub( path2 )
|
|
|
|
else
|
|
|
|
return sub( path1 ), sub( path2 )
|
|
|
|
end
|
2012-10-02 05:53:13 +00:00
|
|
|
end
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- stores all filters by integer index
|
|
|
|
--
|
|
|
|
local filterI = { }
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Stores all filters with path index
|
|
|
|
--
|
|
|
|
local filterP = { }
|
2012-02-15 19:00:28 +00:00
|
|
|
|
|
|
|
--
|
2012-10-03 16:34:09 +00:00
|
|
|
-- Adds one path to the filter
|
|
|
|
--
|
|
|
|
local function addToFilter( path )
|
2012-02-16 07:28:40 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
if filterP[ path ] then
|
|
|
|
return
|
2012-02-15 19:00:28 +00:00
|
|
|
end
|
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
filterP[ path ] = true
|
|
|
|
|
|
|
|
table.insert( filterI, path )
|
|
|
|
end
|
|
|
|
|
2012-02-15 19:00:28 +00:00
|
|
|
--
|
2012-10-03 16:34:09 +00:00
|
|
|
-- Adds a path to the filter.
|
|
|
|
--
|
|
|
|
-- Rsync needs to have entries for all steps in the path,
|
|
|
|
-- so the file for example d1/d2/d3/f1 needs following filters:
|
|
|
|
-- 'd1/', 'd1/d2/', 'd1/d2/d3/' and 'd1/d2/d3/f1'
|
|
|
|
--
|
|
|
|
for _, path in ipairs( paths ) do
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
if path and path ~= '' then
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
addToFilter(path)
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
local pp = string.match( path, '^(.*/)[^/]+/?' )
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
while pp do
|
|
|
|
addToFilter(pp)
|
|
|
|
pp = string.match( pp, '^(.*/)[^/]+/?' )
|
|
|
|
end
|
2012-10-02 05:53:13 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local filterS = table.concat( filterI, '\n' )
|
|
|
|
local filter0 = table.concat( filterI, '\000' )
|
|
|
|
|
|
|
|
log(
|
|
|
|
'Normal',
|
|
|
|
'Calling rsync with filter-list of new/modified files/dirs\n',
|
|
|
|
filterS
|
|
|
|
)
|
|
|
|
|
|
|
|
local config = inlet.getConfig( )
|
|
|
|
local delete = nil
|
|
|
|
|
2012-10-09 15:47:39 +00:00
|
|
|
if config.delete == true or config.delete == 'running' then
|
2012-10-03 16:34:09 +00:00
|
|
|
delete = { '--delete', '--ignore-errors' }
|
|
|
|
end
|
|
|
|
|
|
|
|
spawn(
|
|
|
|
elist,
|
|
|
|
config.rsync.binary,
|
|
|
|
'<', filter0,
|
|
|
|
config.rsync._computed,
|
|
|
|
'-r',
|
|
|
|
delete,
|
|
|
|
'--force',
|
|
|
|
'--from0',
|
|
|
|
'--include-from=-',
|
|
|
|
'--exclude=*',
|
|
|
|
config.source,
|
|
|
|
config.target
|
|
|
|
)
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Spawns the recursive startup sync
|
|
|
|
--
|
2012-10-05 07:41:46 +00:00
|
|
|
rsync.init = function(event)
|
2012-10-03 16:34:09 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
local config = event.config
|
|
|
|
local inlet = event.inlet
|
2012-10-03 16:34:09 +00:00
|
|
|
local excludes = inlet.getExcludes( )
|
2012-10-05 19:48:06 +00:00
|
|
|
local delete = nil
|
|
|
|
local target = config.target
|
|
|
|
|
2016-12-05 14:47:12 +00:00
|
|
|
if not target
|
|
|
|
then
|
|
|
|
if not config.host
|
|
|
|
then
|
2012-10-05 19:48:06 +00:00
|
|
|
error('Internal fail, Neither target nor host is configured')
|
|
|
|
end
|
|
|
|
|
|
|
|
target = config.host .. ':' .. config.targetdir
|
|
|
|
end
|
2012-10-03 16:34:09 +00:00
|
|
|
|
2016-12-05 14:47:12 +00:00
|
|
|
if config.delete == true or config.delete == 'startup'
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
delete = { '--delete', '--ignore-errors' }
|
|
|
|
end
|
|
|
|
|
2016-12-05 14:47:12 +00:00
|
|
|
if #excludes == 0
|
|
|
|
then
|
|
|
|
-- starts rsync without any excludes
|
2012-10-03 16:34:09 +00:00
|
|
|
log(
|
|
|
|
'Normal',
|
|
|
|
'recursive startup rsync: ',
|
|
|
|
config.source,
|
|
|
|
' -> ',
|
2012-10-05 19:48:06 +00:00
|
|
|
target
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
spawn(
|
|
|
|
event,
|
|
|
|
config.rsync.binary,
|
|
|
|
delete,
|
|
|
|
config.rsync._computed,
|
|
|
|
'-r',
|
|
|
|
config.source,
|
2012-10-05 19:48:06 +00:00
|
|
|
target
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
else
|
2016-12-05 14:47:12 +00:00
|
|
|
-- starts rsync providing an exclusion list
|
2012-10-03 16:34:09 +00:00
|
|
|
-- on stdin
|
|
|
|
local exS = table.concat( excludes, '\n' )
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
log(
|
|
|
|
'Normal',
|
|
|
|
'recursive startup rsync: ',
|
|
|
|
config.source,
|
|
|
|
' -> ',
|
2012-10-05 19:48:06 +00:00
|
|
|
target,
|
2012-10-03 16:34:09 +00:00
|
|
|
' excluding\n',
|
|
|
|
exS
|
|
|
|
)
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
spawn(
|
|
|
|
event,
|
|
|
|
config.rsync.binary,
|
|
|
|
'<', exS,
|
|
|
|
'--exclude-from=-',
|
|
|
|
delete,
|
|
|
|
config.rsync._computed,
|
|
|
|
'-r',
|
|
|
|
config.source,
|
2012-10-05 19:48:06 +00:00
|
|
|
target
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Prepares and checks a syncs configuration on startup.
|
|
|
|
--
|
2015-10-14 12:39:14 +00:00
|
|
|
rsync.prepare =
|
|
|
|
function(
|
|
|
|
config, -- the configuration
|
|
|
|
level, -- additional error level for inherited use ( by rsyncssh )
|
|
|
|
skipTarget -- used by rsyncssh, do not check for target
|
|
|
|
)
|
2012-10-05 19:48:06 +00:00
|
|
|
|
|
|
|
-- First let default.prepare test the checkgauge
|
|
|
|
default.prepare( config, level + 6 )
|
2012-10-02 06:25:46 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if not skipTarget and not config.target
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
error(
|
|
|
|
'default.rsync needs "target" configured',
|
2012-10-05 19:48:06 +00:00
|
|
|
level
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
|
|
|
end
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if config.rsyncOps
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
error(
|
|
|
|
'"rsyncOps" is outdated please use the new rsync = { ... } syntax.',
|
2012-10-05 19:48:06 +00:00
|
|
|
level
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if config.rsyncOpts and config.rsync._extra
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
error(
|
|
|
|
'"rsyncOpts" is outdated in favor of the new rsync = { ... } syntax\n"' +
|
|
|
|
'for which you provided the _extra attribute as well.\n"' +
|
|
|
|
'Please remove rsyncOpts from your config.',
|
2012-10-05 19:48:06 +00:00
|
|
|
level
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
|
|
|
end
|
2012-10-02 06:25:46 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if config.rsyncOpts
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
log(
|
|
|
|
'Warn',
|
|
|
|
'"rsyncOpts" is outdated. Please use the new rsync = { ... } syntax."'
|
|
|
|
)
|
2012-10-02 05:53:13 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
config.rsync._extra = config.rsyncOpts
|
|
|
|
config.rsyncOpts = nil
|
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if config.rsyncBinary and config.rsync.binary
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
error(
|
|
|
|
'"rsyncBinary is outdated in favor of the new rsync = { ... } syntax\n"'+
|
|
|
|
'for which you provided the binary attribute as well.\n"' +
|
|
|
|
"Please remove rsyncBinary from your config.'",
|
2012-10-05 19:48:06 +00:00
|
|
|
level
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if config.rsyncBinary
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
log(
|
|
|
|
'Warn',
|
|
|
|
'"rsyncBinary" is outdated. Please use the new rsync = { ... } syntax."'
|
|
|
|
)
|
2012-02-16 07:28:40 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
config.rsync.binary = config.rsyncBinary
|
|
|
|
config.rsyncOpts = nil
|
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
-- checks if the _computed argument exists already
|
2015-10-14 12:39:14 +00:00
|
|
|
if config.rsync._computed
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
error(
|
|
|
|
'please do not use the internal rsync._computed parameter',
|
2012-10-05 19:48:06 +00:00
|
|
|
level
|
2012-10-03 16:34:09 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- computes the rsync arguments into one list
|
2012-10-06 12:22:08 +00:00
|
|
|
local crsync = config.rsync;
|
|
|
|
|
|
|
|
-- everything implied by archive = true
|
|
|
|
local archiveFlags = {
|
|
|
|
recursive = true,
|
|
|
|
links = true,
|
|
|
|
perms = true,
|
|
|
|
times = true,
|
|
|
|
group = true,
|
|
|
|
owner = true,
|
|
|
|
devices = true,
|
|
|
|
specials = true,
|
|
|
|
hard_links = false,
|
|
|
|
acls = false,
|
|
|
|
xattrs = false,
|
|
|
|
}
|
2012-10-05 19:48:06 +00:00
|
|
|
|
2014-02-28 09:15:48 +00:00
|
|
|
-- if archive is given the implications are filled in
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.archive
|
|
|
|
then
|
|
|
|
for k, v in pairs( archiveFlags )
|
|
|
|
do
|
|
|
|
if crsync[ k ] == nil
|
|
|
|
then
|
2012-10-06 12:22:08 +00:00
|
|
|
crsync[ k ] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
crsync._computed = { true }
|
2016-12-05 14:25:58 +00:00
|
|
|
|
2012-10-06 12:22:08 +00:00
|
|
|
local computed = crsync._computed
|
2016-12-05 14:25:58 +00:00
|
|
|
|
2012-10-30 08:57:54 +00:00
|
|
|
local computedN = 2
|
2012-10-05 19:48:06 +00:00
|
|
|
|
|
|
|
local shortFlags = {
|
2012-11-09 19:15:42 +00:00
|
|
|
acls = 'A',
|
2016-12-05 15:38:07 +00:00
|
|
|
backup = 'b',
|
2012-10-05 19:48:06 +00:00
|
|
|
checksum = 'c',
|
2012-11-09 19:15:42 +00:00
|
|
|
compress = 'z',
|
2016-12-01 11:35:02 +00:00
|
|
|
copy_dirlinks = 'k',
|
2012-10-05 19:48:06 +00:00
|
|
|
copy_links = 'L',
|
2012-11-09 19:15:42 +00:00
|
|
|
cvs_exclude = 'C',
|
|
|
|
dry_run = 'n',
|
2012-10-05 19:48:06 +00:00
|
|
|
executability = 'E',
|
2014-02-28 09:15:48 +00:00
|
|
|
group = 'g',
|
2012-11-09 19:15:42 +00:00
|
|
|
hard_links = 'H',
|
2012-10-05 19:48:06 +00:00
|
|
|
ignore_times = 'I',
|
|
|
|
ipv4 = '4',
|
2012-11-09 19:15:42 +00:00
|
|
|
ipv6 = '6',
|
|
|
|
keep_dirlinks = 'K',
|
|
|
|
links = 'l',
|
|
|
|
one_file_system = 'x',
|
2016-05-04 09:25:40 +00:00
|
|
|
omit_dir_times = 'O',
|
|
|
|
omit_link_times = 'J',
|
2012-11-09 19:15:42 +00:00
|
|
|
owner = 'o',
|
|
|
|
perms = 'p',
|
|
|
|
protect_args = 's',
|
|
|
|
prune_empty_dirs = 'm',
|
|
|
|
quiet = 'q',
|
|
|
|
sparse = 'S',
|
2014-02-28 09:15:48 +00:00
|
|
|
times = 't',
|
2012-11-09 19:15:42 +00:00
|
|
|
update = 'u',
|
|
|
|
verbose = 'v',
|
2014-02-28 09:15:48 +00:00
|
|
|
whole_file = 'W',
|
2012-11-09 19:15:42 +00:00
|
|
|
xattrs = 'X',
|
2012-10-05 19:48:06 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
local shorts = { '-' }
|
2012-10-05 19:48:06 +00:00
|
|
|
local shortsN = 2
|
2012-10-03 16:34:09 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync._extra
|
|
|
|
then
|
|
|
|
for k, v in ipairs( crsync._extra )
|
|
|
|
do
|
2012-10-05 19:48:06 +00:00
|
|
|
computed[ computedN ] = v
|
|
|
|
computedN = computedN + 1
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
for k, flag in pairs( shortFlags )
|
|
|
|
do
|
|
|
|
if crsync[ k ]
|
|
|
|
then
|
2012-10-05 19:48:06 +00:00
|
|
|
shorts[ shortsN ] = flag
|
|
|
|
shortsN = shortsN + 1
|
|
|
|
end
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.devices and crsync.specials
|
|
|
|
then
|
2012-10-06 12:22:08 +00:00
|
|
|
shorts[ shortsN ] = 'D'
|
|
|
|
shortsN = shortsN + 1
|
|
|
|
else
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.devices
|
|
|
|
then
|
2012-10-06 12:22:08 +00:00
|
|
|
computed[ computedN ] = '--devices'
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.specials
|
|
|
|
then
|
2012-10-06 12:22:08 +00:00
|
|
|
computed[ computedN ] = '--specials'
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
end
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-12-05 14:47:12 +00:00
|
|
|
if crsync.append
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--append'
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if crsync.append_verify
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--append-verify'
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2016-12-05 15:38:07 +00:00
|
|
|
|
|
|
|
if crsync.backup_dir
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--backup-dir=' .. crsync.backup_dir
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2016-12-05 14:47:12 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.bwlimit
|
|
|
|
then
|
2013-06-07 09:11:42 +00:00
|
|
|
computed[ computedN ] = '--bwlimit=' .. crsync.bwlimit
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2012-10-06 12:22:08 +00:00
|
|
|
|
2016-12-01 13:12:56 +00:00
|
|
|
if crsync.chmod
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--chmod=' .. crsync.chmod
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
2016-08-29 11:12:09 +00:00
|
|
|
if crsync.chown
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--chown=' .. crsync.chown
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2016-11-28 10:20:12 +00:00
|
|
|
|
2016-12-05 14:25:58 +00:00
|
|
|
if crsync.groupmap
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--groupmap=' .. crsync.groupmap
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
2016-11-28 10:20:12 +00:00
|
|
|
if crsync.existing
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--existing'
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2016-08-29 11:12:09 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.inplace
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--inplace'
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if crsync.password_file
|
|
|
|
then
|
2012-10-30 08:57:54 +00:00
|
|
|
computed[ computedN ] = '--password-file=' .. crsync.password_file
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.rsh
|
|
|
|
then
|
2012-10-30 08:57:54 +00:00
|
|
|
computed[ computedN ] = '--rsh=' .. crsync.rsh
|
2012-10-05 19:48:06 +00:00
|
|
|
computedN = computedN + 1
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.rsync_path
|
|
|
|
then
|
2012-10-30 08:57:54 +00:00
|
|
|
computed[ computedN ] = '--rsync-path=' .. crsync.rsync_path
|
2012-10-05 19:48:06 +00:00
|
|
|
computedN = computedN + 1
|
2012-10-03 16:34:09 +00:00
|
|
|
end
|
|
|
|
|
2016-12-05 15:38:07 +00:00
|
|
|
if crsync.suffix
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--suffix=' .. crsync.suffix
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.temp_dir
|
|
|
|
then
|
2012-10-30 08:57:54 +00:00
|
|
|
computed[ computedN ] = '--temp-dir=' .. crsync.temp_dir
|
2012-10-23 05:23:58 +00:00
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if crsync.timeout
|
|
|
|
then
|
2013-03-19 07:25:29 +00:00
|
|
|
computed[ computedN ] = '--timeout=' .. crsync.timeout
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2016-12-05 14:25:58 +00:00
|
|
|
|
|
|
|
if crsync.usermap
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '--usermap=' .. crsync.usermap
|
|
|
|
computedN = computedN + 1
|
|
|
|
end
|
2013-03-19 07:25:29 +00:00
|
|
|
|
2015-10-14 12:39:14 +00:00
|
|
|
if shortsN ~= 2
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
computed[ 1 ] = table.concat( shorts, '' )
|
|
|
|
else
|
|
|
|
computed[ 1 ] = { }
|
|
|
|
end
|
|
|
|
|
|
|
|
-- appends a / to target if not present
|
2015-10-14 12:39:14 +00:00
|
|
|
if not skipTarget and string.sub(config.target, -1) ~= '/'
|
|
|
|
then
|
2012-10-03 16:34:09 +00:00
|
|
|
config.target = config.target..'/'
|
|
|
|
end
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
end
|
2012-10-03 16:34:09 +00:00
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- By default do deletes.
|
|
|
|
--
|
2012-10-05 07:41:46 +00:00
|
|
|
rsync.delete = true
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- Rsyncd exitcodes
|
|
|
|
--
|
|
|
|
rsync.exitcodes = default.rsyncExitCodes
|
2012-10-03 16:34:09 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Calls rsync with this default options
|
|
|
|
--
|
2015-10-14 12:39:14 +00:00
|
|
|
rsync.rsync =
|
|
|
|
{
|
2012-10-03 16:34:09 +00:00
|
|
|
-- The rsync binary to be called.
|
2012-10-05 19:48:06 +00:00
|
|
|
binary = '/usr/bin/rsync',
|
|
|
|
links = true,
|
|
|
|
times = true,
|
|
|
|
protect_args = true
|
2012-02-15 19:00:28 +00:00
|
|
|
}
|
2012-10-03 16:34:09 +00:00
|
|
|
|
2012-10-05 07:41:46 +00:00
|
|
|
|
2012-10-03 16:34:09 +00:00
|
|
|
--
|
|
|
|
-- Default delay
|
|
|
|
--
|
2012-10-05 07:41:46 +00:00
|
|
|
rsync.delay = 15
|