This is a snippet of script I use to backup all my drives using built in windows utilities. it can be customized , just change the drive letters and paths accordingly. in this example , we are using a weekly scheduled task to execute however, by changing the maxage of the robocopy command you can make it daily (1) or every month (30) . I have 3 copies I modified, a daily which runs daily, a weekly, and a monthly. Both the weekly and the monthly have according functions to delete and clean up the back up folders each time, and the monthly copies into my main back up folder directly, updating my “pristine copy” of back up (a full backup ). Presently, these parts are a bit messy so i will post the clean up script once i convert it to a proper array and make it look a bit more elegant.
[code]Function BACKUP_C () {
$source=”C:\”
$Dest = “e:\Backup\weekly\” + (get-date).tostring(“MMddyyyy”) + “\C\”MKDIR
$Dest -Force
$loog=(“e:\Backup\” + (get-date).tostring(“MMddyyyy”) + “\C_BackUp_Log” + (get-date).tostring(“MMddyyyy”) + “.log”)
robocopy $source $Dest /R:5 /W:2 /XO /XX /s /maxage:7 /LOG:$loog
$Destu = “e:\Backup\” + (get-date).tostring(“MMddyyyy”) + “\C*”
$Destz = “e:\Backup\” + (get-date).tostring(“MMddyyyy”) + “\C_Drive_BackUp” + (get-date).tostring(“MMddyyyy”) + “.zip”
Compress-Archive -path $Destu -DestinationPath $Destz -CompressionLevel Fastest -Force
$Destd = (“e:\Backup\weekly\” + (get-date).tostring(“MMddyyyy”) + “\C”)
rm -R $Destd -Force
}
BACKUP_C[/code]





Leave a Reply