Samba

在 linux 上掛載 windows 共享,同時保持 windows 權限

  • February 14, 2014

我在 windows2003 伺服器 (WINJOE) 上有一個 windows 共享,我想將它備份到正確加入域的 Linux 機器 (LINUXJOE)。我的目標是將 WINJOE 的共享文件夾備份到 LINUXJOE,同時保留 Windows 權限/所有者。在閱讀了相關文獻後,我的印像是這是不可能的……

無論如何,在理想情況下,我想在 LINUXJOE 上掛載一個 win 共享(只讀),例如 \WINJOE\important_folder,然後從那裡執行 rsync 到備份目錄。

到目前為止我所擁有的:

\WINJOE\important_folder -> 要備份的共享文件夾

LINUXJOE: /mnt/important -> LINUXJOE 上 \WINJOE\important_folder 的掛載點

LINUXJOE: /backup/$DATE-important -> 備份目標目錄

目前我可以使用我的 Windows 域帳戶登錄到 LINUXJOE,如果我在 LINUXJOE 的文件系統上創建文件,它們會將所有者顯示為“somewinuser”域使用者“,因此從 Windows 到 linux 的使用者映射工作正常。當我使用以下命令安裝 \WINJOE\important_folder 時:

linuxjoe# mount.cifs //WINJOE/important_folder /mnt/important \
-o ro,user=backitup,dom=TODOMAIN,cifsacl,nounix  --verbose

我得到:

ls -latrh

linuxjoe# ls -latrh /mnt/important
total 518M
-r-xr-xr-x 0 root root         518M Sep 28 01:19 test.mkv
-rwxr-xr-x 0 root root            0 Oct 25 19:04 testlalala
-rwxr-xr-x 0 root root            0 Oct 25 19:05 testkoko
drwxrwxrwx 1 root domain users    0 Oct 25 19:05 .
drwxr-xr-x 5 root root         4.0K Oct 29 16:29 ..


getcifsacl

linuxjoe# getcifsacl /mnt/important/test.mkv
REVISION:0x1
CONTROL:0x8404
OWNER:BUILTIN\Administrators
GROUP:TODOMAIN\Domain Users
ACL:Everyone:ALLOWED/I/FULL
ACL:NT AUTHORITY\SYSTEM:ALLOWED/I/FULL
ACL:BUILTIN\Administrators:ALLOWED/I/FULL
ACL:TODOMAIN\lukeskywalker:ALLOWED/I/FULL

rsyncing:

linuxjoe# rsync -apvXAgo /mnt/important/koko.mkv  /root/test/

linuxjoe# ls -latrh  /root/test/
total 518M
-rwxrwxrwx 1 root domain users 518M Sep 28 01:19 test.mkv
drwx------ 8 root root         4.0K Oct 29 18:29 ..
drwxr-xr-x 2 root root         4.0K Oct 29 18:29 .

當我從 Windows 共享 rsync 到我的 linux 備份盒時,是否可以以任何方式查看 Windows 共享上文件的正確所有者,並保留該所有者以及所有 Windows 安全屬性?

配置文件

[global]
workgroup = TODOMAIN
realm=SOMEOFFICE.SOMEWHERE.GR
server string = %h server
wins support = no
security = ads
encrypt passwords = yes
obey pam restrictions = yes
template shell = /bin/bash
template homedir = /home/%D/%U
password server=winjoe.someoffice.somewhere.gr
domain master = no
local master = no
prefered master = no

idmap config * : backend = rid
idmap config * : range = 5000-3000000000
idmap config * : base_rid = 0

idmap config TODOMAIN : backend = rid
idmap config TODOMAIN : range = 5000-3000000000
idmap cache time = 900
algorithmic rid base = 5000
client schannel = no
disable spoolss=yes

winbind separator=+
winbind use default domain=yes
winbind nested groups=yes
winbind enum users=yes
winbind enum groups=yes
winbind cache time= 300
winbind refresh tickets = yes

inherit acls = Yes
map acl inherit = Yes
acl group control = yes

不幸的是,Linux ACL 和 Windows ACL 非常不同。當您通過 Samba 從 Windows 訪問 Linux 文件系統時,Samba 設法將更簡單的 Linux ACL 映射到 Windows ACL,而不會失去太多資訊。為此,您已經需要 smb.conf 中的許多選項。

反之則困難得多,甚至可能是不可能的,尤其是當 Linux 掛載與 Windows 映射共享具有不同的語義時。並且安裝發生在根本不實現 ACL 的核心驅動程序上。我們唯一的方法是使用 getcifsacl 等附加程序獲取資訊。

因此,像 rsync 這樣的普通 Linux 工具對 Windows ACL 一無所知,也無法儲存它們。如果您需要恢復這些 ACL,您需要自己使用 getcifsacl 保存它們並使用 setcifsacl 進行恢復。不幸的是,這些命令僅適用於單個文件,而 setcifsacl 不能直接使用 getcifsacl 的輸出,因此您需要一組複雜的腳本來備份/恢復這些 ACL。快速搜尋未顯示任何現有解決方案。

解決此問題的一種方法是讓 Windows 進行備份並使用 Linux 共享作為備份文件(而不是單個文件)的儲存。

引用自:https://serverfault.com/questions/549440