2012-08-25 11:45:50 +00:00
|
|
|
--
|
2012-02-15 19:00:28 +00:00
|
|
|
-- default-rsyncssh.lua
|
|
|
|
--
|
|
|
|
-- Improved rsync - sync with rsync, but moves and deletes executed over ssh.
|
|
|
|
-- 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-08-25 11:45:50 +00:00
|
|
|
--
|
|
|
|
|
2016-12-01 13:12:56 +00:00
|
|
|
if not default
|
|
|
|
then
|
2012-10-05 19:48:06 +00:00
|
|
|
error( 'default not loaded' );
|
2012-08-25 11:45:50 +00:00
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2016-12-01 13:12:56 +00:00
|
|
|
if not default.rsync
|
|
|
|
then
|
2012-10-05 19:48:06 +00:00
|
|
|
error( 'default.rsync not loaded' );
|
2012-08-25 11:45:50 +00:00
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2016-12-01 13:12:56 +00:00
|
|
|
if default.rsyncssh
|
|
|
|
then
|
2012-10-05 19:48:06 +00:00
|
|
|
error( 'default-rsyncssh already loaded' );
|
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- rsyncssh extends default.rsync
|
|
|
|
--
|
|
|
|
local rsyncssh = { default.rsync }
|
2016-12-01 13:12:56 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
default.rsyncssh = rsyncssh
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- used to ensure there aren't typos in the keys
|
|
|
|
--
|
|
|
|
rsyncssh.checkgauge = {
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
-- unsets the inherited value of from default.rsync
|
2012-10-06 12:22:08 +00:00
|
|
|
target = false,
|
|
|
|
onMove = true,
|
2012-02-16 07:28:40 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
-- rsyncssh users host and targetdir
|
2012-10-06 12:22:08 +00:00
|
|
|
host = true,
|
|
|
|
targetdir = true,
|
|
|
|
sshExitCodes = true,
|
|
|
|
rsyncExitCodes = true,
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
-- ssh settings
|
|
|
|
ssh = {
|
2013-07-30 09:16:29 +00:00
|
|
|
binary = true,
|
|
|
|
identityFile = true,
|
|
|
|
options = true,
|
|
|
|
port = true,
|
2012-10-05 19:48:06 +00:00
|
|
|
},
|
|
|
|
}
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2017-01-03 14:30:13 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Returns true for non Init, Blanket and Move events.
|
|
|
|
--
|
|
|
|
local eventNotInitBlankMove =
|
|
|
|
function
|
|
|
|
(
|
|
|
|
event
|
|
|
|
)
|
|
|
|
-- TODO use a table
|
|
|
|
if event.etype == 'Move'
|
|
|
|
or event.etype == 'Init'
|
|
|
|
or event.etype == 'Blanket'
|
|
|
|
then
|
|
|
|
return 'break'
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Replaces what rsync would consider filter rules by literals.
|
|
|
|
--
|
|
|
|
local replaceRsyncFilter =
|
|
|
|
function
|
|
|
|
(
|
|
|
|
path
|
|
|
|
)
|
2018-02-27 09:09:28 +00:00
|
|
|
if not path then return end
|
2017-01-03 14:30:13 +00:00
|
|
|
|
|
|
|
return(
|
|
|
|
path
|
|
|
|
:gsub( '%?', '\\?' )
|
|
|
|
:gsub( '%*', '\\*' )
|
|
|
|
:gsub( '%[', '\\[' )
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- Spawns rsync for a list of events
|
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
rsyncssh.action = function
|
|
|
|
(
|
|
|
|
inlet
|
|
|
|
)
|
2013-07-30 09:16:29 +00:00
|
|
|
local config = inlet.getConfig( )
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2017-01-03 14:30:13 +00:00
|
|
|
local event, event2 = inlet.getEvent( )
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
-- makes move local on target host
|
|
|
|
-- if the move fails, it deletes the source
|
2016-12-14 07:45:33 +00:00
|
|
|
if event.etype == 'Move'
|
|
|
|
then
|
2014-11-25 22:49:25 +00:00
|
|
|
local path1 = config.targetdir .. event.path
|
2016-12-14 07:45:33 +00:00
|
|
|
|
2014-11-25 22:49:25 +00:00
|
|
|
local path2 = config.targetdir .. event2.path
|
2016-12-14 07:45:33 +00:00
|
|
|
|
2014-11-25 22:49:25 +00:00
|
|
|
path1 = "'" .. path1:gsub ('\'', '\'"\'"\'') .. "'"
|
|
|
|
path2 = "'" .. path2:gsub ('\'', '\'"\'"\'') .. "'"
|
2013-07-30 09:16:29 +00:00
|
|
|
|
|
|
|
log(
|
|
|
|
'Normal',
|
|
|
|
'Moving ',
|
|
|
|
event.path,
|
|
|
|
' -> ',
|
|
|
|
event2.path
|
|
|
|
)
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
spawn(
|
|
|
|
event,
|
|
|
|
config.ssh.binary,
|
2012-10-08 06:06:34 +00:00
|
|
|
config.ssh._computed,
|
2012-10-05 19:48:06 +00:00
|
|
|
config.host,
|
|
|
|
'mv',
|
2014-11-25 22:49:25 +00:00
|
|
|
path1,
|
|
|
|
path2,
|
2012-10-05 19:48:06 +00:00
|
|
|
'||', 'rm', '-rf',
|
2014-11-25 22:49:25 +00:00
|
|
|
path1
|
2013-07-30 09:16:29 +00:00
|
|
|
)
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-01-03 14:30:13 +00:00
|
|
|
-- otherwise a rsync is spawned
|
|
|
|
local elist = inlet.getEvents( eventNotInitBlankMove )
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2017-01-03 14:30:13 +00:00
|
|
|
-- gets the list of paths for the event list
|
|
|
|
-- deletes create multi match patterns
|
2017-01-05 09:22:00 +00:00
|
|
|
local paths = elist.getPaths( )
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2017-02-16 11:17:37 +00:00
|
|
|
--
|
|
|
|
-- Replaces what rsync would consider filter rules by literals
|
|
|
|
--
|
|
|
|
local function sub( p )
|
2018-02-27 09:09:28 +00:00
|
|
|
if not p then return end
|
2017-02-16 11:17:37 +00:00
|
|
|
|
|
|
|
return p:
|
|
|
|
gsub( '%?', '\\?' ):
|
|
|
|
gsub( '%*', '\\*' ):
|
|
|
|
gsub( '%[', '\\[' ):
|
|
|
|
gsub( '%]', '\\]' )
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- 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
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
-- stores all filters by integer index
|
|
|
|
local filterI = { }
|
|
|
|
|
|
|
|
-- stores all filters with path index
|
|
|
|
local filterP = { }
|
|
|
|
|
|
|
|
-- adds one path to the filter
|
|
|
|
local function addToFilter( path )
|
2018-02-27 09:09:28 +00:00
|
|
|
if filterP[ path ] then return end
|
2017-02-16 11:17:37 +00:00
|
|
|
|
|
|
|
filterP[ path ] = true
|
|
|
|
|
|
|
|
table.insert( filterI, path )
|
|
|
|
end
|
|
|
|
|
|
|
|
-- 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 )
|
2017-01-05 10:31:29 +00:00
|
|
|
do
|
2017-02-16 11:17:37 +00:00
|
|
|
if path and path ~= ''
|
2017-01-05 10:31:29 +00:00
|
|
|
then
|
2017-02-16 11:17:37 +00:00
|
|
|
addToFilter(path)
|
|
|
|
|
|
|
|
local pp = string.match( path, '^(.*/)[^/]+/?' )
|
|
|
|
|
|
|
|
while pp
|
|
|
|
do
|
|
|
|
addToFilter(pp)
|
|
|
|
pp = string.match( pp, '^(.*/)[^/]+/?' )
|
|
|
|
end
|
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
end
|
2017-02-16 11:17:37 +00:00
|
|
|
|
2017-01-05 10:31:29 +00:00
|
|
|
end
|
|
|
|
|
2013-07-30 09:16:29 +00:00
|
|
|
log(
|
|
|
|
'Normal',
|
2017-02-16 11:17:37 +00:00
|
|
|
'Calling rsync with filter-list of new/modified files/dirs\n',
|
|
|
|
table.concat( filterI, '\n' )
|
2013-07-30 09:16:29 +00:00
|
|
|
)
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2017-02-16 11:17:37 +00:00
|
|
|
local config = inlet.getConfig( )
|
|
|
|
|
2017-01-03 14:30:13 +00:00
|
|
|
local delete = nil
|
|
|
|
|
2017-02-16 11:17:37 +00:00
|
|
|
if config.delete == true or config.delete == 'running'
|
2017-01-03 14:30:13 +00:00
|
|
|
then
|
2017-02-16 11:17:37 +00:00
|
|
|
delete = { '--delete', '--ignore-errors' }
|
2017-01-03 14:30:13 +00:00
|
|
|
end
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
spawn(
|
|
|
|
elist,
|
|
|
|
config.rsync.binary,
|
2017-02-16 11:17:37 +00:00
|
|
|
'<', table.concat( filterI, '\000' ),
|
2012-10-05 19:48:06 +00:00
|
|
|
config.rsync._computed,
|
2017-02-16 11:17:37 +00:00
|
|
|
'-r',
|
2017-01-03 14:30:13 +00:00
|
|
|
delete,
|
|
|
|
'--force',
|
2012-10-05 19:48:06 +00:00
|
|
|
'--from0',
|
2017-02-16 11:17:37 +00:00
|
|
|
'--include-from=-',
|
|
|
|
'--exclude=*',
|
2012-10-05 19:48:06 +00:00
|
|
|
config.source,
|
|
|
|
config.host .. ':' .. config.targetdir
|
|
|
|
)
|
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2017-02-16 11:17:37 +00:00
|
|
|
|
|
|
|
----
|
|
|
|
---- NOTE: This optimized version can be used once
|
|
|
|
---- https://bugzilla.samba.org/show_bug.cgi?id=12569
|
|
|
|
---- is fixed.
|
|
|
|
----
|
|
|
|
--
|
|
|
|
-- Spawns rsync for a list of events
|
|
|
|
--
|
|
|
|
--rsyncssh.action = function
|
|
|
|
--(
|
|
|
|
-- inlet
|
|
|
|
--)
|
|
|
|
-- local config = inlet.getConfig( )
|
|
|
|
--
|
|
|
|
-- local event, event2 = inlet.getEvent( )
|
|
|
|
--
|
|
|
|
-- -- makes move local on target host
|
|
|
|
-- -- if the move fails, it deletes the source
|
|
|
|
-- if event.etype == 'Move'
|
|
|
|
-- then
|
|
|
|
-- local path1 = config.targetdir .. event.path
|
|
|
|
--
|
|
|
|
-- local path2 = config.targetdir .. event2.path
|
|
|
|
--
|
|
|
|
-- path1 = "'" .. path1:gsub ('\'', '\'"\'"\'') .. "'"
|
|
|
|
-- path2 = "'" .. path2:gsub ('\'', '\'"\'"\'') .. "'"
|
|
|
|
--
|
|
|
|
-- log(
|
|
|
|
-- 'Normal',
|
|
|
|
-- 'Moving ',
|
|
|
|
-- event.path,
|
|
|
|
-- ' -> ',
|
|
|
|
-- event2.path
|
|
|
|
-- )
|
|
|
|
--
|
|
|
|
-- spawn(
|
|
|
|
-- event,
|
|
|
|
-- config.ssh.binary,
|
|
|
|
-- config.ssh._computed,
|
|
|
|
-- config.host,
|
|
|
|
-- 'mv',
|
|
|
|
-- path1,
|
|
|
|
-- path2,
|
|
|
|
-- '||', 'rm', '-rf',
|
|
|
|
-- path1
|
|
|
|
-- )
|
|
|
|
--
|
|
|
|
-- return
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- -- otherwise a rsync is spawned
|
|
|
|
-- local elist = inlet.getEvents( eventNotInitBlankMove )
|
|
|
|
--
|
|
|
|
-- -- gets the list of paths for the event list
|
|
|
|
-- -- deletes create multi match patterns
|
|
|
|
-- local paths = elist.getPaths( )
|
|
|
|
--
|
|
|
|
-- -- removes trailing slashes from dirs.
|
|
|
|
-- for k, v in ipairs( paths )
|
|
|
|
-- do
|
|
|
|
-- if string.byte( v, -1 ) == 47
|
|
|
|
-- then
|
|
|
|
-- paths[ k ] = string.sub( v, 1, -2 )
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- log(
|
|
|
|
-- 'Normal',
|
|
|
|
-- 'Rsyncing list\n',
|
|
|
|
-- table.concat( paths, '\n' )
|
|
|
|
-- )
|
|
|
|
--
|
|
|
|
-- local delete = nil
|
|
|
|
--
|
|
|
|
-- if config.delete == true
|
|
|
|
-- or config.delete == 'running'
|
|
|
|
-- then
|
|
|
|
-- delete = { '--delete-missing-args', '--ignore-errors' }
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- spawn(
|
|
|
|
-- elist,
|
|
|
|
-- config.rsync.binary,
|
|
|
|
-- '<', table.concat( paths, '\000' ),
|
|
|
|
-- config.rsync._computed,
|
|
|
|
-- delete,
|
|
|
|
-- '--force',
|
|
|
|
-- '--from0',
|
|
|
|
-- '--files-from=-',
|
|
|
|
-- config.source,
|
|
|
|
-- config.host .. ':' .. config.targetdir
|
|
|
|
-- )
|
|
|
|
--end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
2012-10-05 19:48:06 +00:00
|
|
|
-- Called when collecting a finished child process
|
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
rsyncssh.collect = function
|
|
|
|
(
|
|
|
|
agent,
|
|
|
|
exitcode
|
|
|
|
)
|
2012-10-05 19:48:06 +00:00
|
|
|
local config = agent.config
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2016-12-14 07:45:33 +00:00
|
|
|
if not agent.isList and agent.etype == 'Init'
|
|
|
|
then
|
2012-10-05 19:48:06 +00:00
|
|
|
local rc = config.rsyncExitCodes[exitcode]
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2016-12-14 07:45:33 +00:00
|
|
|
if rc == 'ok'
|
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
log( 'Normal', 'Startup of "', agent.source, '" finished: ', exitcode )
|
2016-12-14 07:45:33 +00:00
|
|
|
elseif rc == 'again'
|
|
|
|
then
|
|
|
|
if settings('insist')
|
|
|
|
then
|
2017-01-03 12:08:48 +00:00
|
|
|
log( 'Normal', 'Retrying startup of "', agent.source, '": ', exitcode )
|
2012-02-15 19:00:28 +00:00
|
|
|
else
|
2017-01-03 12:08:48 +00:00
|
|
|
log(
|
|
|
|
'Error',
|
|
|
|
'Temporary or permanent failure on startup of "',
|
2018-02-27 09:09:28 +00:00
|
|
|
agent.source, '". Terminating since "insist" is not set.'
|
2017-01-03 12:08:48 +00:00
|
|
|
)
|
|
|
|
|
2016-12-14 07:45:33 +00:00
|
|
|
terminate( -1 ) -- ERRNO
|
2012-02-15 19:00:28 +00:00
|
|
|
end
|
2016-12-14 07:45:33 +00:00
|
|
|
elseif rc == 'die'
|
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
log( 'Error', 'Failure on startup of "', agent.source, '": ', exitcode )
|
2012-02-15 19:00:28 +00:00
|
|
|
else
|
2018-02-27 09:09:28 +00:00
|
|
|
log( 'Error', 'Unknown exitcode on startup of "', agent.source, ': "', exitcode )
|
2016-12-14 07:45:33 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
rc = 'die'
|
|
|
|
end
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
return rc
|
|
|
|
end
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2016-12-14 07:45:33 +00:00
|
|
|
if agent.isList
|
|
|
|
then
|
|
|
|
local rc = config.rsyncExitCodes[ exitcode ]
|
|
|
|
|
|
|
|
if rc == 'ok'
|
|
|
|
then
|
|
|
|
log( 'Normal', 'Finished (list): ', exitcode )
|
|
|
|
elseif rc == 'again'
|
|
|
|
then
|
|
|
|
log( 'Normal', 'Retrying (list): ', exitcode )
|
|
|
|
elseif rc == 'die'
|
|
|
|
then
|
|
|
|
log( 'Error', 'Failure (list): ', exitcode )
|
2012-10-05 19:48:06 +00:00
|
|
|
else
|
2016-12-14 07:45:33 +00:00
|
|
|
log( 'Error', 'Unknown exitcode (list): ', exitcode )
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
rc = 'die'
|
|
|
|
end
|
|
|
|
return rc
|
|
|
|
else
|
|
|
|
local rc = config.sshExitCodes[exitcode]
|
|
|
|
|
2016-12-14 07:45:33 +00:00
|
|
|
if rc == 'ok'
|
|
|
|
then
|
2017-01-03 12:08:48 +00:00
|
|
|
log( 'Normal', 'Finished ', agent.etype,' ', agent.sourcePath, ': ', exitcode )
|
2016-12-14 07:45:33 +00:00
|
|
|
elseif rc == 'again'
|
|
|
|
then
|
2017-01-03 12:08:48 +00:00
|
|
|
log( 'Normal', 'Retrying ', agent.etype, ' ', agent.sourcePath, ': ', exitcode )
|
2016-12-14 07:45:33 +00:00
|
|
|
elseif rc == 'die'
|
|
|
|
then
|
2017-01-03 12:08:48 +00:00
|
|
|
log( 'Normal', 'Failure ', agent.etype, ' ', agent.sourcePath, ': ', exitcode )
|
2012-10-05 19:48:06 +00:00
|
|
|
else
|
2018-02-27 09:09:28 +00:00
|
|
|
log( 'Error', 'Unknown exitcode ', agent.etype,' ', agent.sourcePath,': ', exitcode )
|
2016-12-14 07:45:33 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
rc = 'die'
|
2012-02-15 19:00:28 +00:00
|
|
|
end
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
return rc
|
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
end
|
2012-08-25 11:45:50 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- checks the configuration.
|
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
rsyncssh.prepare = function
|
|
|
|
(
|
|
|
|
config,
|
|
|
|
level
|
|
|
|
)
|
2012-10-06 12:22:08 +00:00
|
|
|
default.rsync.prepare( config, level + 1, true )
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if not config.host
|
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
error( 'default.rsyncssh needs "host" configured', level )
|
2012-10-05 19:48:06 +00:00
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if not config.targetdir
|
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
error( 'default.rsyncssh needs "targetdir" configured', level )
|
2012-10-08 06:06:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- computes the ssh options
|
|
|
|
--
|
2016-11-25 13:55:59 +00:00
|
|
|
if config.ssh._computed
|
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
error( 'please do not use the internal rsync._computed parameter', level )
|
2012-10-08 06:06:34 +00:00
|
|
|
end
|
|
|
|
|
2017-01-03 14:30:13 +00:00
|
|
|
if config.maxProcesses ~= 1
|
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
error( 'default.rsyncssh must have maxProcesses set to 1.', level )
|
2017-01-03 14:30:13 +00:00
|
|
|
end
|
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
local cssh = config.ssh;
|
2012-10-08 06:06:34 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
cssh._computed = { }
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
local computed = cssh._computed
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
local computedN = 1
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
local rsyncc = config.rsync._computed
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if cssh.identityFile
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '-i'
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
computed[ computedN + 1 ] = cssh.identityFile
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
computedN = computedN + 2
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if not config.rsync._rshIndex
|
|
|
|
then
|
|
|
|
config.rsync._rshIndex = #rsyncc + 1
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
rsyncc[ config.rsync._rshIndex ] = '--rsh=ssh'
|
2013-07-30 09:16:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rsyncc[ config.rsync._rshIndex ] =
|
|
|
|
rsyncc[ config.rsync._rshIndex ] ..
|
|
|
|
' -i ' ..
|
|
|
|
cssh.identityFile
|
|
|
|
end
|
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if cssh.options
|
|
|
|
then
|
|
|
|
for k, v in pairs( cssh.options )
|
|
|
|
do
|
|
|
|
computed[ computedN ] = '-o'
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
computed[ computedN + 1 ] = k .. '=' .. v
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
computedN = computedN + 2
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if not config.rsync._rshIndex
|
|
|
|
then
|
|
|
|
config.rsync._rshIndex = #rsyncc + 1
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
rsyncc[ config.rsync._rshIndex ] = '--rsh=ssh'
|
2013-07-30 09:16:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rsyncc[ config.rsync._rshIndex ] =
|
|
|
|
table.concat(
|
|
|
|
{
|
|
|
|
rsyncc[ config.rsync._rshIndex ],
|
|
|
|
' -o ',
|
|
|
|
k,
|
|
|
|
'=',
|
|
|
|
v
|
|
|
|
},
|
|
|
|
''
|
|
|
|
)
|
2012-10-08 06:06:34 +00:00
|
|
|
end
|
2012-10-05 19:48:06 +00:00
|
|
|
end
|
2012-10-01 19:36:23 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if cssh.port
|
|
|
|
then
|
|
|
|
computed[ computedN ] = '-p'
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
computed[ computedN + 1 ] = cssh.port
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
computedN = computedN + 2
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
if not config.rsync._rshIndex
|
|
|
|
then
|
|
|
|
config.rsync._rshIndex = #rsyncc + 1
|
2013-07-30 09:16:29 +00:00
|
|
|
|
2016-11-25 13:55:59 +00:00
|
|
|
rsyncc[ config.rsync._rshIndex ] = '--rsh=ssh'
|
2013-07-30 09:16:29 +00:00
|
|
|
end
|
2012-11-23 15:05:15 +00:00
|
|
|
|
2013-07-30 09:16:29 +00:00
|
|
|
rsyncc[ config.rsync._rshIndex ] =
|
|
|
|
rsyncc[ config.rsync._rshIndex ] .. ' -p ' .. cssh.port
|
|
|
|
end
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
-- appends a slash to the targetdir if missing
|
2018-02-27 09:09:28 +00:00
|
|
|
-- and is not ':' for home dir
|
2016-11-25 13:55:59 +00:00
|
|
|
if string.sub( config.targetdir, -1 ) ~= '/'
|
2018-02-27 09:09:28 +00:00
|
|
|
and string.sub( config.targetdir, -1 ) ~= ':'
|
2016-11-25 13:55:59 +00:00
|
|
|
then
|
2018-02-27 09:09:28 +00:00
|
|
|
config.targetdir = config.targetdir .. '/'
|
2012-10-05 19:48:06 +00:00
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
end
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- allow processes
|
|
|
|
--
|
2016-08-29 11:12:09 +00:00
|
|
|
rsyncssh.maxProcesses = 1
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- The core should not split move events
|
|
|
|
--
|
2016-08-29 11:12:09 +00:00
|
|
|
rsyncssh.onMove = true
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- default delay
|
|
|
|
--
|
2016-08-29 11:12:09 +00:00
|
|
|
rsyncssh.delay = 15
|
2012-02-15 19:00:28 +00:00
|
|
|
|
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- no default exit codes
|
|
|
|
--
|
2016-08-29 11:12:09 +00:00
|
|
|
rsyncssh.exitcodes = false
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- rsync exit codes
|
|
|
|
--
|
2016-08-29 11:12:09 +00:00
|
|
|
rsyncssh.rsyncExitCodes = default.rsyncExitCodes
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-10-05 19:48:06 +00:00
|
|
|
--
|
|
|
|
-- ssh exit codes
|
|
|
|
--
|
2016-08-29 11:12:09 +00:00
|
|
|
rsyncssh.sshExitCodes = default.sshExitCodes
|
2012-10-05 19:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- ssh calls configuration
|
|
|
|
--
|
|
|
|
-- ssh is used to move and delete files on the target host
|
|
|
|
--
|
|
|
|
rsyncssh.ssh = {
|
2012-02-15 19:00:28 +00:00
|
|
|
|
2012-08-25 11:45:50 +00:00
|
|
|
--
|
2012-10-05 19:48:06 +00:00
|
|
|
-- the binary called
|
2012-02-16 07:28:40 +00:00
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
binary = '/usr/bin/ssh',
|
2013-07-30 09:16:29 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- if set adds this key to ssh
|
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
identityFile = nil,
|
2013-07-30 09:16:29 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- if set adds this special options to ssh
|
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
options = nil,
|
2012-02-16 07:28:40 +00:00
|
|
|
|
2012-08-25 11:45:50 +00:00
|
|
|
--
|
2012-10-05 19:48:06 +00:00
|
|
|
-- if set connect to this port
|
2012-02-15 19:00:28 +00:00
|
|
|
--
|
2016-12-14 07:45:33 +00:00
|
|
|
port = nil,
|
2012-02-15 19:00:28 +00:00
|
|
|
}
|
2012-10-05 19:48:06 +00:00
|
|
|
|