--SQL Full Back declare @Current datetime; declare @dateStr varchar(50); declare @dir varchar(max); set @Current = getDate(); set @dateStr = CONVERT(varchar(10), @Current, 120) set @dir = 'z:\backup\backupTest' + @dateStr + '.bak' BACKUP DATABASE backupTest TO DISK=@dir WITH INIT -- SQL DIFFERENTIAL backup declare @Current datetime; declare @dateStr varchar(50); declare @dir varchar(max); set @Current = getDate(); set @dateStr = CONVERT(varchar(10), @Current, 120) set @dir = 'z:\backup\backupTest_Diff' + @dateStr + '.bak' BACKUP DATABASE backupTest TO DISK= @dir WITH DIFFERENTIAL, INIT --SQL log backup declare @Current datetime; declare @dateStr varchar(50); declare @dir varchar(max); set @Current = getDate(); set @dateStr = convert(varchar(10), @Current, 112) + convert( varchar(2),DATEPART(HOUR, @Current)); set @dir = 'z:\backup\backupTest' + @dateStr + '.trn' BACKUP LOG backupTest TO DISK=@dir WITH INIT --SQL restore BACKUP LOG backupTest TO DISK='z:\backup\backupTest_Tail.trn' WITH NO_TRUNCATE ALTER DATABASE backupTest SET OFFLINE WITH ROLLBACK IMMEDIATE GO RESTORE DATABASE backupTest FROM DISK='z:\backups\backupTest2014-11-04.bak' WITH REPLACE, NORECOVERY RESTORE DATABASE backupTest FROM DISK='z:\backup\backupTest_Diff2014-11-04.bak' WITH NORECOVERY RESTORE LOG backupTest FROM DISK='z:\backup\backupTest2014110417.trn' WITH NORECOVERY GO RESTORE LOG backupTest FROM DISK='z:\backup\backupTest_Tail.trn' WITH NORECOVERY GO RESTORE DATABASE backupTest WITH RECOVERY GO
2015-10-05
SQL Server Backup and Restore
Reference:
Step-by-Step Approach to Differential Backup and Recovery
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment