Solved What is the Robocopy syntax?


OK, I will try the /XA:SH switch, there are discouraging examples on the net, but maybe I am lucky.

I note in your example, that you use a 'list script' too. Are those items the only ones that you are interested in in backing up, or is your actual list a lot longer? I'd rather back up everything and pick and choose what I need.
 

My Computer

System One

  • OS
    Windows 10 Pro
A couple of items to add:

1) Be cautious with the /mir switch in robocopy. You need to be aware that it can not only copy files / folders from the source to the destination, but it can DELETE items from the destination as well. Put another way, any files or folders that exist in the destination, but not in the source will be deleted from the destination.

2) Until you get comfortable with robocopy, consider using a "/L" switch for testing purposes. That switch tells robocopy to simulate the operation but does not actually copy / move / delete anything. It will give you a summary so that you can see what would have happened if you ran the command without the "/L".
 

My Computers

System One System Two

  • OS
    Win11 Pro 23H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Built
    CPU
    Intel i7-11700K
    Motherboard
    ASUS Prime Z590-A
    Memory
    128GB Crucial Ballistix 3200MHz DRAM
    Graphics Card(s)
    No GPU - CPU graphics only (for now)
    Sound Card
    Realtek (on motherboard)
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe Gen 4 x 4 SSD
    1 x 2TB NVMe Gen 3 x 4 SSD
    2 x 512GB 2.5" SSDs
    2 x 8TB HD
    PSU
    Corsair HX850i
    Case
    Corsair iCue 5000X RGB
    Cooling
    Noctua NH-D15 chromax.black cooler + 10 case fans
    Keyboard
    CODE backlit mechanical keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    1Gb Up / 1 Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    Additional options installed:
    WiFi 6E PCIe adapter
    ASUS ThunderboltEX 4 PCIe adapter
  • Operating System
    Win11 Pro 23H2
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkBook 13x Gen 2
    CPU
    Intel i7-1255U
    Memory
    16 GB
    Graphics card(s)
    Intel Iris Xe Graphics
    Sound Card
    Realtek® ALC3306-CG codec
    Monitor(s) Displays
    13.3-inch IPS Display
    Screen Resolution
    WQXGA (2560 x 1600)
    Hard Drives
    2 TB 4 x 4 NVMe SSD
    PSU
    USB-C / Thunderbolt 4 Power / Charging
    Mouse
    Buttonless Glass Precision Touchpad
    Keyboard
    Backlit, spill resistant keyboard
    Internet Speed
    1Gb Up / 1Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    WiFi 6e / Bluetooth 5.1 / Facial Recognition / Fingerprint Sensor / ToF (Time of Flight) Human Presence Sensor
@denis Well, I can't make the /XA:SH switch to work, which is consistent with what I generally read on the net. The RoboCopy 'list script' works well, though.

@hsehestedt Thanks for the caution, but I have already 2 backup files on the backup medium (and I have 2 more backup media, each with the 2 backup files). The 2 backup files that are already on the backup medium are from File History and Direct Copy. I am presently testing Macrium and RoboCopy to add more backup files on the backup medium/media. If one backup on one backup medium fails to restore, then there are still the other backups on that one backup medium. Moreover, there are the other backup media.

I like the /MIR switch in RoboCopy to prevent backing up junk. File History is really good in keeping snapshots every hour. In the same vein, here is hoping that I can create synergy between various backup methods.
--------------------
To people who might pooh pooh Direct Copy: if this most basic copy and paste no longer work, then nothing else (like running backup software) will work. I consider Direct Copy an excellent last ditch fall back method. (And I don't really care about OS and apps all that much, I can always restore them, even on a different machine, if need be)
 

My Computer

System One

  • OS
    Windows 10 Pro
I note in your example, that you use a 'list script' too. Are those items the only ones that you are interested in in backing up

It does not matter much these days but I started using scripts of that pattern years ago when lots of applications put their own subfolders inside My documents. So I picked out the specific ones I wanted to back up; all my own folders are within the listed ones.

I should have mentioned /XA:SH as being additional to /XD C:\Users\%UserName%\AppData not instead of it.
- /XA stops SH files being copied - such as desktop.ini files
- /XD stops folders being copied
My brain must have started melting as I typed.

By the way, one of the benefits of RoboCopy that has not cropped up in our conversation is that it preserves file created dates. This can be a handy property sometimes if you are trying to sort out a disaster.

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
You confuse me, so what are the switches in the option string, like this?

SET options=/R:2 /W:20 /XD /XA:SH

I am still in a testing mode/mood :)
 

My Computer

System One

  • OS
    Windows 10 Pro
You need to specify which folder your /XD applies to e.g.

SET options=/R:2 /W:20 /XA:SH /XD C:\Users\%UserName%\AppData

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Still does not work. Among other things, RoboCopy now tries to copy
C:\Users\%Username%\Local Settings and gets stuck doing so. I don't want to get into known issues with RoboCopy, that's what it appears to be from my readings on the net.

The RoboCopy 'list script' works well, though, and that's what I am going to use for evaluating how it will complement my other backup methods, thanks again (y)
 

My Computer

System One

  • OS
    Windows 10 Pro
That must have been a mistype because there is no such folder as C:\Users\%Username%\Local Settings
Are you saying that it's now trying to copy C:\Users\%Username%\AppData\Local? I don't see how.

Whilst I use the 'list script' for my main Documents backups, I use /XD all the time for other backups and have not seen any problems with it.

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
RoboCopy now tries to copy C:\Users\%Username%\Local Settings and gets stuck doing so....
there is no such folder as C:\Users\%Username%\Local Settings
No, it's not a folder, 'Local Settings' is a Junction, put there for compatibility with software written for older versions of Windows. The Junction points to C:\Users\%Username%\AppData\Local. I use the Robocopy option /XJD to exclude copying junctions.

1646957944116.png

1646958166654.png

By default RoboCopy follows a junction or symbolic link and copies the target that it points to. That's all very well unless the target itself contains a junction point. It's possible for that to become an infinite loop! I hit (and dealt with) that problem years ago while updating my own backup batch file from using XCopy to using RoboCopy.

Bree said:
The other problem I had was an infinite recursion (well, until the maximum path length was exceeded) of particular folders on the destination drive. These were caused by what look like links to 'My Music', 'My Pictures', etc. in the Documents folder. They're not links, they are Junction Points.....
https://www.tenforums.com/general-s...amilair-robocopy-post1120923.html#post1120923

If you really need to copy junctions and/or symbolic links as themselves, rather than following them to their target, then there are options for that too. Me, I just exclude them.

1646960245411.png
 
Last edited:

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Acer Aspire 3 A315-23
    CPU
    AMD Athlon Silver 3050U
    Memory
    8GB
    Graphics Card(s)
    Radeon Graphics
    Monitor(s) Displays
    laptop screen
    Screen Resolution
    1366x768 native resolution, up to 2560x1440 with Radeon Virtual Super Resolution
    Hard Drives
    1TB Samsung EVO 870 SSD
    Internet Speed
    50 Mbps
    Browser
    Edge, Firefox
    Antivirus
    Defender
    Other Info
    fully 'Windows 11 ready' laptop. Windows 10 C: partition migrated from my old unsupported 'main machine' then upgraded to 11. A test migration ran Insider builds for 2 months. When 11 was released on 5th October it was re-imaged back to 10 and was offered the upgrade in Windows Update on 20th October. Windows Update offered the 22H2 Feature Update on 20th September 2022. It got the 23H2 Feature Update on 4th November 2023 through Windows Update.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro (and all my Hyper-V VMs).

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 8GB RAM, 256GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro RTM and Insider Beta as native boot vhdx.

    My SYSTEM FIVE is a Dell Latitude 3190 2-in-1, Pentium Silver N5030, 4GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro, plus the Insider Beta, Dev, and Canary builds as a native boot .vhdx.
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Dell Lattitude E4310
    CPU
    Intel® Core™ i5-520M
    Motherboard
    0T6M8G
    Memory
    8GB
    Graphics card(s)
    (integrated graphics) Intel HD Graphics
    Screen Resolution
    1366x768
    Hard Drives
    500GB Crucial MX500 SSD
    Browser
    Firefox, Edge
    Antivirus
    Defender
    Other Info
    unsupported machine: Legacy bios, MBR, TPM 1.2, upgraded from W10 to W11 using W10/W11 hybrid install media workaround. In-place upgrade to 22H2 using ISO and a workaround. Feature Update to 23H2 by manually installing the Enablement Package. Also running Insider Beta, Dev, and Canary builds as a native boot .vhdx.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro (and all my Hyper-V VMs).

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 8GB RAM, 256GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro RTM and Insider Beta as native boot vhdx.

    My SYSTEM FIVE is a Dell Latitude 3190 2-in-1, Pentium Silver N5030, 4GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro, plus the Insider Beta, Dev, and Canary builds as a native boot .vhdx.
Wow, I have not encountered any Junctions when robocopying 'real' user folders like Documents, Pictures, Desktop, etc. These 'real' user folders are the only things I am interested in in backing up.

Is there a possibility that they might contain Junctions or other snags sometime in the future?

Robocopy can do more than copy, but it should not come at too high a price.
 

My Computer

System One

  • OS
    Windows 10 Pro
There is a good tutorial on sevenforums (yes it works in 10 and 11) that may help.

Also Microsoft's Robocopy Syntax can be found here robocopy
 

My Computers

System One System Two

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    Self built
    CPU
    Ryzen 9 5900X
    Motherboard
    Asus X570 ROG Crosshair Viii Hero
    Memory
    G Skill 32 GB DDR4-3600
    Graphics Card(s)
    EVGA RTX 3080 FTW3 Ultra
    Sound Card
    Creative Sound Blaster Zx
    Monitor(s) Displays
    Asus ROG Swift 165Hz 256X1440/ 2x 1920X1080
    Screen Resolution
    2560X1440 165 Hz
    Hard Drives
    2 X 1 TB NVME drives
    1 X Samsung 500 GB NVME
    PSU
    EVGA 850
    Case
    Phanteks Eclipse P400A
    Cooling
    EVGA 280mm AIO
    Keyboard
    Logitech G510s
    Mouse
    Logitech G502
    Internet Speed
    24/1
    Antivirus
    ESET Smart Security/Malwarebytes/Superantispyware
    Other Info
    Sennheiser PC37X Headset
  • Operating System
    Windows 10 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Self built
    CPU
    i7-8700K
    Motherboard
    Asus Maximus Apex
    Memory
    16Gb DDR4-3200
    Graphics card(s)
    EVGA 1080 TI FTW3
    Sound Card
    Soundblaster ZX
    Monitor(s) Displays
    27" X3
    Screen Resolution
    2560x1440
    Hard Drives
    2X Samsung M.2 SSD
    PSU
    EVGA 1000W
    Cooling
    Evga 280mm CLC
    Mouse
    G502
    Keyboard
    G510s
Well, to recap:

The objective is to mirror contents of the Users folder to an external SSD.
--------------------
What works
robocopy.exe C:\Users\Me\Documents D:\MeMirror\Documents switches
robocopy.exe C:\Users\Me\Pictures D:\MeMirror\Pictures switches
etc.
--------------------
What does not work
robocopy.exe C:\Users\Me D:\MeMirror there is no switch to exclude the AppData folder
--------------------
In my previous post (#30) I asked whether this happy circumstance (the 'list script' works, and it works well) will continue in the future. That's perhaps an unreasonable question, because we are not in the fortune-telling biz :eek1:

I am still evaluating robocopy, the issue now is not so much syntax anymore, but finding ways if alarms can be set if a robocopy run does not 100% succeed, then finding ways how robocopy can best complement my other backup methods, etc (y)
 

My Computer

System One

  • OS
    Windows 10 Pro
whether this happy circumstance (the 'list script' works, and it works well) will continue in the future

All I can say is that I've been using that method for well over a decade and that, whilst MS do change some commands with different versions, RoboCopy is still the same in Windows 11.

finding ways if alarms can be set if a robocopy run does not 100% succeed

Yes. You can check RoboCopy's "Exit code" [also generally called its "ErrorLevel"].
Robocopy Exit Codes - SS64 ***
ErrorLevel is a variable that is, in effect, set by the processing of commands. Most commands have their own pattern of ErrorLevel usage. In general, an ErrorLevel of 0 means there were no errors.

I'll just look around for a ready-made simple example then add it to this post.
There are examples in the SS64 guide.

One of my own examples [using source & destination variables defined earlier in my script]
Code:
ROBOCOPY %SourceFolder% %DestFolder% /E /MIR /DCOPY:DAT /R:10
If %errorlevel% LEQ 3 GoTo ContinueBackup
Echo RoboCopyErrorLevel is %errorlevel%, 0-3 are OK but this is not.
Pause to swear about life's unfairness.
GoTo EndBackup

:ContinueBackup
:: This is where whatever else is being done gets done

:EndBackup
:: Pause to check proceedings during testing by removing the ::


In fact, I do not end the backup if RoboCopy fails. I make it return to the first line of the example shown and run through it six times before it is treated as a failure.
- We have not discussed a further refinement, use of the /MT switch. This is how many "threads" of data processing are run in parallel to allow the command to progress quickly [since the computer's capability for data processing far outstrips its disks' ability to supply the data]. The default is 8 threads.​
- I start off using 32 threads and halve that at each repeated try until it reaches 1 [which means the disks are setting the limit of data processing speed].​
- Only one of my computers ever needs to get down to 1 but having that capability allows me to start the backup then make a pot of Earl Grey and not bother coming back until it is all expected to be over.​

*** I've been using ErrorLevel 3 as my decision level with RoboCopy [since WinXP, I think]. In checking the link still worked, I read their article again and I cannot see why I chose that instead of ErrorLevel 2. I just cannot see any logic in my choice.


Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Denis, I looked at the Exit Codes, and I am afraid that I am too unsophisticated to make the most efficient use of it. I would most likely just re-run the whole batch file.

In that sense, I added the /LOG: and /LOG+: switches and the log file contains something like the following. Note that it is the log of a re-run (just minutes after a previous re-run) hence the 0 copies. But the thing is that the log flags failures (in the second column from the right) and that's good enough for unsophisticated me.

ScreenShot.JPG

What I don't like is that the log is lodged in C:\Windows\System32 whereas I prefer to have the log in the root of external SSD where the batch file is also located. How do I do that?
 

My Computer

System One

  • OS
    Windows 10 Pro
You can set the log up for anywhere you want. See that SS64 guide - Robocopy - SS64
Their example is /LOG:C:\batch\RoboLog.txt

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Yeah, I found it (on my own, even, I am getting the hang of it, LOL) you can specify the location of the log file like /LOG:D:\MIRROR_LOG.TXT in the first command and in subsequent commands /LOG+:D:\MIRROR_LOG.TXT to have the entire log in one big log file.

Next is how to make robocopy best work together with my other backup methods (Direct Copy, File History, Macrium) But that's largely up to me, my work habits, and my specific system, I guess.

Thanks again, Denis (y) and to all who responded (y)

Edit: Oops, the emoji automaton strikes with the colon D
 

My Computer

System One

  • OS
    Windows 10 Pro
You can set the log up for anywhere you want. See that SS64 guide - Robocopy - SS64
Their example is /LOG:C:\batch\RoboLog.txt

Denis

If I can add my two cents to the expert advice other members have given, instead of /LOG use /UNILOG, in order to log correctly any weird looking file names (very useful for us, non-english speaking people, but definitely useful to everybody!)
 

My Computer

System One

  • OS
    Windows 11 Pro x64
    Computer type
    Laptop
    Manufacturer/Model
    DELL Precision 3560
    CPU
    Intel® Core™ i7-1165G7 (Tiger Lake)
    Motherboard
    DELL 004N73 / UEFI Ver. 1.18.1
    Memory
    SK Hynix 16GB DDR4 3200MHz SDRAM
    Graphics Card(s)
    intel® iRIS® Xe Graphics / NVIDIA T500 2GB GDDR6 SDRAM
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1920x1080 IPS
    Hard Drives
    Internal: KIOXIA BG4 Series 512 GB PCIe® NVMe™ M.2 SSD
    External: 2 x WD Passport 2TB USB 3.0, 1 x Toshiba 500GB USB 3.0
    Keyboard
    Standard laptop backlit keyboard with numeric keypad
    Mouse
    hp wheel mouse
    Browser
    MS Edge Chromium
    Antivirus
    MS Windows Defender
    Other Info
    DELL USB slim Optical Drive DW316
    Macrium Reflect v8 (backup and.... lifesaver)
And one final thing, now that I read carefully the entire thread.

The /MIR switch prevails over the /S one, as it includes it. i.e. by specifying /MIR you don't need /S as /MIR will traverse the entire directory tree and it will include Empty directories either way!
Please test it, before making it final.
 

My Computer

System One

  • OS
    Windows 11 Pro x64
    Computer type
    Laptop
    Manufacturer/Model
    DELL Precision 3560
    CPU
    Intel® Core™ i7-1165G7 (Tiger Lake)
    Motherboard
    DELL 004N73 / UEFI Ver. 1.18.1
    Memory
    SK Hynix 16GB DDR4 3200MHz SDRAM
    Graphics Card(s)
    intel® iRIS® Xe Graphics / NVIDIA T500 2GB GDDR6 SDRAM
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1920x1080 IPS
    Hard Drives
    Internal: KIOXIA BG4 Series 512 GB PCIe® NVMe™ M.2 SSD
    External: 2 x WD Passport 2TB USB 3.0, 1 x Toshiba 500GB USB 3.0
    Keyboard
    Standard laptop backlit keyboard with numeric keypad
    Mouse
    hp wheel mouse
    Browser
    MS Edge Chromium
    Antivirus
    MS Windows Defender
    Other Info
    DELL USB slim Optical Drive DW316
    Macrium Reflect v8 (backup and.... lifesaver)
Incorporating the latest feedback, this is the status of my script. I welcome further feedback! It already works, but further optimization can't be bad :D
:: This robocopy script mirrors the contents of the Users folder Haydon to the Haydon folder on the external D: drive. :: Change the name of the external drive to D: if need be. :: Mirror means copy and delete. :: The Haydon folder on the external drive holds a full mirror along with file security info like file creation date, etc. :: IMPORTANT: Check the log file ROBOLOG on the D: drive after running the script for any failures :: /B :: copy files in Backup mode :: /MIR :: MIRror a directory tree :: /R:n :: number of Retries :: /W:n :: Wait time between retries in seconds :: /LOG: :: Output specified LOG file at specified location, the first command line has no + , subsequent command lines have the + , to append and consolidate the logs in one big log file. :: pause :: keeps the CLI window open after running the script, useful for debugging purposes robocopy.exe C:\Users\Haydon\Documents D:\Haydon\Documents /B /MIR /R:2 /W:20 /LOG:D:\ROBOLOG.txt robocopy.exe C:\Users\Haydon\Pictures D:\Haydon\Pictures /B /MIR /R:2 /W:20 /LOG+:D:\ROBOLOG.txt :: add command lines for additional folders to mirror :: pause :: IMPORTANT: Use script at your own risk, folks!
 

My Computer

System One

  • OS
    Windows 10 Pro
Maybe you should also consider adding the /XJ switch, to avoid following the junction points (particularly for directories) and thus copying the contents twice.
For instance in the Documents folder there are 3 hidden 'folders' (actually junctions) called 'My Pictures', 'My Music' and 'My Videos'. These are kept for backwards compatibility and they point to the corresponding folders 'Pictures', 'Music' and 'Videos'. If you don't include the /XJ switch these three folders will be copied twice. Once from their original location and a second time from the junction point within 'Documents'. That will result to waist of space and waist of time in each run.


Update: My sincere apologies for duplicating Bree's comment.
Sorry @Bree, hadn't seen it.
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Pro x64
    Computer type
    Laptop
    Manufacturer/Model
    DELL Precision 3560
    CPU
    Intel® Core™ i7-1165G7 (Tiger Lake)
    Motherboard
    DELL 004N73 / UEFI Ver. 1.18.1
    Memory
    SK Hynix 16GB DDR4 3200MHz SDRAM
    Graphics Card(s)
    intel® iRIS® Xe Graphics / NVIDIA T500 2GB GDDR6 SDRAM
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1920x1080 IPS
    Hard Drives
    Internal: KIOXIA BG4 Series 512 GB PCIe® NVMe™ M.2 SSD
    External: 2 x WD Passport 2TB USB 3.0, 1 x Toshiba 500GB USB 3.0
    Keyboard
    Standard laptop backlit keyboard with numeric keypad
    Mouse
    hp wheel mouse
    Browser
    MS Edge Chromium
    Antivirus
    MS Windows Defender
    Other Info
    DELL USB slim Optical Drive DW316
    Macrium Reflect v8 (backup and.... lifesaver)

Latest Support Threads

Back
Top Bottom