# Querying and Restoring Data and Log Backup Images on Windows

You can use the db2util.ps1 utility on Windows 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.

## Before You Begin

The db2util.ps1 script works in a PowerShell version 2 environment. If your PowerShell environment is higher than version 2, type the following command at the PowerShell prompt:

    powershell -version 2

## Procedure

1. On the command line, use qlogin from the software_installation_directory/Base directory

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

2. Start the powershell prompt.

   You can type powershell from the Windows prompt or you can start it from the command line prompt.

3. Enable the powerShell script execution on the system:

        set db2instance=$[db2_instance_name]
       powershell
       powershell Set-ExecutionPolicy $[Unrestricted]

4. Type the following command to get the usage information.

        PS C:\$[software_installation_directory]\iDataAgent> db2util.ps1

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

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

        db2util.ps1 -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]]

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

        db2util.ps1 -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]]

7. 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.

    PS C:\Program Files\CommVault\ContentStore\iDataAgent> .\db2util.ps1 -q $[all] -d $[testdb30] -i $[Instance001]
    Input:: DBNAME=testdb30 INSTANCE=Instance001
    Querying Database: testdb30
    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.ps1 -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 to restore a backup image to a disk:

     db2util.ps1 -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 to use an input options file which include all the query and restore commands for execution:

     db2util.ps1 -a $[input_file] [-i $[commvault_instance]]

×

Loading...