Labels

ASP.NET (1) Data Model (1) Django (1) MDX (15) Python (3) Redshift (3) SSAS (15) SSRS (3) T-SQL (29)

Monday, 18 June 2012

Query to Backup and Restore Database

Below is the query to backup and restore a database:

BACKUP
DATABASE [Source_1] TO DISK = N'E:\Backup\Source_1.bak' WITH
NOFORMAT
, COMPRESSION
.NOINIT

,NAME  = N'Full bakup of Source_1'
, SKIP, STATS = 10
GO

--2.Optionally, determine the logical and physical names of the files in the backup set that contains the full database backup that you want to restore.
RESTORE FILELISTONLY FROM DISK = N'E:\Backup\Source_1.bak'
-- 3. Restore
RESTORE DATABASE [Source_3]FROM DISK = N'E:\Backup\Source_1.bak' WITH FILE = 1,
MOVE 'Source_1' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Source_3.mdf'
, MOVE 'Source_1_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Source_3_log.ldf',
NOUNLOAD, REPLACE,STATS = 10
GO;

No comments:

Post a Comment