Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Restore Latest Backup with Powershell

By Luke Losli,

This script is used to restore a full backup of an existing database to a server of your choice.  If the latest full backup is not found, or if the $newBackup switch is on, a new full backup is created.  If the database already exists on the destination server, it will not be replaced.

Before running the script, set the value of the $backupFolder variable to a directory that both the source and destination SQL Server Service accounts can access.

To restore the latest backup to the same server:

.\Restore-LatestBackup.ps1 "DbName" "ServerA" "ServerA" "NewDbName"

To restore a new backup to a different server:

.\Restore-LatestBackup.ps1 "DbName" "ServerA" "ServerB" -newBackup

To use SQL Authentication:

.\Restore-LatestBackup.ps1 "DbName" "ServerA" "ServerB" "NewDbName" -newBackup -sqlAuth "sa" "p4$$w0rd"

Total article views: 992 | Views in the last 30 days: 1
 
Related Articles
FORUM

SQL Server Backup & Restore startergies

SQL Server Backup & Restore startergies

FORUM

Backup/restore

Backup/restore

FORUM

Restoring backup to remote server.

Problem with restoring backup to remote server.

FORUM

Production Server DB backup Restored on Development Server Backup

Production Server DB backup Restored on Development Server Backup

FORUM

Sql Server 2005 Backup ,restore

Sql Server 2005 Backup ,restore

Tags
powershell    
restore    
 
Contribute