Backing up SCCM isn’t simple. Using PowerShell though, you can create a script to backup a site server with nearly everything we need!
Using the afterbackup.bat File
Previously, I was using the afterbackup.bat file to do some post-backup tasks doing a combination of SSRS backups and daily folders. It was working great although being a batch file it was pretty rudimentary.
I decided to write a PowerShell script that did all that batch file did with the robustness that PowerShell can provide like error handling and verification. Previously, I was limited to well…uh…a batch file but now I see a whole new light.
Any good SCCM admin knows that every time the built-in Site Backup SQL maintenance task runs, the site server executes the afterbackup.bat file located in %CONFIGURATION_MANAGER_INSTALL_FOLDER%\inboxes\smsbkup.box folder.
Buiding an SCCM Backup Site Server Script
People have done all kinds of stuff with this batch file. I’m not down with batch files anymore; I’m monogamous now with my friend PowerShell. Due to my monogamy, I’m just using afterbackup.bat to launch a PowerShell script which is going to do all the work. I think I’ve come up with a pretty slick solution.
After a lot of deliberation I decided against using a SQL Server maintenance plan to backup the database. Third-party database restoration is supported now with SCCM 2012 SP1 and I’ve heard good things about this approach but it wasn’t for me. I decided to use the built-in site backup task because of a single reason; I know the restore works great.
I’ve never performed a restore via a database backed up with the maintenance plan so I’d be in uncharted water if I ever had to do another restore.
To get a solid SCCM site backup requires a few prereqs first:
- You have the Site Backup SQL Maintenance task enabled and verified to be working in your ConfigMgr site.
- You have the site backup task configured to push off the backup to a remote server. You aren’t backing it up to the site server, are you?
- You have this line in your afterbackup.bat file:
powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -FilePath %SOMEREMOTEPATH%\%POSTBACKUPSCRIPT%.PS1
Now that we have that out of the way here’s what I’ve come up with. I’ve tried to make this as robust as possible accounting for everything I can think of but if you see something that should be changed, please let me know.