Friday 25 July 2014

Automatic Informatica Repository Backup


It is a common practice to take regular backup of Informatica repository contents, especially of Dev and Production instances so that any loss or corruption can be confronted later. But this backup activity has always been a manual headache for the administrator. If you are looking on how to get rid of the manual efforts and trying to automate the entire process, here is it. [Update 1: By process, it’s almost similar to my post on OBIEE web catalog backup which can be found here]

Strategy

The idea here is to create a shell/bash script (for Unix based) or a batch file (for Windows machines) in which you specify the path to store the backup repositories and also the username and password to connect to your Informatica domain. Eventually the script you create has to be scheduled to run as per your need. The following section would help you understand how.

The Linux/Unix Way

Write a shell script to connect to the Informatica repository service by specifying your repository name, username and password along with the domain. Let me show a sample.


#!/bin/bash

backupDirectory="/oracle/ETL_Weekly_BKP/";

backupDate=$(date +%F)

backupName=$backupDirectory"InfaRep-Dev-Bkp-"$backupDate".rep";

cd $backupDirectory;

pmrep connect -r DEV_RS -n Administrator -x Admin123 -d domain_infadev

pmrep backup -o $backupName –f

In the above snippet, you may notice the pmrep connect and pmrep backup commands which actually do the job for you. 

Explanation to the attributes follows.
-r             : Specifies that the repository name follows
-n            : To specify the username
-x            : To specify the password
-d            : To specify your domain
-o            : Output file name 

The Windows way

If you are looking to automate this activity in windows, write a batch file instead of a shell as against the previous case with the same functionality. Here is a sample one.


@ECHO OFF

SET backupDirectory=D:\\ETL_Weekly_Backup

SET backupDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

SET backupName=Infa_Dev_Backup_%backupDate%.rep

cd %backupDirectory%

C:\Informatica\9.5.1\clients\PowerCenterClient\client\bin\pmrep connect -r DEV_RS -n Administrator -x Admin123 -d domain_infadev

C:\Informatica\9.5.1\clients\PowerCenterClient\client\bin\pmrep backup -o $backupName –f

[For description on the pmrep arguments, please refer to the Linux/Unix section]

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 *.rep /D -<days> /C "cmd /c del @file"

Example: 

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

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

Scheduling the Backup Process

With the script being ready for creating backups, the next step is to schedule and set trigger at the desired time and frequency. In Linux/Unix based 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 /ETL_Weekly_BKP, the crontab entry should be something like this- 
        30 09 * * 5 /ETL_Weekly_BKP/InfaRepositoryBkp.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. for example, 30 July, 2013.
  4. Set the action to start the created batch file [InfaRepositoryBkp.bat]
There it is! Your Informatica repository will backed up automatically.

Sample Screens


 Windows Task Scheduler showing the scheduled trigger


Windows Task Scheduler with the batch file as the action 

No comments:

Post a Comment