Loading...

Restoring SQL Server Agent Using the Command Line Interface

Table of Contents

Log On to the CommServe

Perform the Restore

Generate the Command Line Script from the CommCell Console

Log On to the CommServe

To run command line operations, you must first login to the CommServe.

From Command prompt, navigate to <Software_Installation_Directory>/Base and run the following command:

qlogin -cs <commserve name> -u <user name>

For example, to log on to CommServe 'server1' with username 'user1':

qlogin -cs server1 -u user1

Perform the Restore

  1. Download the restore_template.xml file and save it on the computer from where the command will be executed.
  2. Execute the saved xml script using qoperation execute command.

    qoperation execute -af restore_template.xml -clientName kraken64 -instanceName kraken64 -toTimeValue "2011-11-28 15:40:00" -restoreSource ACC2 -database ACC2

  3. Verify the status of the job using the following command:

    qlist job -j jobID

  4. Once the job completes, log off from the CommServe using the qlogout command.

    qlogout [-cs <commserve_host_name>] [-all] [-tf <tokenfile>] [-tk <token>] [-h]

Out-of-Place Restore on the Same SQL Server

  1. Download the out_of_Place_restore_template.xml file and save it on the computer from where the command will be executed.
  2. In the template locate the following section and edit it as per your setup:

    <device>|DB1|#12!DB1_rename|#12!DB1|#12! E:\RestoreLocation\DB1.mdf|#12!C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\DB1.mdf </device>

    <device>|DB1|#12!DB1_rename|#12!DB1_log|#12! E:\RestoreLocation\DB1_log.ldf|#12!C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\DB1_log.ldf </device>

    Where:

    • DB1 is the backed up database name.
    • DB1_Rename is the database name you want to provide for the restored database.
    • DB1 and DB1_log are the Logical Names of the backed up database.
    • E:\RestoreLocation is the destination path where you want to restore the database.
    • C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA is the source location of the backed up database.
  3. Execute the saved xml script using qoperation execute command.

    qoperation execute –af out_of_Place_restore_template.xml -clientName ida18 -instanceName ida18 -restoreSource DB1 -database DB1 -toTimeValue "yyyy-mm-dd hh:mm:ss"

  4. Verify the status of the job using the following command:

    qlist job –j JOBID

  5. Once the job completes, logout from the CommServe using the qlogout command.

    qlogout [-cs commserver] [-all] [-tf tokenfile] [-tk token] [-h]

Out-of-Place Restore on a Different SQL Server

  1. Download the out_of_Place_restore_template.xml file and save it on the computer from where the command will be executed.
  2. In the template locate the following section and edit it as per your setup:

    <device>|DB1|#12!DB1_rename|#12!DB1|#12! E:\RestoreLocation\DB1.mdf|#12!C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\DB1.mdf </device>

    <device>|DB1|#12!DB1_rename|#12!DB1_log|#12! E:\RestoreLocation\DB1_log.ldf|#12!C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\DB1_log.ldf </device>

    Where:

    • DB1 is the backed up database name.
    • DB1_Rename is the database name you want to provide for the restored database.
    • DB1 and DB1_log are the Logical Names of the backed up database.
    • E:\RestoreLocation is the destination path where you want to restore the database.
    • C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA is the source location of the backed up database.
  3. Execute the saved xml script using qoperation execute command, for example:

    qoperation execute -af out_of_Place_restore_template.xml -clientName ida18 -instanceName ida18 -restoreSource DB1 -database DB1 -toTimeValue "yyyy-mm-dd hh:mm:ss" -destClient/clientName RUBY -destinationInstance/clientName RUBY -destinationInstance/instanceName RUBY\Instance2

  4. Verify the status of the job using the following command:

    qlist job –j JOBID

  5. Once the job completes, logout from the CommServe using the qlogout command.

    qlogout [-cs commserver] [-all] [-tf tokenfile] [-tk token] [-h]

Examples

Restoring from a Current Backup

qoperation execute -af restore_template.xml -clientName client1 -instanceName client1\instance1 -restoreSource DB1 -database DB1 –toTimeValue "yyyy-mm-dd hh:mm:ss"

Restoring Databases to a Point-in-Time (date and time)

qoperation execute -af pit_restore_template.xml -clientName client1 -instanceName client1\instance1 -restoreSource DB1 -database DB1 –toTimeValue "yyyy-mm-dd hh:mm:ss"

Restoring Database In-Place in Standby Mode

qoperation execute -af standby_inplace_restore_template.xml -clientName client1 -instanceName client1\instance1 -restoreSource DB1 -database DB2 -toTimeValue "yyyy-mm-dd hh:mm:ss" -sqlRecoverType STATE_STANDBY -renameFilesSuffix C:\UndoPath

Generate the Command Line Script from the CommCell Console

In addition to the parameter values provided in the template xml file, if you want to include additional options for the restore, you can do so by selecting the required options from the CommCell Console and generate the command line xml script for the restore operation.

For more information, see Save as Script Overview.

Last modified: 2/27/2018 2:30:46 PM