在 robocopy 期间遍历 samba 份额并排除一些
Traverse samba shares during robocopy and exclude some
我使用 Robocopy 将 Samba 共享备份到本地驱动器,反之亦然。
要将远程共享与本地文件夹同步,我使用 PS 脚本
$Path = Split-Path "\192.168.1.100\asuscloud\*"
$Dest = "E:\back_fold\asuscloud\"
robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL
要排除某些子文件夹,可以使用 /XD
开关
$Path = Split-Path "\192.168.1.100\asuscloud\*"
$Dest = "E:\back_fold\asuscloud"
robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL /XD "\192.168.1.100\asuscloud\subdir"
但是,此语法不适用于该主机的主机和共享
$Path = Split-Path "\192.168.1.100\*"
$Dest = "E:\back_fold\"
robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL /XD "\192.168.1.100\asuscloud\"
它抛出
------------------------------------------------------------------------------>-
ROBOCOPY :: Robust File Copy for Windows
Started : Saturday, September 1, 2018 8:46:23 PM
Source : D:\back_fold\
Dest -
Files : .
Exc Dirs : 2.168.1.100\asuscloud
Options : . /FP /NDL /TEE /DCOPY:DA /COPY:DAT /Z /NP /IS /MT:64 /R:1000000 /W:30
ERROR : No Destination Directory Specified.
我想排除主机的两个共享并将其他共享同步到本地文件夹。
如何实现?
更新:nbtstat -A 192.168.1.100
C:\Windows\system32>nbtstat -A 192.168.1.100
Ethernet:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Ethernet 2:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Bluetooth Network Connection:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Wi-Fi:
Node IpAddress: [192.168.1.105] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
PASCAL <00> UNIQUE Registered
PASCAL <03> UNIQUE Registered
PASCAL <20> UNIQUE Registered
☺☻__MSBROWSE__☻<01> GROUP Registered
WORKGROUP <1E> GROUP Registered
WORKGROUP <00> GROUP Registered
WORKGROUP <1D> UNIQUE Registered
WORKGROUP <1B> UNIQUE Registered
MAC Address = 00-00-00-00-00-00
Local Area Connection* 3:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
网络视图\\192.168.1.100
C:\Windows\system32>NET VIEW \192.168.1.100
Shared resources at \192.168.1.100
Pascal
Share name Type Used as Comment
-------------------------------------------------------------------------------
asuscloud Disk data's asuscloud in External USB3.0
backup Disk data's backup in External USB3.0
downloads Disk data's downloads in External USB3.0
dropbox Disk data's dropbox in External USB3.0
entware Disk data's entware in External USB3.0
os Disk data's os in External USB3.0
The command completed successfully.
记住 \ 是转义字符。二\等于1。尝试在变量字符串上使用单引号 '
而不是双引号 "
这就是它寻找 \192.168.1.100\ 而不是 \192.168.1.100\
的原因
如果需要,我还会包括共享名称。
单引号让你不用转义。示例:
$Path = Split-Path '\192.168.1.100\asuscloud\*'
$Dest = 'E:\back_fold\asuscloud\'
使用双引号可能需要转义。示例:
$Path = Split-Path "\\192.168.1.100\asuscloud\*"
$Dest = "E:\back_fold\asuscloud\"
请注意,您可能还需要转义星号。
包括共享名(如果需要)。示例:
$Path = Split-Path '\192.168.1.100\c$\asuscloud\*'
这不会动态查找远程主机上的共享,但它允许您指定要从中复制的 SHARENAME。
我认为您的基本误解是单独的主机名(或 IP 地址)不是路径。它还必须有一个 SHARENAME。
如果将其保存为 Do-It.ps1
,则要查看详细消息,请使用 .\Do-It.ps1 -Verbose
调用它
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, position=0)]
[string]$computername
,[Parameter(Mandatory=$true, position=1)]
[string[]]$sharenames
,[Parameter(Mandatory=$false, position=2)]
[string]$dest = 'E:/back_fold/asuscloud'
)
$excludeshares = @('SHARE1', 'OTHERSHARE')
foreach ($sharename in $sharenames) {
write-Verbose $sharename
if ($excludeshares -notcontains $sharename.ToUpper()) {
$Path = "//$computername/$sharename"
$cmdline = { robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL }
Write-Verbose $cmdline.ToString()
& $cmdline
}
}
这可以与包含 SHARENAME 列表的文件一起使用。
.\Do-It.ps1 -computername '192.168.1.100' -sharenames $(Get-Content -Path .\sharelist.txt)
我使用 Robocopy 将 Samba 共享备份到本地驱动器,反之亦然。 要将远程共享与本地文件夹同步,我使用 PS 脚本
$Path = Split-Path "\192.168.1.100\asuscloud\*"
$Dest = "E:\back_fold\asuscloud\"
robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL
要排除某些子文件夹,可以使用 /XD
开关
$Path = Split-Path "\192.168.1.100\asuscloud\*"
$Dest = "E:\back_fold\asuscloud"
robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL /XD "\192.168.1.100\asuscloud\subdir"
但是,此语法不适用于该主机的主机和共享
$Path = Split-Path "\192.168.1.100\*"
$Dest = "E:\back_fold\"
robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL /XD "\192.168.1.100\asuscloud\"
它抛出
------------------------------------------------------------------------------>-
ROBOCOPY :: Robust File Copy for Windows
Started : Saturday, September 1, 2018 8:46:23 PM Source : D:\back_fold\ Dest -
Files : .
Exc Dirs : 2.168.1.100\asuscloud
Options : . /FP /NDL /TEE /DCOPY:DA /COPY:DAT /Z /NP /IS /MT:64 /R:1000000 /W:30
ERROR : No Destination Directory Specified.
我想排除主机的两个共享并将其他共享同步到本地文件夹。
如何实现?
更新:nbtstat -A 192.168.1.100
C:\Windows\system32>nbtstat -A 192.168.1.100
Ethernet:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Ethernet 2:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Bluetooth Network Connection:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Wi-Fi:
Node IpAddress: [192.168.1.105] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
PASCAL <00> UNIQUE Registered
PASCAL <03> UNIQUE Registered
PASCAL <20> UNIQUE Registered
☺☻__MSBROWSE__☻<01> GROUP Registered
WORKGROUP <1E> GROUP Registered
WORKGROUP <00> GROUP Registered
WORKGROUP <1D> UNIQUE Registered
WORKGROUP <1B> UNIQUE Registered
MAC Address = 00-00-00-00-00-00
Local Area Connection* 3:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
网络视图\\192.168.1.100
C:\Windows\system32>NET VIEW \192.168.1.100
Shared resources at \192.168.1.100
Pascal
Share name Type Used as Comment
-------------------------------------------------------------------------------
asuscloud Disk data's asuscloud in External USB3.0
backup Disk data's backup in External USB3.0
downloads Disk data's downloads in External USB3.0
dropbox Disk data's dropbox in External USB3.0
entware Disk data's entware in External USB3.0
os Disk data's os in External USB3.0
The command completed successfully.
记住 \ 是转义字符。二\等于1。尝试在变量字符串上使用单引号 '
而不是双引号 "
这就是它寻找 \192.168.1.100\ 而不是 \192.168.1.100\
的原因如果需要,我还会包括共享名称。
单引号让你不用转义。示例:
$Path = Split-Path '\192.168.1.100\asuscloud\*'
$Dest = 'E:\back_fold\asuscloud\'
使用双引号可能需要转义。示例:
$Path = Split-Path "\\192.168.1.100\asuscloud\*"
$Dest = "E:\back_fold\asuscloud\"
请注意,您可能还需要转义星号。
包括共享名(如果需要)。示例:
$Path = Split-Path '\192.168.1.100\c$\asuscloud\*'
这不会动态查找远程主机上的共享,但它允许您指定要从中复制的 SHARENAME。
我认为您的基本误解是单独的主机名(或 IP 地址)不是路径。它还必须有一个 SHARENAME。
如果将其保存为 Do-It.ps1
,则要查看详细消息,请使用 .\Do-It.ps1 -Verbose
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, position=0)]
[string]$computername
,[Parameter(Mandatory=$true, position=1)]
[string[]]$sharenames
,[Parameter(Mandatory=$false, position=2)]
[string]$dest = 'E:/back_fold/asuscloud'
)
$excludeshares = @('SHARE1', 'OTHERSHARE')
foreach ($sharename in $sharenames) {
write-Verbose $sharename
if ($excludeshares -notcontains $sharename.ToUpper()) {
$Path = "//$computername/$sharename"
$cmdline = { robocopy $Path $Dest /B /MT:64 /IS /Z /FP /MIR /TEE /NP /FP /NDL }
Write-Verbose $cmdline.ToString()
& $cmdline
}
}
这可以与包含 SHARENAME 列表的文件一起使用。
.\Do-It.ps1 -computername '192.168.1.100' -sharenames $(Get-Content -Path .\sharelist.txt)