Tuesday, March 13, 2012

Backup the SCCM Backup with AfterBackup.bat

It's always better and a preventive thought to Backup the Daily SMS/SCCM Backup, (keeping a daily copy on the server & mirroring the backups to an alternate server). I have seen people trying to add custom scripts in Scheduled tasks to copy/move the Backup data to a Remote server. But in the process of SCCM's daily backup (visible in smsbkup.log), there's an 'AfterBackup.bat' file used to perform post-backup actions automatically after the Backup Site Server maintenance task runs successfully. By default, the AfterBackup.bat batch file does not exist. To use it, you must first create the batch file and add commands.

To create the AfterBackup.bat batch file:
  1. Prepare an ASCII file with commands that archive your backup snapshot, run a third-party archive tool, or perform any other post-backup tasks your site requires.
  2. Name the file AfterBackup.bat, and save it in the *ConfigMgrInstallPath*\inboxes\smsbkup.box folder
Here is a simple script for 'AfterBackup.bat' written by 'Garth Jones', which saves 7 days backup to a folder named the day of the week, and also deletes/overwrites the older ones.

************************************************************************************************** 
REM @echo off
Setlocal enabledelayedexpansion
Set target=\\Destination_Servername\E$\Primary_SCCM_Backup\%date:~0,3%
If not exist %target% goto datacopy
RD %target% /s /q
:datacopy
xcopy "\\Source_Servername\SCCM_BackupPath\*" "%target%\" /E /-Y
***************************************************************************************************
where, *Source_Server is the Primary Server from which the backup has to be copied,
and *Destination_Server is the Remote Server where you want to copy the SiteBackup.

* You can also replace the word 'copy' to 'move' if you want to move the files instead of copy.
* You can also remove the part "\%date:~0,3%" from the script if you only require present day's backup. In my case we were running out of space on one backup server to save 7 days stuff, hence i removed that date part on the script.


[Although the intended use of AfterBackup.bat is to archive SMS backup snapshots, you can use that file for other tasks that you need to perform at the end of every back up operation, such as: 
  • Run a SQL Server DBCC test to verify that there are no integrity problems with the SMS site database.
  • Run a site health tool, or other health tools.]
Update: I have created a simple document with snapshots on how to implement the AfterBackup.bat script in your SCCM infrastructure. Click the below link to download the document for reference.

Backing up SCCM Backup - Download Link - https://sites.google.com/site/ucrajee/welcome/attachments/Backing%20up%20SCCM%20Backup.pdf?attredirects=0&d=1


Process Ref: http://technet.microsoft.com/en-us/library/cc180424.aspx
Script Ref: http://smsug.ca/blogs/garth_jones/archive/2011/01/13/afterbackup-bat.aspx

Monday, March 12, 2012

COPY, XCOPY, and MOVE Command lines

http://support.microsoft.com/kb/240268
    or
Start -- Run -- Cmd -- copy /?
Start -- Run -- Cmd -- xcopy /?
Start -- Run -- Cmd -- move /?

General Syntax for finding Command line parameters for any .exe or .msi file:
Start -- Run -- Cmd -- "filename.exe / ?"

Start -- Run -- Cmd -- "filename.msi / ?"

This command will generally give you all the command lines and/or silent switches for any .exe or .msi file.

Note that if the command line parameters are not added in the installers (mostly custom installers), then it won't result anything.