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;
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