# Querying and Restoring Data and Log Backup Images on UNIX

You can can use the db2util.sh utility on UNIX to query, and then restore the backup images to a disk. You must be a valid DB2 user to run this DB2 utility. The CommCell user must have the browse and view capability to query DB2 backup jobs.

## Procedure

1. On the command line, use qlogin from the software_installation_directory/Base directory, and then go to the software_installation_directory/iDataAgent directory, where db2util.sh resides.

        cd $[software_installation_directory/Base]
       ./qlogin -cs $[commserve_name] -u $[commcell_user_name] -p $[commcell_login_password]
       cd $[software_installation_directory/iDataAgent]

2. On the command line, type the following command to see the script options.

       ./db2util.sh -h

   For information about the query options, the restore options, and the input file parameters, see Options and Input File Parameters.

3. On the command line, run the script to query the data or log backups.

        ./db2util.sh -q $[LOG | DATA |ALL] -d $[db2_database_name] [-s $[db2_instance_name]] [-c $[client_name]] [-i $[commvault_instance_name]] [-f $[start_time]] [-t $[end_time]]

4. On the command line, run the script to restore the backups to disk.

        ./db2util.sh -r JOB|LOG -d $[database_name] <[-j $[jobId]] | [-f $[start_log_sequence_number] -t $[end_log_sequence_number]]> [-s $[source_db2_instance_name]] [-p $[restore_directory]] [-c $[client_name]] [-n $[DPF]] [-i $[Commvault_instance_name]]

5. After the job completes, use the qlogout command.

        qlogout [-cs $[commserve]] [-all] [-tf $[tokenfile]] [-tk $[token]] [-h]

#### Examples

##### Querying the data and log backups

The following command queried both data and logs.

    # su - db2inst5
    $ cd /opt/Commvault/iDataAgent
    $ ./db2_util.sh -q $[all] -d $[testdb] -i $[Instance001]
    Input:: DBNAME=testdb INSTANCE=Instance001
    Querying Database: testdb
    QScript[QS_querydb2backup] CS[dbserve20] DB[CommServ] SP[QS_querydb2backup]
    Qscript Output:
    jobId bkupLevel NodeNumber timeStamp streams
    ----- --------- ---------- --------- -------
    2742 Full NODE0000 20130204124812 1
    2745 Incr NODE0000 20130204125352 1
    2748 Delta NODE0000 20130204125907 1
    2763 Full NODE0000 20130204133429 1

Use the following command to query both data and logs in a specific time range:

    ./db2util.sh -q $[ALL] -d $[DB2_Database_Name] [-s $[db2_instance_name]] [-c $[client_name]] [-i $[commvault_instance_name]] -f '$[04-11-2019 10:00:00]' -t '$[04-11-2019 11:00:00]'

##### Restoring to a disk

Use the following command and options to restore a backup image to a disk:

     ./db2util.sh -r JOB|LOG -d $[database_name] <[-j $[jobId]] | [-f $[start_log_sequence_number] -t $[end_log_sequence_number]]> [-s $[source_db2_instance_name]] [-p $[restore_directory]] [-c $[client_name]] [-n $[DPF]] [-i $[Commvault_instance_name]]

##### Restoring to a disk using an input file

Use the following command and options to restore a backup image to a disk by using an input file that includes all the commands.

     ./db2util.sh -a $[input_file] [-i $[commvault_instance]]

×

Loading...