Tuesday, July 14, 2015

Using AfterBackup.bat within the ConfigMgr backup process

System Center Configuration Manager provides a backup maintenance task called 'Backup Site Server' that runs on a schedule and backs up the site database, specific registry keys, and specific folders and files. This task is intended to backup key elements of the Configuration Manager site that require synchronization, or other special attention. These are however not all files needed. Microsoft advises to backup other SQL databases and ConfigMgr files as well, making sure nothing is missing. This is described here:
Backup and Recovery in Configuration Manager


You can create a AfterBackup.bat file to perform post-backup actions automatically after the backup maintenance task runs successfully. The AfterBackup.bat file is most frequently used to archive the backup snapshot to a secure location. However, you can also use the AfterBackup.bat file to copy files to your backup folder and start other supplemental backup tasks. This file must be created manually and placed in the <ConfigMgr>\Inboxes\Smsbkup folder.

The following code can be added to the file (example):
- REM @echo off
- setlocal enabledelayedexpansion
- set target=\\SCCM01\C$\AfterBackup\%date:~0,3%
- If not exist %target% goto datacopy
- RD %target% /s /q
- :datacopy
- xcopy "\\SCCM01\Backup\*" "%target%\" /E /-Y



All this does is move the backup folder to a folder named the day of the week. If the destination already exists, then it is deleted first. Resulting in 7 days of backup. I recommend using a remote location for this, not on the local server. Better safe than sorry :-)

For testing purpose, you can start: SMS_SITE_BACKUP (in services or Configuration Manager Service Manager) manually.

More information can be found on the following websites:
Step-By-Step: Testing System Center 2012 Configuration Manager Backups for Restoration
SCCM ConfigMgr 2012 Primary Site Server and Database Recovery Part 1

Update 16-7:
For it seems above information is outdated and SQL Backup is the way to do it. No ConfigMgr backup and AfterBackup.bat is needed, but it works fine if you prefer. Just make sure you have a backup plan! :)


@jarwidmark - Use SQL Backup instead for SCCM 2012.
@henkhoogendoorn - The SCCM job synchronize between DB and Site control files, which seems to be better?
@jarwidmark - Nope, that's not correct, those are not used anyway. Never, ever use the built-in SCCM backup :)
@henkhoogendoorn - FYI Step-By-Step: Testing System Center 2012 Configuration Manager Backups for Restoration
@jarwidmark - I don't agree with that post, use SQL backup instead.
@NickolajA - Since ConfigMgr 2012 SP1 was released, SQL backups would be the prefered way.
@Steve_TSQL - Yes - read this :) SQL Server Backup Recommendations for Configuration Manager
@Steve_TSQL - While that post will work, using native SQL is better. With CM 2012 SP1 and later ConfigMgr 2012 Site Backup and Recovery Overview
@ccmexec - Agreed!! SQL backup is the way to do it!

No comments:

Post a Comment