0
votes

I use Robocopy for backup Samba shares into local drive and vice versa. To sync remote share with local folder I use PS script

$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

To exclude some subfolder one can use /XD switch

$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"

However, this syntax doesn't work for the host and shares of this host

$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\"

It throws

------------------------------------------------------------------------------>-

ROBOCOPY :: Robust File Copy for Windows

Started : Saturday, September 1, 2018 8:46:23 PM Source : D:\back_fold\ Dest -

Files : .

Exc Dirs : \192.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.

I want to exclude two shares of a host and sync others into local folder.

enter image description here

How to achieve this?

UPDATE: 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.

NET VIEW \\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.
2
Is the list of SHARENAMEs on the remote computer a fixed list, or does it need to be dynamically found?lit
Dynamically is better, but I prefer both variantsSuncatcher

2 Answers

1
votes

This does not dynamically find the shares on the remote host, but it does allow you to specify the SHARENAMEs from which to copy.

I think your basic misunderstanding is that a hostname (or IP address) alone is not a path. It has to also have a SHARENAME.

If you save this as Do-It.ps1, then to see the verbose messages, invoke it with .\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
    }
}

This can be use with a file containing a list of SHARENAMEs.

.\Do-It.ps1 -computername '192.168.1.100' -sharenames $(Get-Content -Path .\sharelist.txt)
0
votes

remember \ is an escape character. Two \ equals 1 . Try using single quotes ' on your variable strings instead of double quotes "

That's why it's looking for \192.168.1.100\ instead of \192.168.1.100\

I'd also include share names if needed.

Single quotes will allow you to not need to escape. Example:

$Path = Split-Path '\\192.168.1.100\asuscloud\*'
$Dest = 'E:\back_fold\asuscloud\'

Using double quotes might need escaping. Example:

$Path = Split-Path "\\\\192.168.1.100\\asuscloud\\*"
$Dest = "E:\\back_fold\\asuscloud\\"

Please note you might need to escape the asterisk as well.

Including sharename (if needed). Example:

$Path = Split-Path '\\192.168.1.100\c$\asuscloud\*'