I finally got tired of manually comparing directories in File Explorer to ensure my latest versions were backed up. Sometimes I would just drag-and-drop entire large directories to be "safe," but it resulted in long wait times and a lot of needless copying.

To fix this, I spent a several hours (with more than a little help from Copilot) developing a menu-driven PowerShell script. It uses RoboCopy to backup and restore only new or changed files.

The script features 8 automated options:

  1. Backup (Mirror): Syncs source to destination.
  2. Backup Mirror (Dry Run): Tests the backup without moving files.
  3. Restore (Safe): Restores files without overwriting newer versions.
  4. Restore Safe (Dry Run): Tests the restore process.
  5. Report Backup Direction: Lightweight "what would change" check for backups.
  6. Report Restore Direction: Lightweight check for restores.
  7. Diff Report (Both Directions): A verbose report comparing both source and destination.
  8. Eject Drive: Safely removes your backup media.

Key Features:

Safe Mirroring: Since the /mir command can delete files in the backup that no longer exist in the source, the script asks for confirmation before any deletions occur.

Non-Destructive Restore: The "Safe Restore" option will never accidentally overwrite a newer file with an older backup version.

Defaults: You can easily change the default source and destination paths using Notepad.

Dry Runs vs. Reports: Options 2 and 4 are true "simulation" runs of the actual jobs, while Options 5 and 6 provide lightweight reports—for quick checks on massive datasets.

I'm not sure of the rules for attachments. I attached a zip and a script might get flagged by your browser.

pritaeas commented: Nice! +17

Recommended Answers

All 9 Replies

Could be useful. Do you have any screenshots? I may try running this in a VM to test it out. To date I have been using short cmd files to run robocopy. Typically it does a /mir backup followed by a "touch.exe" on the cmd file so I can check the date/time of the last run.

Here's 2 screen shots - the backup dry run followed by the difference report. It says 7 mode but I added the 8th "Eject Drive" since ejecting a portable drive through the System Tray / Notification Area is slow. The drive to eject can be a path; it will parse out the root.

ScriptDiffReport.png

Script.png

Here's a screen shot showing the permission to delete a file in the destination that is no longer in the source.
Extra.png

The Power Shell script report didn’t properly reflect new directories. My apologies. It has been fixed in the attached. I also added some metrics: Duration, Data copied, Throughput: (MB or GB / sec), and Files/sec. I tried to make the progress bar more meaningful, but that seems to be more than me and two AI models can make happen at the moment.

PS_V2.png

Fix one thing, AI will break another. Final attachment. I'm done with Power Shell and AI coding help!

I don't know if there is an analog in PowerShell, but I wrote a pile of Python scripts as ffmpeg front ends. Instead of coding a progress bar I just call a Windows API to mofify the title bar tab text to display percentage done. It's a lot less code than a progress bar.

Great suggestion Reverend Jim! To my knowledge PowerShell doesn't have a function to modify the title bar, however, I was able to get rid of the silly progress bar and add something a bit more meaningful. Thanks. Have a great weekend.

Running RoboCopy...
Progress: 0%
Progress: 10%
Progress: 20% etc.

You can set the title text with

$host.UI.RawUI.WindowTitle = "My Title"

Sweet! Here's a version with the progress in the title bar. Thanks Jim!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.