Skip to content

Instantly share code, notes, and snippets.

@rjohnsondev
Created August 8, 2017 12:21
Show Gist options
  • Save rjohnsondev/60649318b2c6a7176b712c2825c2cad0 to your computer and use it in GitHub Desktop.
Save rjohnsondev/60649318b2c6a7176b712c2825c2cad0 to your computer and use it in GitHub Desktop.
lsyncd example config which creates a copy of file with timestamp when moved / renamed
local src = "/test_lsyncd/src"
local dest = "/test_lsyncd/dest"
timestampFiles = {
delay = 0,
maxProcesses = 99,
action = function(inlet)
local event, dstEvent = inlet.getEvent()
if event.isdir then
-- ignores events on dirs
inlet.discardEvent(event)
return
end
if event.etype ~= "Move" then
inlet.discardEvent(event)
return
end
-- extract extension and basefilename
local p = dstEvent.pathname
local ext = string.match(p, ".*%.([^.]+)$")
if ext == nil then
inlet.discardEvent(event)
return
end
local base = string.match(p, "(.*)%.[^.]+$")
log("Normal", event.etype)
local date = os.date("%Y-%m-%d_%H-%M-%S", os.time())
local cmd = "cp "..dstEvent.sourcePath.." "..dest.."/"..base.."_"..date.."."..ext
log("Normal", cmd)
spawnShell(event, cmd)
return
end,
}
sync{timestampFiles, source=src, onMove=true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment