To create the AfterBackup.bat batch file:
- 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.
- Name the file AfterBackup.bat, and save it in the *ConfigMgrInstallPath*
\inboxes\smsbkup.box folder
**************************************************************************************************
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.]
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
Script Ref: http://smsug.ca/blogs/garth_jones/archive/2011/01/13/afterbackup-bat.aspx
You've got Source_Server and Destination_Server backwards!
ReplyDeleteOops i didnt notice that. Thanks for intimating that. I have corrected the script. Keep visiting, I value your comments.
Delete@ECHO OFF
ReplyDeleteCLS
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ::
:: Creating Alternate "Son" BackupSet Monday through Sunday every week ::
:: Iteration: Monday through Sunday ::
:: Backup Horisont: 1 Week/Last backup ::
:: ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SetLocal
Set SourceDir1="D:\Drift\Backup\ConfigMgr_Site_Backup"
Set TargetDir1="\\CPH-SCCM01\d$\Drift\Backup\_ConfigMgrDB_Backup"
REM Set TargetDir1="D:\Drift\Backup\_ConfigMgrDB_Backup"
Set SourceDir2="\\CPH-SCCM01\Soft$\Apps"
Set TargetDir2="\\CPH-SCCM01\d$\Drift\Backup\_ConfigMgr_Software_Backup"
Set Archiver=D:\Drift\Tools\7-Zip\7z.exe
:: Getting the current day of the week for the Iteration TimeStamp
FOR /F "tokens=1 delims= " %%a IN ('echo %date%') DO set Iteration=%%a
::------------------------------------------------------------------------------------------------------------
:: Delete DB Backups older than 3 days.
NET USE X: \\CPH-SCCM01\D$
Forfiles -p X:\Drift\Backup\_ConfigMgrDB_Backup\ -s -m *.* -d -3 -c "cmd /C del @PATH" 1>NUL 2>&1
NET USE X: /d /y
:: Creating Backuparchive with ireration - SiteDB
"%Archiver%" a -mx9 -t7z -r "%TargetDir1%\ConfigMgr DB Backup %Iteration%.7z" "%SourceDir1%\LABBackup"
::------------------------------------------------------------------------------------------------------------
:: Delete Software Backups older than 3 days.
NET USE X: \\CPH-SCCM01\D$
Forfiles -p X:\Drift\Backup\_ConfigMgr_Software_Backup\ -s -m *.* -d -3 -c "cmd /C del @PATH" 1>NUL 2>&1
NET USE X: /d /y
:: Creating Backuparchive with ireration - Software
"%Archiver%" a -mx9 -t7z -r "%TargetDir2%\ConfigMgr Software Backup %Iteration%.7z" "%SourceDir2%"
::------------------------------------------------------------------------------------------------------------
EndLocal
GOTO EOF
:EOF
Jeg har set en masse af disse AfterBackup.bat, men manglede en der havde iteration. det her script er mit bud på en fornuftig løsning :o)
ReplyDeleteThanks for your valuable comment with the script. I'll try your script in my lab and let you know my feedback here.
Delete