In this post I am going to explain the importance of recovery models and backup types.
Why I am writing this post ?
Because, when I was teaching about the topic to my PHP friend .He got doubts on bulk logged recovery model and differential backups. I have given some examples and cleared his doubts. I am going to share this with you guys too.
I hope this will help for Freshers and DBA managers.
Recovery models and backup types are important to plan the recovery point objective (RPO) and recovery time objective (RTO). We can’t differentiate the recovery models and backup types. Simply, it’s a mixture.
Let’s see the discussion.
Manager:
We need minimum data loss and downtime.
DBA:
The existing system has low disk space and the transaction log backups are often failing. We need more disk space to do this, Sir!
Manager:
I asked about this to management they will give soon, until you will do something with your DBA knowledge.
DBA:
Changing the recovery models full to simple and back to full and shrinking the log file daily. The DBA send an email to his manager. The shrinking is not best practices, Sir!
Manager:
???
Let’s come to the point.
Recovery Models
SQL server has three types of recovery models.
- Full
-
Bulk Logged
-
Simple
Full
- In full recovery model all the database operations are fully logged like all redo information. This means all the modifications have written fully to the log file.
- The full recovery model is always the best one for production servers.
- In the full recovery model we can take all kinds of backups like full, differential, transaction Log and point in time recovery (PTR) too.
Full recovery mode, the transaction log file will grow like anything(big), until we do a log backup. In other words, The log file will not be reusable/clear until the log backup taken.
Bulk Logged
- The name itself you can understand the answer. The bulk operations (bulk operations) are minimally logged in this mode. This means it does not have sufficient information in the log to replay the transaction. The BCM page contains all the required information. See an example you can understand.
- Bulk logged recovery model is the best model for server performance. Because all the bulk changes have been written minimally (Not fully) to the transaction log file.
- In bulk logged recovery model we can take all kinds of backups like full, differential and transaction Log but, the drawback is the point in time recovery (PTR) is not possible, when there is a bulk operations have done with the transaction log file.
Keep in mind, in full and bulk logged recovery model the log files grow bigger until the BACKUP LOG has done.
For more clarity. See an example: (This is not a concept just an example)
Just assume 5,000 bulk operations have written in 8000 pages.
In full recovery model each 5,000 bulk operations have written in 8000 pages, because all the changes have written fully in the full recovery model.
But when we used bulk logged recovery model, it has written 1000 pages only ,Because SQL server has written the bulk changes to an extent wise not the page wise i.e. minimally logged operation (8 pages = 1 extent). It will help to improve the overall server performance.
Now you know, Writing 8000 pages are good or 1000 pages.
Note: The bulk logged model is good only for the bulk operations.
Simple
- The name itself you can understand the answer all operations are fully logged except bulk operation, Since bulk are minimally logged. Simple recovery model is just simple this means SQL server will run the checkpoint every time and truncate the transaction log file and marked the space for reuse . Mostly the log file will not grow larger.
- Most of the time the simple recovery model is a good choice for non production servers. Because the log file will not grow larger. Also we would not take log backups. (If you’re planning to take the log backup then don’t put in simple)
- In the simple recovery model the transaction log backup is not possible. We can take full and differential backups only.
Now you could know the answer for the following questions.
What is the use of Full, Bulk logged and Simple recovery model.
Which one is best for your case?
Backup Types
SQL server has number of backup types. Here I am going to explain the main three types.
- Full
-
Differential
-
Transaction log
I recommend to read Paul S Randals’s backup survey post.
http://www.sqlskills.com/BLOGS/PAUL/post/Importance-of-having-the-right-backups.aspx
Full backup
- A full backup backs up the full/whole database. That backs up all the data.
- The full database backup has been done in all the recovery models.
Differential backup
- A differential backup only backs up the changed data/extents that were modified after the full database backup has done. The DCM has tracked all the changed extents.
- The differential backup has been done in all the recovery models.
For more clarity. See an example:
Assume we are scheduled every Sunday full backup @12 am and daily differential backup 10 PM.
Note: The data changes daily 500 MB.
Question:
How much data got back up on Thursday?
The student answers 500 MB.
As I already told, differential database backup “backs up all the data that has changed since the last full database backup”.
The answer is,
Monday 500MB + Tuesday 500 MB + Wednesday 500MB + Thursday 500MB= 2000MB
Edit: I added these lines after I had replied the forum question SSC.
So the differential backup on Thursday has all the data. That is (Monday+Tuesday+Wednesday+Thursday). It helps to bring the database online as quickly as possible.
Transaction log backup
- A transaction log backup backs up the transaction log file. That is all the modifications/changes.
- The transaction log backup only possible in full and bulk logged recovery model.
- The transaction log backup is important to minimize data loss and log file size too.
It’s very important to keep the transaction log backup as much as safe, because the restoration needs the sequence of the transaction log backup if, you deleted/missing any one of the backups then you can’t recover the whole data.
It’s good to take a log backup often. It will reduce the log file size and helps to minimize your data loss.
Question:
How to restore the database after a disaster? (OR) What is the sequence to restore the database?
Answer:
Restore a recent full backup and followed by a recent differential backup and all the log backup one by one, that has done after a recent differential backup.
For more clarity. See an example:
Assume we have scheduled every Sunday full backup @12 am and daily differential backup 8 PM and an hourly log backup.
The database crashed on Wednesday at 11PM. Then the restoration will be on Sunday full backup (@12AM)+ Wednesday differential backup (Most recent @8PM) + log backup @9+@10+@11 PM.
Believe me guys, Test your backups often and keep at least two copy of the full backups safely, Because the full backup is important to restore the all other backups. This means without a full backup you can’t restore the differential and log backups.
Note: The example has given is just for more understanding. Take a look at MSDN for more information.
37 Comments
ram
dude,superb , very useful to understand the basic recovery model and backup types and the way which you explained s nice
Muthukkumaran
I wrote this post after we had a class discussion. Thanks to you dude.
david
this is very informative, but when we should take full backup and when differential and transaction log backup? i mean weekly or daily or hourly? can you please explain that with some example sir. And if you mail me i will be very thankful to you.
Anonymous
Hi Muthu
1. As you said, In-case of any disaster on Wednesday @ 1:30 pm.
2. We have to perform the "Tail-Log" backup first. Then only we will have last 30 minutes transaction after the actual transaction-log hourly backup. correct ?
3. Then, we have to proceed with further Restore either (Norecovery or Standby state)
Muthukkumaran
@Anonymous user
Yep, You are right.we can take the tail log backup if, there is no damage in transaction log file.I didn't focus the restore part fully. It's just an example to understand the restoration sequence to all the newbies.
Thanks to reading my posts.
i don't know most of my comments are from Anonymous user. Nobody is writing his name.
Anonymous
Spot-on post.I agree with the first person comment the way you explained really superb and it's written using very simple/understandable english.
keep up the good work.
Great examples.
BY
Yardy
Muthukkumaran
@yardy glad you liked it.thanks
To be frank i don’t know complex words.lol
vinoth
Hi muthu,
Great post.
I liked this.
Monday 500MB + Tuesday 500 MB + Wednesday 500MB + Thursday 500MB= 2000MB
Muthukkumaran
So the differential backup on Thursday has all the data. That is (Monday+Tuesday+Wednesday+Thursday). It helps to bring the database online as quickly as possible.
I have added these lines after i replied the forum question
http://www.sqlservercentral.com/Forums/Topic1128012-391-2.aspx?Update=1
Muthukkumaran
Pooja,
Yep you are right. If you have log backup you can restore that too.
If you want more answer I suggest you to ask questions to SQlservercentral and MSDN forum.
Pingback:
Pingback:
Myrman
Thank you for making your work very easy to comprehend. The topic is somewhat baffling as it is but you make it look easy. This is just what people need to read.
Muthukkumaran kaliyamoorthy
Glad you liked it.Thanks.
Deandrea Nodine
Useful page and incredibly informative. Thanks for taking the time to write it and post it!
Muthukkumaran kaliyamoorthy
Thanks Deandrea Nodine.
Mellie Partible
You, my friend, ROCK! I found just the info I already searched everywhere and just could not locate it. What a perfect website. I have bookmarked your website: https://sqlserverblogforum.com/2011/06/sql-server-recovery-models-and-backup-types/ and will check back often. Thanks for the awesome information!
Muthukkumaran kaliyamoorthy
I’m glad you liked it.
Dee Lazich
I don’t even understand how I finished up right here, however I assumed this publish was once great. I do not recognize who you might be however certainly you’re going to a well-known blogger should you are not already 😉 Cheers!
Muthukkumaran kaliyamoorthy
I’m glad it helps you.
Thanks Dee.
Pingback:
Sandesh M. Shinde
Hi Muthu,
Amazing info. in lucid language. Thank you so so much.
prabhar
ur site very useful for me
WebTree Technologies
I Learned this article it’s very useful to understand the DBA concept
yugandhar
thanks bro nice explnation
Pingback:
elliswhite
Learn more about backup models and their consistencies go through this:- http://www.sqlrecoverysoftware.net/blog/sql-database-recovery-model.html
yvonneclark
To retrieve your lost and damaged SQL database from SQL server. You can try SQL database recovery software to retrieve your lost files.
For more details:-
http://www.pcrecoveryutility.com/sql-database-recovery.html
Dawit
Thank you for your clear understandable demonstration, I understood now about three types of recovery and backup model very well. keep it up.
Pingback:
Sam
Really appreciable task that you have done and well tried to explain in short. The main concept against the designing of recovery model is to know how the transactions are logged, whether the transaction logs need backup, and what kind of restore operations are available with the recovery model?
After a long googling I found this article which describes the recovery models in very simple words. http://sqltechtips.blogspot.com/2015/11/-recovery-models.html
DavidHarmer
To repair corrupt MS SQL server database file, I would like to refer more effective highly advance software, you can use SQL Database Recovery Tool. This software easy to ecovery of highly corrupted or damaged MDF files of Microsoft SQL Server. It can supported all version of 2016, 2014, 2012, 2008, 2005 and 2000.
For more detail click here – http://www.tools4recovery.com/sql-database-recovery.html
sameclark
To repair corrupt or damaged SQL database using an effective tool SQL recovery tool. This tool quickly recovers all tables, stored procedure, functions, views, rules, triggers and associated Primary Key, Unique keys and etc. It supports all versions of MS SQL server and Windows OS versions. Visit here – http://www.en.sqlrepair.org
Parvinder Nijjar
A nice succinct post.
Muthukkumaran kaliyamoorthy
Thank you sir!
Muthukkumaran kaliyamoorthy
Thank you Parvinder Nijjar!
Rajesh sharma
Thank you so much for sharing the article with us. It helped me a lot to take a backup of my sql server models. And i have already shared this article with friend and they also liked it very much