1

I want to sync certain files from one linux system to another using lsyncd. The files are not confined to one directory, neither do I want all files from a directory.

Specifically I'm trying to make sure certain mail server files are kept in sync with a standby server. Here is a list:

/etc/postfix/master.cf /etc/postfix/main.cf /etc/postfix/blocked_senders /etc/postfix/relay_recipients /etc/mail/spamassassin/local.cf

Can I specify all these files in a single sync stanza via some kind of list or will I need to configure each individual file in separate sync stanzas?

3

I suggest

--[[
The _extra= hack allows synchronization of individual files. Use one sync {}
stanza per source directory. Use additional --include= lines to handle multiple
files within a single source directory.
]]

sync {
  default.rsync,
  delay = 0,
  source = "/etc/postfix/",
  target = "standby.example.com:/etc/postfix/",
  rsync = {
    _extra = {
      "--include=master.cf",
      "--include=main.cf",
      "--include=blocked_senders",
      "--include=relay_recipients",
      "--exclude=*",
    }
  }
}

sync {
  default.rsync,
  delay = 0,
  source = "/etc/mail/spamassassin/",
  target = "standby.example.com:/etc/mail/spamassassin/",
  rsync = {
    _extra = {
      "--include=local.cf",
      "--exclude=*",
    }
  }
}

I think a sync {} stanza is needed for each source directory because lsyncd detects changes efficiently via triggers established at the directory level.

1

Though this is an old one I would like put David's response into an "lsyncd" context. A sample configuration could look like this (tested and confirmed on one of my systems):

sync {
   default.rsyncssh,
   source = "/tmp",
   host = "gw2",
   targetdir = "/tmp",
   delete = false,
   rsync = { _extra = { "--files-from=/etc/lsyncd/files.list" } }
}

With the file /etc/lsyncd/files.list containing the files you want to sync with paths relative to "destination" (/tmp here).

  • That way seems strongly disapproved by the conceptor : github.com/axkibe/lsyncd/issues/394 – tisc0 Mar 25 '17 at 11:15
  • @tisc0: Just adding your solution here for informational purposes: _extra = { "--include=php.ini", "--exclude=*" } – Fox Mar 26 '17 at 12:00
  • Actually it's the solution of Marc just above :) – tisc0 Mar 27 '17 at 18:29
0

Save them to a file file_list

rsync -a --files-from=file_list /source /dest

If only these 5 files, then I think you can also use -c (checksum check) and -z (compression) options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.