Created
August 8, 2017 12:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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