Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 926 | Views in the last 30 days: 4
 
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

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones