Mirror a folder automatically?

8,832

Mirror a folder automatically?

Let's cay I store some really important stuff in C:\User\Rahul\Desktop\IMP.

Is it possible to make windows automatically mirror the contents of that folder to C:\Users\Rahul\OneDrive\IMP constantly or at the end of every hour/week/minute?

Robocopy Script Example

(Look over options to ensure all is set for your needs)

SET SRC="C:\User\Rahul\Desktop\IMP"
SET DEST="C:\Users\Rahul\OneDrive\IMP"
SET FName=*.*
SET LOG=C:\Path\Log.txt
::   If you do not want a log file, remove the "/LOG+:%LOG%" below
SET OPT=/PURGE /S /NP /R:5 /LOG+:%Log% /TS /FP
SET CMD=robocopy %SRC% %FName% %DEST% %OPT%
%CMD%

Scheduling for Unattended Automation

Refer to my answer Scheduled Tasks for the options, gotchas, etc. you'll want to select when scheduling a batch script with Task Scheduler to run as expected; screen shots and all are provided.


Further Resources and Reading

Share:
8,832

Related videos on Youtube

undo
Author by

undo

Updated on September 18, 2022

Comments

  • undo
    undo over 1 year

    Let's say I store some really important stuff in C:\User\Rahul\Desktop\IMP.

    Is it possible to make windows automatically mirror the contents of that folder to C:\Users\Rahul\OneDrive\IMP constantly or at the end of every hour/week/minute?

    • Jonno
      Jonno over 8 years
      You could set up a scheduled task with RoboCopy
    • Syberdoor
      Syberdoor over 8 years
      Keep in mind that if it's about a backup you don't want to mirror it. Mirroring means if you accidentally delete the source file the backup one will be deleted on the next sync..... This will also happen in LMFAO_A_JOKE answer because of the /PURGE parameter
  • Vomit IT - Chunky Mess Style
    Vomit IT - Chunky Mess Style over 8 years
    @RahulBasu Just to touch on the comments above, yes, the /PURGE switch will purge from destination what doesn't exist on source but it'll MIRROR the locations as you stated. Having data redundancy is not a replacement for data backups so the assumption is you'll also have your source data backed up to tape, etc. as well based on your need. If it's a mirrored copy you're looking for on a Windows system then Robocopy is the way to go, the link in the resources and reading shows full details of all switches, etc. so feel free to adjust or let me know if you have questions.