2

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 Answers 3

5

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
  • Works fine, tried with "file.*", for 5 files with same name but different extension. May 2 at 23:52
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).

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .