cancel
Showing results for 
Search instead for 
Did you mean: 

Script to Backup OpsCenter and Associated Config Files

David_Bowlby
Level 4

Thought i would share to all who might be able to benefit from this

Script ran through powershell does the following

Create Backup Directories for DataBase Backup and Config Files

Copies the Config files to the backup directory

Performs the DataBase Backup

Zips the files

Moves files to a Nas storage device

 

#### SCRIPT #######

$Date=(get-date).ToString('MM-dd-yyyy')
New-Item -ItemType Directory -Name "OpsCenter_Backup_$date" -Path "E:\DatabaseBackups\"
New-Item -ItemType Directory -Name "OpsCenter_DataBase_Backup_$date" -Path "E:\DatabaseBackups\OpsCenter_Backup_$date"
New-Item -ItemType Directory -Name "WebServer_Conf" -Path "E:\DatabaseBackups\OpsCenter_Backup_$date"

$Destination = "E:\DatabaseBackups\OpsCenter_Backup_$date"
$USRPro = "C:\Program Files\VERITAS\Security\Authentication\systemprofile"
$cnfg1 = "E:\Program Files\Symantec\OpsCenter\server\config"
$cnfg2 = "E:\Program Files\Symantec\OpsCenter\server\db\CONF"
$cnfg3 = "E:\Program Files\Symantec\OpsCenter\gui\webserver\conf"
$cnfg4 = "E:\Program Files\Symantec\OpsCenter\gui\Security"

Get-ChildItem -Path "E:\Program Files\Symantec\OpsCenter" -Recurse | ?{$_.Name -like "opscenter*Service.xml" } | Copy-Item -Destination $Destination
Get-ChildItem -Path "E:\Program Files\Symantec\OpsCenter\gui\webserver\webapps\opscenter" -Recurse | ?{$_.Name -like "web.xml" } | Copy-Item -Destination $destination
copy-item -Path $USRPro -Destination "$destination" -Recurse
copy-item -Path $cnfg1 -Destination "$destination" -Recurse
copy-item -Path $cnfg2 -Destination "$destination" -Recurse
copy-item -Path $cnfg3 -Destination "$destination\WebServer_Conf" -Recurse
copy-item -Path $cnfg4 -Destination "$destination" -Recurse

& 'E:\Program Files\Symantec\OpsCenter\server\bin\dbbackup.bat' "E:\DatabaseBackups\OpsCenter_Backup_$date\OpsCenter_DataBase_Backup_$date"

Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory("$destination", "$destination.zip") ;

remove-item $destination -confirm:$False -Recurse -Force

Start-Sleep 10

$DBBackupLocation = "E:\DatabaseBackups"
$BackupDestination = "\\server\OpsCenter_DB_Backups"
$BackupDate = (get-date).AddDays(-14).ToString("M/d/yyyy")
get-childitem -Path $DBBackupLocation | Where-Object {$_.LastWriteTime -lt $BackupDate} | Copy-Item -Destination $BackupDestination
Start-sleep 3
get-childitem -Path $DBBackupLocation | Where-Object {$_.LastWriteTime -lt $BackupDate} | Remove-Item -confirm:$false -recurse -force

1 REPLY 1

RiaanBadenhorst
Moderator
Moderator
Partner    VIP    Accredited Certified

Thanks for sharing this with the community.