Lsyncd 2.2.2 所有權與權限問題

Lsyncd 2.2.2 所有權與權限問題

我遇到一個問題,文件被複製到遠端伺服器,但目標伺服器上複製文件的擁有者/群組始終為“1002”。來源的權限受到尊重並在目標上正確複製。我只是想不出一種方法來保留複製文件的所有者(和群組)。

Lsyncd版本:2.2.2

我的設定如下:

settings {
    logfile = "/var/log/lsyncd/lsyncd.log",
    statusFile = "/var/log/lsyncd/lsyncd.status"
}

sync {
    default.rsyncssh,
    source="/home",
    host="1*52.*.15",
    targetdir="/home/",
    delete = "running", -- prevents deletion of files on startup (ie when a server comes back online, don't delete files that are new on the backup)
    delay = 5, -- run every 5 seconds instead of default 20
    exclude = {
        "/home/backup",
    },
    rsync = {
        archive = true, -- use the archive flag in rsync
        perms = true, -- Keep the permissions
        owner = true, -- Keep the owner
        compress = true,
        acls = true,
            xattrs = true,
        _extra = {"-a"}, -- Sometimes permissions and owners isn't copied correctly so the _extra can be used for any flag in rsync
    }
}

lsyncd 日誌錯誤:

Dec 15 21:42:47 server1.*.group lsyncd[21033]: sending incremental file list
Dec 15 21:42:47 server1.*.group lsyncd[21033]: rsync: failed to set times on "/home/admin/conf": Operation not permitted (1)
Dec 15 21:42:47 server1.*.group lsyncd[21033]: admin/conf/
Dec 15 21:42:47 server1.*.group lsyncd[21033]: sent 5,387 bytes  received 160 bytes  3,698.00 bytes/sec
Dec 15 21:42:47 server1.*.group lsyncd[21033]: total size is 2,849,404,839  speedup is 513,683.94
Dec 15 21:42:47 server1.*.group lsyncd[21033]: rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]

答案1

我相信問題是本機系統上檔案的 uid/gid 與目標系統上的 uid/gid 不對應。

檢查本機系統上的使用者/群組 ID 並在目標系統上建立相同的使用者/群組。

# On source system
$ ls -l /home/admin/conf
-rw-r--r--. 1 user1 user1 1.0K Jul 13  2018 /home/admin/conf

$ id user1
uid=1002(user1) gid=1002(user1) groups=1002(user1)

# On target system
$ useradd -u 1002 -g 1002 user1

答案2

當 RSYNC 傳輸保留所有權的檔案時,它傳輸的不是使用者名稱/群組名稱,而是擁有者的 UID 和 GID。

因此,您對 1002 的體驗意味著該 UID 未在目標系統上使用。

您可以透過以下兩種方式之一解決此問題:

  • 刪除舊用戶,然後使用 useradd 中的 UID 設定重新建立它。 -- 這可能是最乾淨的方法,因為您不必 chown 或 chmod 任何內容。
  • 使用 usermod 更新 UID 和 GID。 -- 如果您這樣做,您將需要 chown 主目錄中的文件,並且可能會對該使用者擁有的其他文件產生其他意外的副作用。

項目清單

相關內容