Backup and Restore pt 1

 

use master

-- take a snapshot of a database without truncating any logs

backup database ReportBuilderTraining 
	TO DISK='c:\backups\ReportBuilderTraining_20170601_1020.bak' WITH COPY_ONLY

-- check contents of a backup

restore FILELISTONLY 
	FROM DISK = 'c:\ReportBuilderTraining\ReportBuilderTraining.bak'

-- restore database
--
-- You can find default location for the files by right clicking on the server in SSMS, select properties and
-- select "Database Settings" on the left
use master

RESTORE DATABASE ReportBuilderTraining
	FROM DISK = 'c:\ReportBuilderTraining\ReportBuilderTraining.bak'
	WITH REPLACE, 
	MOVE 'ReportBuilderTraining' TO  'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\ReportBuilderTraining.mdf',
	MOVE 'ReportBuilderTraining_log' TO  'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\ReportBuilderTraining_log.LDF'