Restore-VESQLIRDatabase

In this article

    Short Description

    Performs instant restore of backed-up Microsoft SQL Server databases.

    Applies to Veeam Backup & Replication

    Product Edition: Enterprise, Enterprise Plus, Veeam Universal License

    Syntax

    Restore-VESQLIRDatabase [-Database] <VESQLDatabase> -SwitchOverOptions <VESQLIRSwitchOverOptions> [-DatabaseName <string>] [-ServerName <string>] [-InstanceName <string>] [-Port <int>] [-SqlCredentials <pscredential>] [-UseSQLAuthentication] [-GuestCredentials <pscredential>] [-ToPointInTimeUtc <datetime>] [-TargetFolder <string>] [-File <VESQLDatabaseFile[]>] [-TargetPath <string[]>] [-Force] [<CommonParameters>]

    Detailed Description

    This cmdlet performs instant restore of backed-up Microsoft SQL Server databases. You can restore databases to the original location or to another location. For details, see the Instant Recovery section of the Veeam Explorers Guide.

    Parameters

    Parameter

    Description

    Type

    Required

    Position

    Accept Pipeline Input

    Database

    Specifies a Microsoft SQL Server database. The cmdlet will restore this database.

    Accepts the VESQLDatabase type. To get this object, run the Get-VESQLDatabase cmdlet.

    True

    0

    True (ByValue)

    SwitchOverOptions

    Specifies a switchover option: automated, manual or scheduled.

    Accepts the VESQLIRSwitchOverOption type. To get this object, run the New-VESQLIRSwitchOverOptions cmdlet.

    True

    Named

    True (ByValue)

    DatabaseName

    For restore to another location.

    Specifies a name for the restored SQL Server database. The cmdlet will restore the database with the specified name.

    String

    False

    Named

    False

    ServerName

    For restore to another location.

    Specifies a name of a target SQL Server server. The cmdlet will restore the database to the specified target server.

    String

    False

    Named

    False

    InstanceName

    For restore to another location.

    Specifies a name of a target SQL Server instance. The cmdlet will restore an SQL Server database to the specified target instance.

    String

    False

    Named

    False

    Port

    Specifies a port number that will be used to connect to the target SQL Server.

    Int32

    False

    Named

    False

    SqlCredentials

    Specifies SQL Server credentials to authenticate against a target SQL Server.

    Note: If you do not specify SQL Server credentials, the cmdlet will use current account credentials. If these credentials do not work, the cmdlet will use credentials specified in the backup job.

    PSCredential

    False

    Named

    False

    UseSQLAuthentication

    Defines that the cmdlet will use the SQL Server authentication to connect to the target SQL Server instance.

    Note: If you omit this parameter, the cmdlet will use credentials specified in the SqlCredentials parameter to connect to both the SQL Server and to the guest OS.

    SwitchParameter

    False

    Named

    False

    GuestCredentials

    Specifies credentials to authenticate against the target SQL Server. If these credentials do not work, the cmdlet will use credentials, specified in the backup job.

    Note: If you omit this parameter, the cmdlet will use credentials specified in the SqlCredentials parameter or current account credentials to connect to both the SQL Server and to the guest OS.

    PSCredential

    False

    Named

    False

    ToPointInTime

    Specifies the point in time within a restore interval of an SQL Server database.

    The cmdlet will restore the database to the state of the specified point in time.

    Datetime

    False

    Named

    False

    TargetFolder

    For restore of SQL Server database files to specific location.

    Specifies the folder. The cmdlet will restore all database files to that folder.

    Note: This parameter is not available if you use the TargetPath parameter.

    String

    False

    Named

    False

    File

    Specifies an array of file names for Microsoft SQL Server databases.

    Accepts the VESQLDatabaseFile[] type. To get this object, run the Get-VESQLDatabaseFile cmdlet.

    False

    Named

    False

    TargetPath

    Specifies a target path array. The cmdlet restores SQL Server database files to locations, specified in the target path array.

    Note:

    • For every database file, you must assign the specific file path.
    • This parameter is not available if you use the TargetFolder parameter.

    String[]

    False

    Named

    False

    Force

    Defines that the cmdlet will overwrite an existing SQL Server database with a database from a backup.

    Note: The cmdlet will show no prompt before executing the command.

    SwitchParameter

    False

    Named

    False

    <CommonParameters>

    This cmdlet supports Microsoft PowerShell common parameters. For more information on common parameters, see the About Common Parameters section of Microsoft Docs.

    Examples

    Restore-VESQLIRDatabaseExample 1. Performing Instant Restore of Microsoft SQL Server Databases to Original Location and Configuring Scheduled Switchover

    This example shows how to perform instant recovery of the SQLDatabase database to the original location using the switchover option. The cmdlet will perform the switchover at 13:00:00 on 2020-11-24.

    $time = Get-Date -Date "2020-11-24 13:00:00"

    $TimeUtc = $time.ToUniversalTime()

    $ScheduledSwitch = New-VESQLIRSwitchOverOptions -Scheduled -SwitchingTimeUtc $TimeUtc

    $session = Get-VESQLRestoreSession

    $database = Get-VESQLDatabase -Session $session[0] -Name "SQLDatabase"

    Restore-VESQLIRDatabase -Database $database -SwitchOverOptions $ScheduledSwitch

    Perform the following steps:

    1. Run the Get-Date cmdlet. Specify the Date parameter value to set the time when the switchover must be performed. Save the result to the $time variable.
    2. Convert the scheduled time to the UTC format using the ToUniversalTime() mehod. Save the result to the $TimeUtc variable.
    3. Run the New-VESQLIRSwitchOverOptions cmdlet. Provide the Scheduled parameter and specify the SwitchingTimeUtc parameter value. Save the result to the $ScheduledSwitch variable.
    4. Run the Get-VESQLRestoreSession cmdlet. Specify the Session and Name parameter values. Save the result to the $session variable.

    The Get-VESQLRestoreSession cmdlet will return an array of restore sessions. Mind the ordinal number of the necessary restore session (in our example, it is the first restore session in the array).

    1. Run the Get-VESQLDatabase cmdlet. Specify the Session and Name pameter values. Save the result to the $database variable.
    2. Run the Restore-VESQLIRDatabase cmdlet. Set the $database variable as the Database parameter value. Set the $ScheduledSwitch variable as the VESQLSwitchOverOptions parameter value.

    Restore-VESQLIRDatabaseExample 2. Performing Instant Recovery of Microsoft SQL Server Databases to Specific Folder and Switching Over Manually

    This example shows how to restore the SQLDatabase01 database files to the latest restore point with the following settings:

    • The cmdlet will restore the database to the localhost target server.
    • The cmdlet will restore the database to the SQLExpress instance.
    • The cmdlet will restore the database with the TableDatabase2020 name.
    • The cmdlet will restore the database to the C:\ folder.
    • To perform the switchover operation manually, you must run the Switch-VESQLIRDatabase cmdlet.

    $restore = Get-VBRApplicationRestorePoint -Id E4786E49-D943-4E27-80C2-C99A059CBB27

    $session = Start-VESQLRestoreSession -RestorePoint $restore

    $db = Get-VESQLDatabase -Session $session[1] -Name "SQLDatabase01"

    $ManualSwitch = New-VESQLIRSwitchOverOptions -Manual

    Restore-VESQLIRDatabase -Database $db -SwitchOverOptions $ManualSwitch -ServerName localhost -InstanceName "SQLExpress" -DatabaseName "TableDatabase2020" -TargetFolder "C:\"

    $irDatabase = Get-VESQLIRDatabase -DatabaseName "SQLDatabase01"

    Switch-VESQLIRDatabase -Database $irDatabase

    Perform the following steps:

    1. Run the Get-VBRApplicationRestorePoint cmdlet. Specify the ID parameter value. Save the restore point to the $restore variable.
    2. Run the Start-VESQLRestoreSession cmdlet. Specify the RestorePoint parameter value. Save the restore point to the $session variable.

    The Get-VESQLRestoreSession cmdlet will return an array of restore sessions. Mind the ordinal number of the necessary restore session (in our example, it is the first restore session in the array).

    1. Run the Get-VESQLDatabase cmdlet. Specify the RestorePoint and Name parameter values. Save the restore point to the $db variable.
    2. Run the New-VESQLIRSwitchOverOptions cmdlet. Provide the Manual parameter. Save the result in the $ManualSwitch variable.
    3. Run the Get-VESQLDatabase cmdlet. Set the $session variable as the Session parameter value. Specify the Name parameter. Save the result to the $database variable.
    4. Run the Get-VESQLDatabaseRestoreInterval cmdlet. Set the $database as the Database parameter value. Save the result to the $restoreinterval variable.
    5. Run the Restore-VESQLDatabase cmdlet with the $database variable. Specify the following options:
    • Set the $db as the Database parameter value.
    • Set the $ManualSwitch as the SwitchOverOptions parameter value.
    • Specify the ServerName parameter value.
    • Specify the InstanceName parameter value.
    • Specify the DatabaseName parameter value.
    • Specify the TargetFolder parameter value.
    1. Run the Get-VESQLIRDatabase cmdlet. Specify the DatabaseName parameter value. Save the result to the $IRDatabase variable.
    2. Run the Switch-VESQLIRDatabase cmdlet. Set the $IRDatabase variable as the Database parameter value.

    Related Commands

    I want to report a typo

    There is a misspelling right here:

     

    I want to let the Veeam Documentation Team know about that.