| Author |
Topic |
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-09 : 14:26:36
|
| Hi, Im trying to restore the differential backup,I have to restore the full backup first and then restore the differential backup.Can any body tell me the code for this?my program is like this--for fullbackupif type=Dbeginrestore database databasenamefrom disk=pathend--for differential backupelse if type=I??? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-09 : 14:33:25
|
| Use WITH DIFFERENTIAL in the RESTORE command to restore a differential backup. See BOL for details.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-09 : 15:06:22
|
| Do i need to restore the full backup once again?if i need to restore the full backup & differential backup my code is like this,is any thing wrong in my codealter procedure res1asdeclare @db as varchar(100)declare @path as varchar(100)declare @type as char(5)declare @bfd varchar(100) set @bfd=(select max(backup_finish_date) from resto)set @path=(select physical_device_name from resto where backup_finish_date=@bfd)set @db=(select database_name from resto where backup_finish_date=@bfd)set @type=(select typ from resto where backup_finish_date=@bfd)if @type='D'beginrestore database @dbfrom disk=@pathwith stats=10,recoveryendelse if @type='I'begin restore database @db --(i need to resotre the fullback here,is this correct????)from disk=@pathwith norecoveryrestore database @dbfrom disk=@pathwith stats=10,recoveryendelse if @type='L'beginrestore database @db --(i need to resotre the fullback here,is this correct????)from disk=@pathwith norecoveryrestore log @dbfrom disk=@pathwith stats=10,recoveryendelseprint'operation failed' |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-09 : 15:32:33
|
| You restore the full backup only once, but you must specify WITH NORECOVERY in order to apply anything after that.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-09 : 16:36:30
|
| If you don't mind,can you tell me whats wrong in my program? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-09 : 17:39:21
|
| You aren't using WITH DIFFERNTIAL for the differential restore.Rather than editing your first post with our suggestions, please submit new replies with the modified code so that our posts don't look so odd. Your first post did not originally have the WITH NORECOVERY, so my second post looks incorrect even though at the time it wasn't.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-09 : 17:59:03
|
| WITH DIFFERENTIAL is used only for backup,For restore also can we use that "WITH DIFFERENTIAL"???? |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-02-09 : 19:19:28
|
| No you can't. |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-09 : 19:25:34
|
| thnx rmiao, Is there anything wrong in my program???alter procedure res1asdeclare @db as varchar(100)declare @path as varchar(100)declare @type as char(5)declare @bfd varchar(100)set @bfd=(select max(backup_finish_date) from resto)set @path=(select physical_device_name from resto where backup_finish_date=@bfd)set @db=(select database_name from resto where backup_finish_date=@bfd)set @type=(select typ from resto where backup_finish_date=@bfd)if @type='D'beginrestore database @dbfrom disk=@pathwith stats=10,recovery,replaceendelse if @type='I'begin restore database @dbfrom disk=@pathwith norecovery,replacerestore database @dbfrom disk=@pathwith stats=10,recovery,replaceendelse if @type='L'beginrestore database @dbfrom disk=@pathwith norecovery,replacerestore log @dbfrom disk=@pathwith stats=10,norecovery,replacerestore log @dbfrom disk=@pathwith stats=10,recovery,replaceendelseprint'operation failed' |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-02-09 : 22:43:38
|
| Does it work? Got any error when run it? |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-09 : 23:12:27
|
Thanks alot to all of u for the help.I got the result finally.. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-10 : 20:51:17
|
| Sorry about misleading you about the WITH DIFFERENTIAL. I was thinking we were talking BACKUP command even though your post says RESTORE. I didn't read it close enough.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-11 : 03:07:54
|
| It's ok Tara mam.I am getting only the full backup,I am unable to restore the Differential and log backup.Can you tell me anything wrong in my code???alter procedure res1asdeclare @db as varchar(100)declare @path as varchar(100)declare @type as char(5)declare @bfd datetimedeclare @db1 as varchar(100)declare @path1 as varchar(100)declare @type1 as char(5)declare @bfd1 datetimedeclare @db2 as varchar(100)declare @path2 as varchar(100)declare @type2 as char(5)declare @bfd2 datetimeset @bfd=(select max(backup_finish_date) from resto where typ='D')set @path=(select physical_device_name from resto where backup_finish_date=@bfd)set @db=(select database_name from resto where backup_finish_date=@bfd)set @type=(select typ from resto where backup_finish_date=@bfd)set @bfd1=(select max(backup_finish_date) from resto where typ='I')set @path1=(select physical_device_name from resto where backup_finish_date=@bfd1)set @db1=(select database_name from resto where backup_finish_date=@bfd1)set @type1=(select typ from resto where backup_finish_date=@bfd1)set @bfd2=(select max(backup_finish_date) from resto where typ='L')set @path2=(select physical_device_name from resto where backup_finish_date=@bfd2)set @db2=(select database_name from resto where backup_finish_date=@bfd2)set @type2=(select typ from resto where backup_finish_date=@bfd2)if @type='D'beginrestore database @dbfrom disk=@pathwith stats=10,recovery,replaceendelse if @type1='I'begin restore database @dbfrom disk=@pathwith norecovery,replacerestore database @db1from disk=@path1with stats=10,recovery,replaceendelse if @type2='L'beginrestore database @dbfrom disk=@pathwith norecovery,replacerestore database @db1from disk=@path1with stats=10,norecovery,replacerestore log @db2from disk=@path2with stats=10,recovery,replaceendelseprint'operation failed' |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-11 : 16:07:30
|
| What error are you getting?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
honey_191
Starting Member
49 Posts |
Posted - 2008-02-11 : 18:03:10
|
| I am not getting any errors.I take the log backup but it is restoring the full backup.Is any thing wrong in my code? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-11 : 18:43:44
|
| Have you checked that the correct values are being put into your variables? Run PRINT statements for each of the variables directly after the SET statements.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
|