mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-07 09:04:05 +00:00
This commit is contained in:
parent
ddc6157e91
commit
c05ba085f6
12
examples/lrssh.lua
Normal file
12
examples/lrssh.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
----
|
||||||
|
-- User configuration file for lsyncd.
|
||||||
|
--
|
||||||
|
-- Simple example for default rsync.
|
||||||
|
--
|
||||||
|
settings = {
|
||||||
|
statusFile = "/tmp/lsyncd.stat",
|
||||||
|
statusIntervall = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
sync{default.rssh, source="src", host="localhost", targetdir="dst/"}
|
||||||
|
|
120
lsyncd.lua
120
lsyncd.lua
@ -576,8 +576,10 @@ local Inlet, InletControl = (function()
|
|||||||
-----
|
-----
|
||||||
-- Gets all events that are not blocked by active events.
|
-- Gets all events that are not blocked by active events.
|
||||||
--
|
--
|
||||||
local function getEvents()
|
-- @param if not nil a function to test each delay
|
||||||
local dlist = sync:getDelays()
|
--
|
||||||
|
local function getEvents(test)
|
||||||
|
local dlist = sync:getDelays(test)
|
||||||
return dl2el(dlist)
|
return dl2el(dlist)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -923,7 +925,8 @@ local Sync = (function()
|
|||||||
local c = self.config.collapse(oel, nel, self.config)
|
local c = self.config.collapse(oel, nel, self.config)
|
||||||
if c == 0 then
|
if c == 0 then
|
||||||
-- events nullificate each ether
|
-- events nullificate each ether
|
||||||
od.etype = "None" -- TODO better remove?
|
od.etype = "None"
|
||||||
|
table.remove(self.delays, il)
|
||||||
return
|
return
|
||||||
elseif c == 1 then
|
elseif c == 1 then
|
||||||
log("Delay",nd.etype," is absored by event ",
|
log("Delay",nd.etype," is absored by event ",
|
||||||
@ -997,7 +1000,9 @@ local Sync = (function()
|
|||||||
-----
|
-----
|
||||||
-- Gets all delays that are not blocked by active delays.
|
-- Gets all delays that are not blocked by active delays.
|
||||||
--
|
--
|
||||||
local function getDelays(self)
|
-- @param test function to test each delay
|
||||||
|
--
|
||||||
|
local function getDelays(self, test)
|
||||||
local dlist = {}
|
local dlist = {}
|
||||||
local blocks = {}
|
local blocks = {}
|
||||||
|
|
||||||
@ -1006,13 +1011,17 @@ local Sync = (function()
|
|||||||
--
|
--
|
||||||
local function getBlocks(delay)
|
local function getBlocks(delay)
|
||||||
blocks[delay] = true
|
blocks[delay] = true
|
||||||
for i, d in ipairs(delay.blocks) do
|
if delay.blocks then
|
||||||
getBlocks(d)
|
for i, d in ipairs(delay.blocks) do
|
||||||
|
getBlocks(d)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, d in ipairs(self.delays) do
|
for i, d in ipairs(self.delays) do
|
||||||
if d.status == "active" then
|
if d.status == "active" or
|
||||||
|
(test and not test(InletControl.d2e(d)))
|
||||||
|
then
|
||||||
getBlocks(d)
|
getBlocks(d)
|
||||||
elseif not blocks[d] then
|
elseif not blocks[d] then
|
||||||
dlist[i] = d
|
dlist[i] = d
|
||||||
@ -2091,21 +2100,21 @@ end
|
|||||||
-----
|
-----
|
||||||
-- lsyncd classic - sync with rsync
|
-- lsyncd classic - sync with rsync
|
||||||
--
|
--
|
||||||
local defaultRsync = {
|
local default_rsync = {
|
||||||
-----
|
-----
|
||||||
-- Spawns rsync for a list of events
|
-- Spawns rsync for a list of events
|
||||||
--
|
--
|
||||||
action = function(inlet)
|
action = function(inlet)
|
||||||
local elist = inlet.getEvents()
|
local elist = inlet.getEvents()
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig()
|
||||||
local spaths = elist.getSourcePaths()
|
local paths = elist.getPaths()
|
||||||
log("Normal", "rsyncing list\n", spaths)
|
log("Normal", "rsyncing list\n", paths)
|
||||||
spawn(elist, "/usr/bin/rsync",
|
spawn(elist, "/usr/bin/rsync",
|
||||||
"<", spaths,
|
"<", paths,
|
||||||
"--delete",
|
"--delete",
|
||||||
config.rsyncOps.."d",
|
config.rsyncOps .. "d",
|
||||||
"--include-from=-",
|
"--include-from=-",
|
||||||
"--exclude=\"*\"",
|
"--exclude=*",
|
||||||
config.source, config.target)
|
config.source, config.target)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -2122,7 +2131,7 @@ local defaultRsync = {
|
|||||||
" -> ", config.target)
|
" -> ", config.target)
|
||||||
spawn(event, "/usr/bin/rsync",
|
spawn(event, "/usr/bin/rsync",
|
||||||
"--delete",
|
"--delete",
|
||||||
config.rsyncOps.."r",
|
config.rsyncOps .. "r",
|
||||||
config.source,
|
config.source,
|
||||||
config.target)
|
config.target)
|
||||||
end,
|
end,
|
||||||
@ -2135,7 +2144,77 @@ local defaultRsync = {
|
|||||||
-----
|
-----
|
||||||
-- Default delay 3 seconds
|
-- Default delay 3 seconds
|
||||||
--
|
--
|
||||||
delay = 3,
|
delay = 20,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- lsyncd classic - sync with rsync
|
||||||
|
--
|
||||||
|
local default_rssh = {
|
||||||
|
-----
|
||||||
|
-- Spawns rsync for a list of events
|
||||||
|
--
|
||||||
|
action = function(inlet)
|
||||||
|
local event = inlet.getEvent()
|
||||||
|
local config = inlet.getConfig()
|
||||||
|
if event.etype == 'Move' then
|
||||||
|
-- makes move local on host
|
||||||
|
spawn(event, "/usr/bin/ssh",
|
||||||
|
config.host, "mv",
|
||||||
|
config.targetdir .. event.path,
|
||||||
|
config.targetdir .. event.path2)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- for everything else spawn a rsync
|
||||||
|
-- gets all events that are not Move
|
||||||
|
local elist = inlet.getEvents(function(e)
|
||||||
|
return e.etype ~= "Move"
|
||||||
|
end)
|
||||||
|
local spaths = elist.getPaths()
|
||||||
|
log("Normal", "rsyncing list\n", spaths)
|
||||||
|
spawn(elist, "/usr/bin/rsync",
|
||||||
|
"<", spaths,
|
||||||
|
config.rsyncOps .. "d",
|
||||||
|
"--delete",
|
||||||
|
"--include-from=-",
|
||||||
|
"--exclude=*",
|
||||||
|
config.source,
|
||||||
|
config.host .. ":" .. config.targetdir)
|
||||||
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Spawns the recursive startup sync
|
||||||
|
--
|
||||||
|
init = function(inlet)
|
||||||
|
local config = inlet.getConfig()
|
||||||
|
local event = inlet.createBlanketEvent()
|
||||||
|
if string.sub(config.targetdir, -1) ~= "/" then
|
||||||
|
config.targetdir = config.targetdir .. "/"
|
||||||
|
end
|
||||||
|
log("Normal", "recursive startup rsync: ", config.source,
|
||||||
|
" -> ", config.host .. ":" .. config.targetdir)
|
||||||
|
spawn(event, "/usr/bin/rsync",
|
||||||
|
"--delete",
|
||||||
|
config.rsyncOps .. "r",
|
||||||
|
config.source,
|
||||||
|
config.host .. ":" .. config.targetdir)
|
||||||
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Calls rsync with this options
|
||||||
|
--
|
||||||
|
rsyncOps = "-lts",
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- allow several processes
|
||||||
|
--
|
||||||
|
maxProcesses = 10,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Default delay 3 seconds
|
||||||
|
--
|
||||||
|
delay = 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -2176,6 +2255,10 @@ default = {
|
|||||||
-- 3 ... events block.
|
-- 3 ... events block.
|
||||||
--
|
--
|
||||||
collapse = function(event1, event2, config)
|
collapse = function(event1, event2, config)
|
||||||
|
print(event1.path, event2.path)
|
||||||
|
print(event1.etype, event1.move)
|
||||||
|
print(event2.etype, event2.move)
|
||||||
|
|
||||||
if event1.path == event2.path then
|
if event1.path == event2.path then
|
||||||
local e1 = event1.etype .. event1.move
|
local e1 = event1.etype .. event1.move
|
||||||
local e2 = event2.etype .. event2.move
|
local e2 = event2.etype .. event2.move
|
||||||
@ -2273,7 +2356,12 @@ default = {
|
|||||||
-----
|
-----
|
||||||
-- a default rsync configuration for easy usage.
|
-- a default rsync configuration for easy usage.
|
||||||
--
|
--
|
||||||
rsync = defaultRsync,
|
rsync = default_rsync,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- a default rsync configuration with ssh'd move and rm actions
|
||||||
|
--
|
||||||
|
rssh = default_rssh,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Minimum seconds between two writes of a status file.
|
-- Minimum seconds between two writes of a status file.
|
||||||
|
Loading…
Reference in New Issue
Block a user