So....
The SCOM MP uses a powershell script to do the acutal backup so that was the first thing to look at.
param ($targetFilePath, $DeleteDate)
#Initializing the SCSM 2010 Powershell Snapin
add-pssnapin "SMCMDLetSnapin" -ErrorVariable errSnapin ;
#Create TargetDir if it doesn't exist
if (test-path $targetFilePath)
{
"Folder Exists"
}
else
{
md "$targetFilePath"
}
#Remove old backups
$xDays = (Get-Date).addDays($DeleteDate)
Get-ChildItem $targetFilePath -Recurse | where {$_.lastWriteTime -le $xDays} | Remove-Item -recurse -force
#Create new backup dir
md "$targetFilePath\MP_$((get-date).toString('yyyyMMdd'))"
#Backup unsealed MP's
Get-SCSMManagementPack|where-object {! $_.Sealed}|Export-SCSMManagementPack -Directory "$targetFilePath\MP_$((get-date).toString('yyyyMMdd'))"
Running this as so: "powershell.exe mpbackup.ps1 C:\MPBackup -30" (assuming the above code is saved as mpback.ps1) tells the script to backup all unsealed MP's to the C:\MPBackup directory in a dir called MP_currentdate and purge all dir's older than 30 days.
Really, if you wanted, this could just be setup as a scheduled task on the management server and left to run. Functional, but boring.
So I thought I'd place it into a management pack as a workflow.
The only bit of the PowerShell I've changed is to remove the following:
param ($targetFilePath, $DeleteDate)
#Initializing the SCSM 2010 Powershell Snapin
add-pssnapin "SMCMDLetSnapin" -ErrorVariable errSnapin ;
The Param and the add-pssnapin isn't needed as I've used the script properties tab within the workflow designer of the authoring tool.
This ends up with a very simple (can it get simpler?) workflow that just runs the PowerShell script.
Benefits of doing it as an MP rather than a scheduled task? Not much, but I wanted to have a play. The only thing really is that you can now keep an eye on the workflow status from within the console.
I've attached the MP and related files, open it up in the Authoring tool and set the schedule, backup location and purge time to your preferences and have a play.
I'd liked to have setup some CI's and a view that could be used within the console to set the backup location and purge time, but it doesn't seem to want to let me choose a class property as a value. Given some more time I might have another go, but this is just purely as a quick play for me.
One interesting thing to note however. I noticed that after setting this up as a workflow the following is logged in the event log:
This is basically saying that the workflow service account doesn't have permissions to export the management packs, however... it works!!! So I'm not quiet sure what's going on there, an error to say it's denied and yet it succeeds.
*Update - 18/11/2010 * The errors seen in the event log were actually a result of the workflow account not being in the Administrators group within Service Manager. The account should be in this group as per Microsoft's documentation: http://technet.microsoft.com/en-us/library/ff461084.aspx
MP Files download here: http://cid-d130da82a6555249.office.live.com/self.aspx/.Public/BackupMP.zip
2 comments:
Nice one Steve,
I was just about to do as you have done and then saw this, happy days!
Can I suggest that you post it for the community at systemcentercentral.com as well?
Cheers,
Aengus
Hi Aengus,
I'll try and pop a post on soon, just been stupidly busy recently.
Cheers,
SB
Post a Comment