lsyncd cant use dynamic backup suffix

417 Views Asked by At

I wan't to use lsyncd to create backups of the modified files using as a suffix a date/time string. If I set the suffix option (in the lsyncd.conf file) using lua, the date/time is computed once, when I start the daemon, and is not updated at each sync iteration. This leads to the creation of only one backup file per each modified file (with the same suffix) and I wish for the creation of a new backup file per modification per file. The config file I use is the following:

-- global settings
settings {
   delay        = 5,
   maxProcesses = 5,
   statusFile   = "<STATUS_FILE_PATH>",
   logfile      = "<LOG_FILE_PATH>",
   insist       = true
}

-- target nodes
nodes = {
{ source = "/home/<USER>/sync", target = "<TARGET_IP>:/home/<USER>/sync"},
}

-- execution
time = os.date("*t")
datetime = (time.year .. time.month .. time.day .. time.hour .. time.min .. time.sec)
for _, node in ipairs(nodes) do
  sync {
    default.rsync,
    source = node.source,
    target = node.target,
    rsync = {
      compress  = true,
      checksum  = true,
      perms     = true,
      rsh       = "/usr/bin/ssh -i /home/<USER>/.ssh/id_dsa -o StrictHostKeyChecking=no",
      times     = true,
      verbose   = true,
      _extra    = { "--backup", "--suffix=" .. datetime },
    }
  }
end

If i try to pass the date function of bash in the suffix option, like this:

_extra = { "--backup", "--suffix=_$(date +\"%Y%m%d%H%M%S\")" },

it is converted to a string without computing the value, leading to a backup file with a name like this:

testfile.txt_$(date +"%Y%m%d%H%M%S")

I am limited to using the 2.1.4 version of lsyncd. Is it possible to create dynamic backup file suffixes?

1

There are 1 best solutions below

1
On

Not tested. But try this

--suffix=`date +"%F"`