PowerShell | Windows Backup with email notifications
We are always wanting a good solid backup in case something hits the fan and how much do we want to pay for this software? Well typically $0. Well $0 if it works! So lets have a look at wbadmin which is a builtin windows tool that uses Volume Shadow Copy Service.
Who is this aimed at? These ideas are aimed at single PC, different configured machines, small environment or part of remote monitoring system. Typically in large environment you will just have a few images on a Server that you can push to a PC whenever it is going to crap or taking to long to fix. Plus in bigger environments you have standard apps and some kind of central storage for data. Contents
1. Security One thing to bare in mind when it comes to backups is SECURITY if you make backup and just leave it anywhere someone can just access all your data. So we want secure it whether be stored on external drives with Bitlocker encryption, on network shares with EFS (Encrypted File System) and Isolated from anyone but who really needs it. so creating a backup user account just for backups. This depends on your environment and where its stored of course. But of course just think about someone stealing your backup and what that means to you and take a few mins to secure it.
2. Introduction to wbadmin From Wikipedia, the free encyclopedia https://en.wikipedia.org/wiki/WBAdmin WBAdmin (WBAdmin.exe) is a command-line utility built into Windows Vista, Windows Server 2008, Windows 7, Windows Server 2008 R2, Windows 8 and Windows Server 2012. The command is used to perform backups and restores of operating systems, drive volumes, files, folders, and applications from a command-line interface. WBAdmin is a disk based backup system. WBAdmin can create a “bare metal” backup used to restore the Windows operating system to similar OR dissimilar hardware. The Backup file(s) created are primarily in the form of Microsoft’s “Virtual Hard Disk” (.VHD) files with some accompanying .xml configuration files. The backup .VHD file can be mounted in Windows Disk Manager to view content. However, the .VHD backup file is not a direct “disk clone”.
Technet on wbadmin https://technet.microsoft.com/en-us/library/cc754015(v=ws.11).aspx
3. One Off Backups One off Backups are great for just in case your doing something huge to the system or upgrading and want the most up to date backup possible. Easy as pie. And who doesn’t like pie? Of course anytime run as from elevated Powershell or cmd for all these backup options.
One Time backup Example to d Drive. This is my favourite as to do and the -quiet means no stress.
One Time backup to network share. As well as extra folders with the -include
One Time backup to network share using a mountpoint and -noInheritAcl
4. Scheduled BackupsOkay so we want these done daily yea? Incrementally? maybe a full backup weekly? So we have two options
2. Making this a Scheduled Task. This should tickle your fancy. Of course in powershell. This is setup in a few different stages one to make a script to backup whatever you want and to make a scheduled task where you compile all the data and throw it into “Register-ScheduldedTask” at the end. FIRE UP THE ISE!!!!
Wbadmin Script and save to “C:\scripts\backup.ps1″
Scheduled Task Setup They way this actually all comes together is intresting atleast. It pays to have template saved for setting up Scheduled Tasks.
5. Scheduled Backups with Email Confirmations I have a quick blog on how to use Send-MailMessage at Powershell using Send-MailMessage to send email So the Scheduled Task Setup stays the same as before it is only the scipt that needs a bit of love. To keep it cool we will build ontop of what we have already with “C:\scripts\backup.ps1″
Thats pretty straight forward yea? But lacking in my eyes. It definitely needs some flavour. Like some logs and some information and what pc this came from. 6. Final Script. FIRE UP THE ISE!!!So lets add that flavour. The windows backup log is actually pretty poor in quality i find so we will grab.Size of backup before and after. Because if you backup isn’t growing there is something wrong.
And lets grab event logs about windows backup. Which will give you plenty of detail.
and Finally lets grab the versions from wbadmin
Simple yea? Now we format it to make it pretty and add it to the final script which is below. Copy and paste
Oh baby thats sweet like sugar!
Hope this was helpful |