Start-VEPSQLDatabaseRestore
Short Description
Restores a backed-up PostgreSQL database.
Product: Veeam Backup & Replication
Product Edition: Enterprise, Enterprise Plus, Veeam Universal License
Syntax
|
Start-VEPSQLDatabaseRestore [-Database] <VEPSQLDatabase> [[-DatabaseName] <String>]
[[-ToPointInTimeUTC] <DateTime>] [-LinuxCredentials <VEPSQLLinuxCredential>] [-ServerName <String>]
[-SshPort <Int32>] -PostgreSqlCredentials <VEPSQLInstanceCredentials> [-TargetPort <Int32>] [-Force] [<CommonParameters>] |
Detailed Description
This cmdlet restores a backed-up PostgreSQL database to a Linux-based server.
Parameters
Parameters
|
Parameter
|
Description
|
Type
|
Required
|
Position
|
Accept Pipeline Input
|
|
Database
|
Specifies a PostgreSQL database that you want to restore.
Note that this parameter accepts a single database only.
Accepts the VEPSQLDatabase object. To get this object, run the Get-VEPSQLDatabaseReturns backed-up PostgreSQL databases. cmdlet.
|
VEPSQLDatabase
|
True
|
0
|
True (ByValue)
|
|
DatabaseName
|
Specifies a name for the restored PostgreSQL database on the target location. The database will be restored with the specified name.
|
String
|
False
|
1
|
True (ByValue)
|
|
Force
|
Defines that the cmdlet will replace the target PostgreSQL database with the database from the backup.
Note: The cmdlet will show no prompt before executing the command.
|
SwitchParameter
|
False
|
Named
|
False
|
|
LinuxCredentials
|
Specifies Linux credentials. The cmdlet will use these credentials to connect to the target PostgreSQL server.
Accepts the VEPSQLLinuxCredential object. To get this object, run the New-VEPSQLLinuxCredentialCreates a Linux credential record to connect to a target PostgreSQL server. cmdlet.
|
VEPSQLLinuxCredential
|
False
|
Named
|
True (ByValue)
|
|
PostgreSqlCredentials
|
Specifies PostgreSQL role credentials for authenticating to PostgreSQL on the target machine.
Accepts the VEPSQLInstanceCredentials object. To get this object, run the New-VEPSQLInstanceCredentialsCreates a PostgreSQL credential object to authenticate to a PostgreSQL database. cmdlet.
|
VEPSQLInstanceCredentials
|
True
|
Named
|
True (ByValue)
|
|
ServerName
|
For restore to another server.
Specifies DNS name or IP address of the target PostgreSQL server. The cmdlet will restore a PostgreSQL database to that server.
|
String
|
False
|
Named
|
False
|
|
SshPort
|
Specifies the SSH port number. The cmdlet will use this port to connect to the Linux machine.
Default: 22
|
Int32
|
False
|
Named
|
False
|
|
TargetPort
|
Specifies the port to connect to the target PostgreSQL instance.
|
Int32
|
False
|
Named
|
False
|
|
ToPointInTimeUTC
|
Specifies the point in time in the UTC format within a restore interval of the PostgreSQL instance.
The cmdlet will restore the database to the state of the specified point in time.
If you do not use this parameter, the cmdlet will restore the database to the point in time when the restore point for which you started the restore session was created.
|
DateTime
|
False
|
2
|
True (ByValue)
|
<CommonParameters>
This cmdlet supports Microsoft PowerShell common parameters. For more information on common parameters, see the About Common Parameters section of Microsoft Docs.
Output Object
The cmdlet returns the VEPSQLDatabaseRestore object that contains information about the restore process for the PostgreSQL database.
Examples
Example 1. Restoring PostgreSQL Database to Latest State
|
This example shows how to restore a backed-up PostgreSQL database to its latest state on the selected restore point. The restore operation will start with the following settings:
- The cmdlet will use PostgreSQL peer authentication credentials for the current Linux OS user.
- The cmdlet will restore the database to the point in time when the restore point for which you started the restore session was created.
- The cmdlet will restore the database to the original PostgreSQL server, with the original name.
|
$session = Get-VEPSQLRestoreSession
$database = Get-VEPSQLDatabase -Session $session[0] -Name "IT"
$creds = New-VEPSQLInstanceCredentials -UseLinuxUserForPeerAuthentication
$restore = Start-VEPSQLDatabaseRestore -Database $database -PostgreSqlCredentials $creds |
Perform the following steps:
- Run the
Get-VEPSQLRestoreSessionReturns active restore sessions started to perform operations with backed-up PostgreSQL instances. cmdlet. Save the result to the $session variable.
The cmdlet will return an array of active restore sessions. Note the ordinal number of the necessary restore session. In this example, it is the first restore session in the array.
- Run the
Get-VEPSQLDatabaseReturns backed-up PostgreSQL databases. cmdlet. Set the $session variable as the Session parameter value. Specify the Name parameter value. Save the result to the $database variable.
- Run the
New-VEPSQLInstanceCredentialsCreates a PostgreSQL credential object to authenticate to a PostgreSQL database. cmdlet. Provide the UseLinuxUserForPeerAuthentication parameter to create credentials that use the current Linux OS user for PostgreSQL peer authentication. Save the result to the $creds variable.
- Run the
Start-VEPSQLDatabaseRestore cmdlet. Set the $database variable as the Database parameter value. Set the $creds variable as the PostgreSqlCredentials parameter value. Save the result to the $restore variable to be able to use it with other cmdlets.
|
Example 2. Restoring PostgreSQL Database to Point-in-Time State
|
This example shows how to restore a backed-up PostgreSQL database to a point-in-time state on the selected restore point. The restore operation will start with the following settings:
- The cmdlet will use custom Linux credentials to connect to the target Linux machine.
- The cmdlet will use SQL credentials for authenticating to PostgreSQL on the target server.
- The cmdlet will restore the database to a point-in-time state on the selected restore point.
- The cmdlet will restore the database to another PostgreSQL server.
|
$session = Get-VEPSQLRestoreSession
$database = Get-VEPSQLDatabase -Session $session[0] -Name "IT"
$time = Get-Date -Date "2026-06-24 13:00:00"
$timeutc = $time.ToUniversalTime()
$securepassword = Read-Host -Prompt "Enter password" -AsSecureString
$linuxcredentials = New-VEPSQLLinuxCredential -Account "wells" -Password $securepassword -ElevateAccountToRoot
$sqlcred = Get-Credential
$postgresqlcredentials = New-VEPSQLInstanceCredentials -SQLCredentials $sqlcred
$restore = Start-VEPSQLDatabaseRestore -Database $database -DatabaseName "Inventory" -ToPointInTimeUTC $timeutc -ServerName srv01.tech.local -LinuxCredentials $linuxcredentials -PostgreSqlCredentials $postgresqlcredentials -SshPort 23 -TargetPort 5555 |
Perform the following steps:
- Run the
Get-VEPSQLRestoreSessionReturns active restore sessions started to perform operations with backed-up PostgreSQL instances. cmdlet. Save the result to the $session variable.
The cmdlet will return an array of active restore sessions. Note the ordinal number of the necessary restore session. In this example, it is the first restore session in the array.
- Run the
Get-VEPSQLDatabaseReturns backed-up PostgreSQL databases. cmdlet. Set the $session variable as the Session parameter value. Specify the Name parameter value. Save the result to the $database variable.
- Run the
Get-Date cmdlet. Specify the Date parameter value to set the point in time to which the database must be restored. Save the result to the $time variable.
- Convert the scheduled time to the UTC format using the
ToUniversalTime() method. Save the result to the $timeutc variable.
- Run the
Read-Host cmdlet. Specify the Prompt parameter value. Provide the AsSecureString parameter. Save the result to the $securepassword variable.
- Run the
New-VEPSQLLinuxCredentialCreates a Linux credential record to connect to a target PostgreSQL server. cmdlet. Specify the Account parameter value. Set the $securepassword variable as the Password parameter value. Provide the ElevateAccountToRoot parameter. Save the result to the $linuxcredentials variable.
- Run the
Get-Credential cmdlet to create a credential object. Enter PostgreSQL credentials that will be used for authenticating to PostgreSQL on the target server. Save the result to the $sqlcred variable.
- Run the
New-VEPSQLInstanceCredentialsCreates a PostgreSQL credential object to authenticate to a PostgreSQL database. cmdlet. Set the $sqlcred variable as the SQLCredentials parameter value. Save the result to the $postgresqlcredentials variable.
- Run the
Start-VEPSQLDatabaseRestore cmdlet. Specify the following settings:
- Set the
$database variable as the Database parameter value.
- Specify the
DatabaseName parameter value.
- Set the
$timeutc variable as the ToPointInTimeUTC parameter value.
- Specify the
ServerName parameter value.
- Set the
$linuxcredentials variable as the LinuxCredentials parameter value.
- Set the
$postgresqlcredentials variable as the PostgreSqlCredentials parameter value.
- Specify the
SshPort parameter value.
- Specify the
TargetPort parameter value.
Save the result to the $restore variable to be able to use it with other cmdlets.
|
Related Commands