Backing up User Homes on Windows with Powershell

If you want to backup an entire windows system Veeam Endpoint free is your best friend, but if you want to Backup only the users actual data (their home folder) your options are a bit more limited there are lots of programs that do this but sometimes installing yet another program on a computer to do something seemingly small as this just seems redundant, for things like that scripts are awesome.

I wrote a quick script that works for me to do this, Robocopy is a great built in tool for windows that allows you to generate a report of what successfully copied.  The way I’v used it is to make a copy of a users home folder and copy it to an external source that that user has access to.  This script does not require admin rights and runs as the user which allows it to be run as a startup script and is super versatile.

### Azulpine User Home Folder Backup Script
### Changes in this version: target of backups was changed so that the backups now point to the users home directory
### Created by Austin Janey on 6/13/17
### This script is designed to backup the users home folder on logon and send the logs of the backup job to the backup location's log folder.

### Creating the file in the users shared folder so that we have a place to dump the log files
mkdir \\\DATA\U\$env:UserName\Backup
mkdir \\\DATA\U\$env:UserName\Backup\logs

### Editing this determines what is backed up
robocopy "C:\Users\$env:UserName" "\\\DATA\U\$env:UserName\Backup" /E /XA:SH /XD /log:\\\DATA\U\$env:UserName\Backup\logs\newlogfile.txt "Appdata" "My Music" "PrintHood" "MY Pictures" "My Documents" "Recent" "Searches" "Saved Games" "Templates" "SendTo" "NetHood" "Local Settings" "My Videos" "Cookies" "Application Data" "Dropbox" "Start Menu" /XF /R:1 /W:5 *.pst *.vir *.js *.jar *.jse *.lnk *.LOG1 *.exe *.msi *.DAT

### Timestamps the log file produced by robocopy by renaming it with the timestamp
Rename-Item \\\DATA\U\$env:UserName\Backup\logs\newlogfile.txt "$env:UserName-$((get-date).toString('backup_dd-MM-yyyy')).txt"

### moves the log to the logs folder in the U drive
Move-Item \\\DATA\U\$env:UserName\Backup\logs\"$env:UserName-$((get-date).toString('backup_dd-MM-yyyy')).txt" \\\DATA\U\logs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s