SCP Daily Maintenance Scripts
For anyone who read my long rant from last week about my adventures in back and restore of SCP, I believe the last thing I had mentioned was that I was putting to use the knowledge I had gain from those adventures into building some maintenance scripts. I figured I would share these with other SCP users.
***DISCLAIMER - Use these scripts and information at your own risk - neither myself or my employer will be held responsible for any outcome of any sort - past, present or future - that results from the use of these or any derivatives.***
Script 1 - SCP_Backup_Cleanup.vbs
This script, when scheduled to run daily, will remove all SCP backups older than 7 days from the backup folder. You can adjust the sBackupsFileFolder variable as required to fit your system. You can use the remarked out schtasks to create the daily scheduled task from the command prompt. You may want to change the /ru from "System" to another user account. Also, with the way the schtasks command is written below, it will schedule the task to run daily at 12:01 am.
- ' scp_backup_cleanup.vbs
' Dean Colpitts / 2013.03.01
' schtasks /create /tn "Daily SCP Backup Cleanup" /sc daily /st 00:01:00 /tr "'C:\Windows\System32\cscript.exe' /b C:\ManageEngine\SupportCenter\bin\scp_backup_cleanup.vbs" /ru "System"
sBackupsFileFolder = "C:\SCP Backups\Integrated Backups"
Dim oFSO, oFolder, oFiles
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sBackupsFileFolder)
Set oFiles = oFolder.Files
For each BackupFile in oFiles
If InStr(BackupFile.Name, "SupportCenter") > 0 Then
If Datediff("D", BackupFile.DateLastModified, Date) > 7 Then
oFSO.DeleteFile BackupFile
End If
End If
Next
Set oFiles = Nothing
Set oFolder = Nothing
Set oFSO = Nothing
Script 2 - SCP_7z_Backup.vbs
This script, when scheduled to run daily, will stop the Windows service "ManageEngine SupportCenter Plus", then using heavy compression, 7-Zip the folder C:\ManageEngine to the folder/file location specified in the variable "OutputFile". The script then restarts the "ManageEngine SupportCenter Plus" service. The "OutputFile" will be appended with the date/time the backup started, your backup file ends up as this:
SupportCenter 7-Zip Backup - YYYY.MM.YY - HH.MM.SS.7z
I would advise making sure your output location of both this file and any backups you perform using backUpData.cmd resides outside of C:\ManageEngine, otherwise you'll end up with pretty large 7-Zip files. In my case, I copied the backUpData.bat to backUpData_custom.bat and set BACKUP_DIR="C:\SCP Backups\Integrated Backups". You can also utilize a modified copy of scp_backup_cleanup.vbs to clean up these backups as well (I did not include a copy of my script for that here since it almost identical to my first script above). The included (but remarked out) schtasks will set this script to run daily at 12:20 am. Don't forget that SupportCenter will be unavailable to users while this script is running.
- 'SupportCenter Plus 7-Zip Backup Script
'Dean Colpitts 2013.03.01
'schtasks /create /tn "Daily SCP 7-Zip Backup" /sc daily /st 00:20:00 /tr "'C:\Windows\System32\cscript.exe' /b C:\ManageEngine\SupportCenter\bin\SCP_7z_Backup.vbs" /ru "System"
'
'This script will stop the ManageEngine service before making a 7-Zip file
'containing C:\ManageEngine (including sub-folders), then restart the service
'
'
BackupDate = Right(String(2,"0") & Year(Now()),4) & "." & Right(String(2,"0") & Month(Now()),2) & "." & Right(String(2,"0") & Day(Now()),2) & " - " & Right(String(2,"0") & Hour(Now()),2) & "." & Right(String(2,"0") & Minute(Now()),2) & "." & Right(String(2,"0") & Second(Now()),2)
OutputFile = "" & chr(34) & "C:\SCP Backups\7z Backups\SupportCenter 7-Zip Backup - " & BackupDate & ".7z" & chr(34)
CommandLine = "" & chr(34) & "C:\Program Files\7-Zip\7Z.exe" & chr(34)
InputFiles = "" & chr(34) & "C:\ManageEngine\" & chr(34)
Switches = "a -ms -mx=9 -mmt -md=28"
ServiceName = "" & chr(34) & "ManageEngine SupportCenter Plus" & chr(34)
Set objShell = CreateObject("Wscript.Shell")
str7zCommand = "" & CommandLine & chr(32) & Switches & chr(32) & Outputfile & chr(32) & InputFiles
Wscript.Echo
Wscript.Echo "Now stopping" & chr(32) & ServiceName & chr(32) & "service."
Wscript.Echo "Please wait..."
objShell.Run "net stop /y" & chr(32) & ServiceName, 1, true
WScript.Sleep(10000)
Wscript.Echo
Wscript.Echo "Now creating" & chr(32) & OutputFile
Wscript.Echo "Please wait..."
objShell.Run str7zCommand, 1, true
WScript.Sleep(10000)
Wscript.Echo "Now starting" & chr(32) & ServiceName & chr(32) & "service."
Wscript.Echo "Please wait..."
objShell.Run "net start" & chr(32) & ServiceName, 1, true
Script 3 - Access_Logfile_Cleanup.vbs
This script deletes any C:\ManageEngine\SupportCenter\server\default\log\localhost_access*.* files older than 7 days. You may not wish to prune you logs quite so much, but we use BackupExec 2012 with De-duplication to disk, which we keep for 1 year, so I don't really need more than 7 days of logs on the server - and they can grow quite large. Although looking at this now, there are some log and text files in there that are growing large, so I may need to prune them daily as well.
- 'SupportCenter Plus Log Pruning Script
'Dean Colpitts 2013.03.01
'schtasks /create /tn "Daily SCP Log Pruning" /sc daily /st 00:03:00 /tr "'C:\Windows\System32\cscript.exe' /b C:\ManageEngine\SupportCenter\bin\access_logfile_cleanup.vbs" /ru "System"
sLogFileFolder = "C:\ManageEngine\SupportCenter\server\default\log"
Dim oFSO, oFolder, oFiles
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sLogFileFolder)
Set oFiles = oFolder.Files
For each LogFile in oFiles
If InStr(LogFile.Name, "localhost_access") > 0 Then
If Datediff("D", LogFile.DateLastModified, Date) > 7 Then
oFSO.DeleteFile LogFile
End If
End If
Next
Set oFiles = Nothing
Set oFolder = Nothing
Set oFSO = Nothing
On my SCP server, I have the following maintenance items in my scheduled task list:
- Daily backup of SCP, using the built in (but customized to redirect to a different folder outside of C:\ManageEngine) backUpData.bat
- Daily backup of SCP using the SCP_7z_Backup.vbs script from above
- Daily pruning / purge of access logs
- Daily pruning / purge of SCP backups (as a result of backUpData.bat)
- Daily pruning / purge of SCP 7-Zip backup
- Daily reboot of Windows every morning at 4:30 am.
Finally - just for comparison, my C:\ManageEngine folder is approximately 1.16 GB in size. The average file size of a backup created using backUpData.bat is 197MB and takes approximately 2m30s to create. The average file size of my 7-Zip backup files (containing all of C:\ManageEngine) are 267MB, and it takes approximately 7m30s to create the 7-Zip backup. I'm sure I could speed up the 7-Zip backup if changed the compression to be a little lighter. We don't have much of a call or use for SCP in the middle of the night, so I am willing to trade the time in the outage window for less disk usage.
Best of luck and I hope this helps at least of you out there in the future.
dcc
New to ADSelfService Plus?