-- wykonaj backup obu baz z plikami mp3
BACKUP DATABASE [PLSSUG_DEMO1]
	TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO1.bak'
	WITH INIT
GO

BACKUP LOG [PLSSUG_DEMO1]
	TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO1.trn'
	WITH INIT
GO

-- --------------------------------------------------

BACKUP DATABASE [PLSSUG_DEMO2]
	TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2.bak'
	WITH INIT
GO

BACKUP LOG [PLSSUG_DEMO2]
	TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2.trn'
	WITH INIT
GO

-- roznica jest niewielka

-- odtworzenie dziala tak samo, jak w standardowym przypadku, chyba ze musimy przeniesc pliki,
-- wtedy trzeba napisac wprost lokalizacje takze dla grupy FILESTREAM

-- taillog backup
BACKUP LOG [PLSSUG_DEMO2]
	TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2_TailLogBackup.bak'
	WITH NOFORMAT, NOINIT,
	NORECOVERY

RESTORE DATABASE [PLSSUG_DEMO2]
	FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2.bak'
	WITH FILE = 1,
	NORECOVERY

RESTORE LOG [PLSSUG_DEMO2]
	FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2.trn'
	WITH FILE = 1,
	NORECOVERY

RESTORE LOG [PLSSUG_DEMO2]
	FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2_TailLogBackup.bak'
	WITH FILE = 1



-- a teraz do innej lokalizacji; jesli chcemy zmienic polozenie plikow - musimy tez wskazac explicite dla grupy FILESTREAM,
-- inaczej bedzie zglaszac bledy
RESTORE DATABASE [PLSSUG_DEMO2a]
	FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2.bak'
	WITH FILE = 1,
	NORECOVERY,

	MOVE 'PLSSUG_DEMO2' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\PLSSUG_DEMO2a1.mdf',
	MOVE 'PLSSUG_DEMO2_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\PLSSUG_DEMO2a1_log.ldf',
	MOVE 'FS_DOCS2' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\FS_DOCS2a1'

RESTORE LOG [PLSSUG_DEMO2a]
	FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PLSSUG_DEMO2.trn'
	WITH FILE = 1