Skip to content

Instantly share code, notes, and snippets.

@perfectayush
Created May 2, 2013 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perfectayush/5502216 to your computer and use it in GitHub Desktop.
Save perfectayush/5502216 to your computer and use it in GitHub Desktop.
lsyncd-config used for logging
scriptdir="/opt/lsyncd/"
file_mod_dir="/opt/lsyncd/tmp/modify"
file_del_dir="/opt/lsyncd/tmp/delete"
function split_path(filename)
local root, dir, basename
local i, j = filename:find("[^/]*$")
if filename:sub(1, 1) == "/" then
root = "/"
dir = filename:sub(2, i - 1)
else
root = ""
dir = filename:sub(1, i - 1)
end
local basename = filename:sub(i, j)
return root, dir, basename
end
function dirname(path)
if path:sub(path:len()) == "/" then
path = path:sub(1, -2)
end
local root, dir = split_path(path)
if #dir > 0 then
dir = dir:sub(1, #dir - 1)
return root .. dir
end
if #root > 0 then
return root
end
return "."
end
function givepath_delete(path,filename)
path = path:gsub("/+","/"):gsub(" ","[[:space:]]")
local file = io.open(filename, "a")
file:write("+ ",path,"\n")
repeat
file:write("+ ",dirname(path),"\n")
path = dirname(path)
until path == "/"
file:close()
end
function givepath_modify(path,filename)
local file = io.open(filename, "a")
file:write(path,"\n")
file:close()
end
custom = {
-----
-- Spawns the recursive startup sync
--
delay = 0,
maxProcesses = 200,
onAttrib = function (event)
local timestamp = os.date ("%d-%b-%H")
givepath_modify(event.pathname,file_mod_dir.."/rsync-"..timestamp..".txt")
end,
onCreate = function (event)
local timestamp = os.date ("%d-%b-%H")
givepath_modify(event.pathname,file_mod_dir.."/rsync-"..timestamp..".txt")
end,
onModify = function (event)
file_mod_dir="/opt/lsyncd/tmp/modify"
local timestamp = os.date ("%d-%b-%H")
givepath_modify(event.pathname,file_mod_dir.."/rsync-"..timestamp..".txt")
end,
onDelete = function (event)
local timestamp = os.date ("%d-%b-%H")
givepath_delete(event.pathname,file_del_dir.."/rsync-"..timestamp..".txt")
end,
onStartup = "mkdir -p "..file_del_dir.." "..file_mod_dir ,
}
custom.checkgauge = {
default.rsync.checkgauge,
onAttrib = true,
onModify = true,
onCreate = true,
onDelete = true,
onModify = true,
onStartup = true,
exclude = true,
excludeFrom = true,
}
sync {
custom,
source = "/",
target = "some_target::lsyncd/",
}
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
nodaemon = false,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment