Robocopy command: Copy only New / Changed files (Sync both the drive)

robocopy command

Robocopy is a command line tool and available free with the download Windows Resource Kit. It is an external command that is available in the below operating systems.

Windows NT , Windows 2000 , Windows Server 2008 , Windows Vista, Windows 7 & Windows XP.

Download Robocopy Command Line Tool for Windows 2003 and 2008 Server / Windows XP / Vista / 7 from following path:

microsoft.com/en-us/download/details.aspx?id=17657


Install the rktool.exeand follow the following steps to copy new and changed files only.

Start > Run > type cmd and press enter to open command prompt window.


Type robocopy /? to get to know about feature provided by Robocopy command line tool. Here i have marked all the feature with grey color and highlighted some feature which i have used to sync my d: drive to destination drive in which the data has to be copied.

C:\>robocopy /?         // Help for any command

Following command i have used to sync my folders and files.

C:\>robocopy "D:\Folder1" "H:\BackupFolder1"  
/E /ZB /X /PURGE /COPYALL /TEE /LOG:E:\Copy_from_HD_to_Ext_HD.log

Meaning of switches used in above command explained below.

/E :: copy subdirectories, including Empty ones.      

/ZB :: use restartable mode; if access denied use Backup mode.

/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).

/PURGE :: delete dest files/dirs that no longer exist in source.

/X :: report all eXtra files, not just those selected.

/TEE :: output to console window, as well as the log file.

/LOG:file :: output status to LOG file (overwrite existing log).

Above command will sync your data from source to destination it means if you have deleted some data from your hard drive then it will also remove from destination drive. I have made it to sync my data, if you don’t want to delete any files from destination drive then don’t use /PURGE option.

Some More Examples:

robocopy c:\folder1 c:\folder2 *.txt

In this example all .txt files would be copied from folder1 directory to folder2 directory. 

robocopy c:\folder1 c:\folder2 

In this example all files would be copied from folder1 to folder2 but not directories.

robocopy c\:hope c:\hope2 /e

In this example all files and folders (including empty ones) will be copied from folder1 to folder2 directory.

Copy all the files from source and delete all files from source drive but don’t delete folder.

C:>robocopy "E:\source" "E:\destination" /E /ZB /MOV /COPYALL

——————————————————————————-
ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
——————————————————————————-

Started : Tue May 21 10:17:22 2013

Source : E:source
Dest : E:destination

Files : *.*

Options : *.* /S /E /COPYALL /MOV /ZB /R:1000000 /W:30

——————————————————————————

3    E:source
100%        New File                1709        Copy from Ext-HD to HD.bat
100%        New File                2711        Copy from HD to Ext-HD.bat
100%        New File                 643        update.bat

——————————————————————————

Total    Copied   Skipped  Mismatch    FAILED    Extras
Dirs :         1         0         1         0         0         0
Files :         3         3         0         0         0         0
Bytes :     4.9 k     4.9 k         0         0         0         0
Times :   0:00:00   0:00:00                       0:00:00   0:00:00

Speed :               40504 Bytes/sec.
Speed :               2.317 MegaBytes/min.

Ended : Tue May 21 10:17:22 2013

C:>

You may also like:

How to install HP LaserJet 1010 driver in Win7

How to get machine serial number, product number using command prompt

160 Run commands for Windows

SiteGround Black Friday Sale Below Banner

Get Free Blogging Tips & Technology updates in your Email !!!

Subscribe via RSS feed

The following two tabs change content below.
Anil Kumar
IT Blogger Tips focus on Blogging Tips, SEO Tips, Social Media, SQL Tips, PL/SQL Tips, Oracle DBA, Linux/Unix, Latest Technology, How Tos and Technical Solutions. You can find us on Facebook | Twitter |
Find on Google+

  • annakram

    Nice post.Another software alternative that works is “LongPathTool” for error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long, the source or destination file may be in use and many other file managing errors.

    • Thanks for sharing about this tool..

  • Ron Cash

    I want to then have “Data Files RC” in “C:\Laptop Backups” zipped with date on end of the file
    so there will be:

    C:\Laptop Backups\
    Data Files RC 9_22_2014.zip
    Data Files RC 9_23_2014.zip
    Data Files RC 9_24_2014.zip
    Data Files RC 9_25_2014.zip

    Then I want to look at the earliest date in the “C:\Laptop Backups” directory based on the created date,
    not the date added to the file name, and delete any zipped files older than 14 days. So in the
    example above, I want to get the created date for “Data Files RC 9_25_2014.zip” then count back 14 days
    and delete all zipped files older than 14 days.

    I want to use the earliest file date, because if I am on vacation or just not paying attention
    and the system fails, then the delete will not continue deleting files based on todays date.
    If I do not catch this then it would eventually delete all backups.

    So if something fails but the delete is still working it would only delete from 14 days back from
    the point of failure, i.e. so say after 9-26-2014 the copy option is not working, but the
    delete is kicking in, then only 14 days back from 9-25-2014 would be deleted, then also on 9-27-2014 it would
    still only delete from 9-25-2014 14 days back, instead of using 9-27-2014. This then would always have 14 days worth
    of backups from 9-25-2014 back.

    Maybe this is not an issue, but I do have a routine that deletes based on todays date, then I have a separate
    backup software, which I just found was failing, so it occured to me that the delete batch routine that I put in Windows
    scheduler would have eventually deleted all my backups.

    So what is the best way to avoid this, can robocopy be set to look at the earliest file date, then delete older files
    based on that or is there a some other script or combination thereof?

    • I hope so, let me do it myself before writing about it.

  • wahid haq

    I suggest everyone to try “Long Path Tool” program.
    It’s really work for me.

Siteground SALE
70% OFF SiteGround WordPress Hosting – $2.95/month (Exclusive Offer !!!)