Thursday 11 June 2015

How to automate OBIEE Web Catalog Backup in Unix and Windows machines

 Automated OBIEE Web Catalog Backup

OBIEE Web Catalogs are regularly backed up for fail-safe and restoration purposes against a corruption or when some inconsistency occurs due to internal or external factors. But the backup activity is usually carried out manually and thus needs an administrator’s efforts to create backups periodically.

I see a way by which we can automate this activity pretty quickly and easily. A small script in Unix or a batch file in Windows can create Web Catalog backups automatically and periodically thus avoiding the manual efforts involved in this activity. 

All that you need to get this process automated is, create a shell/bash script (for Unix based) or a batch file (for Windows machines) to say where your web catalog resides and where would you like to store the backup files. Then the script you create has to be scheduled as per your need. Now let’s see how.

Creating a Unix Script for Web Catalog Backup

You can write your own script where you mention the Catalog path and its name, the name you want to use for archives, backup directory, etc. Here is a sample one that suffixes the backup date to the catalog archive file so as to help us identify the backup chronologically and easily.

#!/bin/bash
#Assigning the Name of the catalog
catalogName="EnterpriseBusinessAnalytics";

#Assigning the catalog path
catalogPath="Oracle/fmw/instances/instance1/bifoundation/OracleBIPresentationServicesComponent/coreapplication_obips1/catalog/"$catalogName;

#Assigning the Backup directory
backupDirectory="/OBIEE_WebCat_Bkp/";

#Extracting the date to suffix with the archive name
backupDate=$(date +%F);
backupName=$catalogName"_"$backupDate".zip";

cd $backupDirectory;
#Creating the backup using Zip
zip -r $backupName $catalogPath >> CatalogBackup.log;
#if zip doesn’t work, try other utilities like tar or gzip

Creating a Batch file for Web Catalog Backup

A small batch file can be created to set the catalog name and path, backup file name, directory and path where the backups are to be stored. Here is a sample script to accomplish this.

@ECHO OFF
SET catalogName=EnterpriseBuisnessAnalytics
SET catalogPath=C:\\Oracle\\fmw\\instances\\instance1\\bifoundation\\OracleBIPresentationServicesComponent\\coreapplication_obips1\\catalog\\%catalogName%
SET backupDirectory=D:\\OBIEE_Catalog_Backup
SET backupDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
SET backupName=%catalogName%_%backupDate%.zip
cd %backupDirectory%
zip -r %backupName% %catalogPath% >> CatalogBackup.log

Auto-Delete Old Backups

As the script will keep creating backups periodically, we would end up having too many backups eating the disk space extensively though we require only one or two latest archives. Again manual intervention is needed to clean them up retaining only the latest ones. To avoid this, you may simply add another line to your script for deleting the old backups based on the desired retention duration.
If you opted for Unix scripting, you may add the following line at the end of your shell file.

find <Backup Directory> -mtime +<days> -exec rm {} \;

This statement simply finds the files inside the <Backup Directory> whose last modified date is greater than the number of days specified by <days>. For example, if you want your backup to be retained only for 15 days, your script would look like:

find $backupDirectory -mtime +15 -exec rm {} \;

In case you take windows approach, you may add this statement.
 
forfiles -p <backup directory>  -m *.zip /D -<days> /C "cmd /c del @file"

Example: 

 forfiles -p %backupDirectory%  -m *.zip /D -15 /C "cmd /c del @file"

For more information on ‘forfiles’, you may check here.

Scheduling the Backup Activity

Now that we are ready with the script for creating backups, the next step is to schedule them to trigger at the desired time and frequency. In Unix machines, you can make use of “crontab” to schedule your utility. On a Windows, just a basic task in the “task scheduler” should serve the purpose. The following sections show you how, in case it sounds new to you.

On UNIX based machines


     
     
  1. After creating the script, it has to be scheduled in the Unix server where the backup you intend to automate.
  2. Login to the Unix server as the user with which the backups are to be taken and open the terminal shell.
  3. Type the command: crontab –e
  4. In the editor that opens, set the desired time, frequency of backup and the backup script as shown below.
  5. If you would like to create a backup every Friday at 09:30 AM and the script you created is under /OBIEE_Weekly_BKP, the crontab entry should be something like this- 
        30 09 * * 5 /OBIEE_Weekly_BKP/OBIEECatalogBkp.sh

     6. Save and close the crontab editor. [To save and quit, use Esc :wq!]

For further reading or understanding on crontab, you may check here.

On Windows


  1. Go to Task Scheduler
  2. Create a task or basic task
  3. Set the trigger with the desired frequency of backup. As per our example, 10 June, 2010.
  4. Set the action to start the created batch file [OBIEECatalogBkp.bat]
There you go! Your web catalog backup activity is now automated.




Screenshots follow. 

Windows Task Scheduler showing the scheduled trigger

Windows Task Scheduler with the batch file as the action
 

1 comment: