Powershell Robocopy backup script

Intro

I was looking for ways to backup my photos from my NAS to my homemade backup server so in the event the NAS stops working I would still have the latest files.

After some searching for free ways to do this I used robocopy and powershell to create the following script you can freely download the latest version from my GitHub page.

Article

Pre-reqs that it needed to be able to do:

  • Show start and endtime of the backup job
  • The duration for performance review
  • Amount of copied folders, data and skipped (if any)
  • Robocopy end-code results in case of any errors with needed catches (took a while!)
  • Source and destination address
  • Attach a log file
  • Send an e-mail to my admin account
  • Have nice feel to it

Robocopy command itself:

robocopy.exe "$src" "$dst" /mir /mt:96 /r:3 /w:3 /np /ts /bytes /xd $exclude /log:"$log"

Explanation of options used:

  • /mir tells robocopy to use mirror mode
  • /mt:96 maximum of allowed threads increasing or decreasing this results in different end-times
  • /r:3 maximum set retry count
  • /w:3 maximum set wait time before a retry is executed
  • /np shows no progress
  • /ts include the timestamp of the source file
  • /bytes display progress in bytes for easy calculation
  • /xd $exclude exclude files that set in the "$exclude" variable
  • /log:"$log" specifies the logfile location by the "$log" variable

Detailed explanation from Microsoft

Like with all scripts improvements are ongoing.

Recent additions to the script was adding HTML with a clone feel of the Veeam mail report.

I use Veeam to backup my servers and so the look & feel goes hand-in-hand with a few modifications.

An example of the output is:

 

If an error occurs the green banner changes to red as shown here:

 

If you find a better way, an improvement or have questions, objections feel free to comment below and/ or on my GitHub page.

Document

Preview not available.

Document options

Download

Gallery


Comments

Loading Comments...