Merlin Seby
asked on
script for restoring database
I want to write a script for automatically restoring the database from back-upset . can you please help me to provide that in case if someone has written it .
Thanks,
Merlin.s
Thanks,
Merlin.s
If you are using Power Shell scripting
You can find some here
https://www.red-gate.com/simple-talk/sql/backup-and-recovery/backup-and-restore-sql-server-with-the-sql-server-2012-powershell-cmdlets/
import-module sqlps
$database = "NewDb"
$backupLocation = "D:\Backups\CurrentDB.bak"
$dataFileLocation = "D:\Databases\NewDB.mdf"
$logFileLocation = "D:\Logs\NewDB_log.ldf"
$sql = @"
USE [master]
ALTER DATABASE [$database]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [$database]
FROM DISK = N'$backupLocation'
WITH FILE = 1,
MOVE N'CurrentDB' TO N'$dataFileLocation',
MOVE N'CurrentDB_log' TO N'$logFileLocation',
NOUNLOAD, REPLACE, STATS = 5
ALTER DATABASE [$database]
SET MULTI_USER
"@
invoke-sqlcmd $sql
You can find some here
https://www.red-gate.com/simple-talk/sql/backup-and-recovery/backup-and-restore-sql-server-with-the-sql-server-2012-powershell-cmdlets/
>> to backup and restore SQL server database
What in the question leads you to believe it is a SQL Server database?
What in the question leads you to believe it is a SQL Server database?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
What scripting language?
What database product?
How is the backup being performed?