Log Chains and SQL Server Transaction Log - sanity check - sql-server

I'm helping with a rather ad-hoc disaster recovery, and we've restored a database backup from a few weeks ago and then restored transactions from a transaction log backup.
We did this using SQL Server Management Studio - right click on database, restore full backup but leave in recovery mode, right click again, restore transaction log, etc.
I'm now trying to verify that we had no gaps in our logs. Is it safe to assume that if the SQL Server Management Studio allowed me to restore the logs without errors, then there were no gaps in the logs (e.g. the log chain is complete)?
In other words - would SQL let me restore logs if there were gaps? I assume it would warn me or stop me in that case.
Thanks for any help you can offer ....
We're on SQL 2005 but I think the rules about log chains are similar through all versions.

According to the document Working with Transaction Log Backups from Microsoft:
If a log backup becomes missing or damaged, start a new log chain by creating a full or differential database backup and then backing up the transaction log to start a new log chain. We recommend that you retain transaction logs backups that come before a missing log backup, in case you ever want to restore the database to a point in time within those backups. For information about how to help protect your backups, see Security Considerations for Backup and Restore.
and Creating Transaction Log Backups states:
If a transaction log is damaged, work that is performed since the most recent log backup is lost. This highlights the importance of putting the log files on fault-tolerant storage.
My free reading of this is:
Considering a lost file a kind of file damage, if Management Studio or any other tool allows you to restore the logs without errors, you can be sure the log chain is complete until the last transaction log backup you're applying. You must be sure it is the last transaction log backup available for that database, but that is other thing to think about.
If you don't trust my reading (and the documentation is not too clear on this point), you can make a simple test to be sure: Say you have 10 transaction logs to apply... deliberately delete the 7th (or a random, but not the first nor the last) transaction log, and try your disaster recovery method.
If you get a error saying something like "a transaction log file backup is missing", you can be sure and trust me.

You are correct. SQL will not apply a transaction log backup if it can't be applied, you would have gotten an error.

Related

Why is my SQL Server Differential backup failing sometimes?

I'm having an issue that only happens sometimes where my SQL Server differential backup job fails with an error message similar to
Msg 3035, Sev 16, State 1, Line 1 : Cannot perform a differential backup for database "MyDatabaseName", because a current database backup does not exist. Perform a full database backup by reissuing BACKUP DATABASE, omitting the WITH DIFFERENTIAL option. [SQLSTATE 42000]
Msg 3013, Sev 16, State 1, Line 1 : BACKUP DATABASE is terminating abnormally. [SQLSTATE 42000]
I'm currently using Ola Hallengren's SQL Server Mantenance Solution script for backup's, integrity check's and index maintenance. I've scheduled the backup job's as such:
Full Backup of system databases every day # 1:30 AM
Full Backup of all user databases every week on Monday, Wednesday & Friday # 2:30 AM
Differential Backup of all user databases every week on Sunday, Tuesday, Thursday & Saturday # 2:30 AM
Transaction Log backup or all user databases every 30 minutes
I've also set the cleanup time to 168 hours...which is 7 days.
I know that usually when this error message comes up, it is due to a full backup not being present, or possible the recovery mode on a database being changed. I have checked both of these and neither seems to be the case. I can confirm that my Friday full backup was successful, however my Saturday and Sunday Differentials failed. There have also been no changes to the recovery model, and no manual backup taken through SQL Server.
It's worth noting that this only happens sometimes. Sometimes the differential backups work without a problem and other times they fail.
This server is a VM, and we are using VMWare vSphere/vCenter 6.5. I've talked to my server admin and asked how his backup is running an he told me that we are using Quest AppAssure which leverage VMWare snapshot technology, and that he is backuping the drives every x number of minutes, so it is possible that the time of his backup changes and eventually overlaps with mine.
We looked back at the time that his backups ran on the weekend and they happened within a few minutes before mine started. I'm wondering if this is causing my backup issues? if so is there a way to prevent this, or do we simply need to plan the backups at different times that don't overlap?
Thanks
We had another call with Quest today and figured out a solution to the problem.
It would seem that when configuring the backup through Quest Rapid Recovery, you have the option to do Machine level backups or Volume level backup. When it's configured to do volume level backups you can choose for it to either do a block level backup which isn't SQL Server aware, or for it to do a backup that is SQL Server aware, which ends up using the volume shadow copy service and these backups show up as Full (Copy Only) backups in the SQL backup history...even though you can't restore them from SQL Server.
Rapid Recovery can only do backups on a schedule, plus has the option to Truncate Logs after the backup complete to avoid filling the log files, but can't do transaction log backups, so you loose the ability to do a more granular recovery down to the second like with the native SQL Timeline Recovery...Which is why we chose to use native SQL Server Backups.
So to fix the issue, you need to either do a machine level backup which has not SQL Server Awareness/integration. Or you can do a volume level backup, but disable the SQL Server Writer extension, and the truncate logs options to remove the integration.
We've run a bunch of tests, and from the point/time that this change was done, we only see SQL Server backups and no longer the Rapid Recovery backups in the SQL Server Backup history.
So now i am in talks with my server/backup admin see if we can do a machine level backup once a day, so that we can do a machine level restore in case of disaster, and also add a volume level backup of my Backup drive, so that he captures my backups more frequently during the day. I think once this is complete, we'll have the best of both backup solutions.
Ability to do machine level restores (Rapid Recovery)
Retention of SQL Server Backups (Rapid Recovery)
Flexible point in time recovery (SQL Server)
Just wanted to post a update to this issue
We scheduled a call with Quest yesterday, and they assured me that their backup is only taking volume snapshots and will have no impact on my SQL backups. They said that the reason that i was seeing these errors is likely do to Rapid Recovery(I guess AppAssure was renamed to Rapid Recovery) and my SQL backup jobs both trying to use the volume shadow copy service at the same time and so we simply needed to stagger the backup jobs. I end up finding out that this wasn't completely true because the Rapid Recovery backups were configured to truncate my SQL Logs. I also told the guy from rapid recovery that when i queried the msdb backupset table that i was seeing backup jobs listed that lined up with the times of the rapid recovery backup. Still he assured me that it would have zero impact on my backups.
I was still concerned that the Rapid Recovery backups might be impacting the chain of my backup files, so in our test environment i right clicked on one of our databases and clicked tasks > restore >database just to see the recovery history. I see a database backup listed as type Full (Copy Only) which coincides with the rapid recovery backup, then a number of my transaction log backups.
It would seem to me that Rapid Recovery is definitely impacting my SQL Backups.
One other thing to note that i just tried in out test environment. I did a few tests backups using Full's , Transaction Log, Differentials and Full (Copy Only) just to see how things showed up in the restore window in SQL Server Management Studio.
So i realized that in the default restore screen, it tries to recover to the nearest point in time using the least combination of various backup files. To go past the last full backup, I have to use the Timeline option.
I could see the Full backup as the first item, and then the transaction logs backups.
Once i do the Differential backup, i see the Full plus the differential, but no more transaction log backups.... which makes sense since it's trying to get the the closest time possible for the recovery.
Next if i do another Transaction Log backup, I see the Full, Differential and the Transaction Log back
One thing that surprised me however is if i do a Full (Copy Only) followed by a transaction log backup, that i see these two item in the list of files for the recovery, yet if i do a differential after a Full (Copy Only) that it show me the last Full (non copy only), plus the differential. I expected that the backups would always be based off of the last full, both for transaction log and differential backups. I thought that the Copy Only backups would be ignored in the backup chain.
Next I decided to use the timeline restore feature and select a point in time during my tests where the Rapid Recovery backup wasn't part of the listed backups, and do a verify backup. As expected it was successful. After this i tried a restore to another point in time where the Rapid Recovery Full (Copy Only) backup was listed and the verify failed on the Full (Copy Only) backup file from rapid recovery, since it doesn't exist on the sql server.
Any recommendations on how to fix this? The point of the Rapid Recovery backup is supposed to be to backup the machine, in case we ever loose the server and have to restore the entire server, plus for it to pick up my sql server backups to keep for retention, since i only keep 7 days worth of backup on the server itself.
You can check the error log file.
Your job may be the victim of deadlock transactions.
Backup file location may not have enough permission.
So, you should check all the possible error log files.

Transaction Log Restore: System objects could not be updated in database because it is read-only

I want to set up a secundary copy of a large ERP production database, which would be used as read-only database for reporting purposes. Regular backup jobs on production DB are already configured: a full backup every night and regular transaction log backups every 15 minutes.
I'm restoring a full backup and then applying transaction log backups (with STANDBY option). The restore of transaction log is successful, but I always get a message at the end that the system objects could not be updated:
Processed 7 pages for database ..., file ... on file 1.
System objects could not be updated in database ... because it is read-only.
System objects could not be updated in database ... because it is read-only.
RESTORE LOG successfully processed 7 pages in 0.029 seconds (1.633 MB/sec).
It seems that the restore is successful. However, the warning (error?) regarding the system objects is confusing. Is it something I should pay attention to? What is the reason for the error? I couldn't find any similar problem on the Microsoft support forums...
Update: SQL Server version is 11.0.7469.6 (2012 with all service packs and hotfixes)
If you don't mind I'll suggest you a workaround(There might be a solution)
step 1. Restore the full backup to a new database and ensure the backup is successful(by accessing some objects).
step 2. restore the transaction backups 2(some count let say 3 or some number) at a time and make db to recovery state then query the same objects which were done at step 1.
step 3. repeat the process until all the backups were restored successfully.
Also check the following link, might work.

Why does my sql server database "full backup" not contain recent data?

I just migrated a SQL Server 2008 database while the sales staff went to lunch. I did a full backup and then copied the backup to the new server where I restored it to the new SQL Server installation.
The staff got back from lunch and told me that a few of the recent deals they put in right before lunch were no longer showing up in the system. Upon investigation it seems that the full backup was not including some of the very recent data that was added to the database before the backup was performed.
I suspect there is something I'm not accounting for that relates to the transaction log, but not being a MSSQL specialist, I'm not quite sure what I'm doing wrong. Could someone point me in the right direction?
Did you back up just the database, or with transaction logs as well? My guess is that you didn't backup transaction logs, which will contain recent transactions not yet flushed down to the mdb file.
The data may have been entered in an open transaction. Since the backup has to adhere to the ACID model, if a transaction was started before the backup started and was not committed by the time the backup has completed, the transaction will be rolled back upon restoring the database.
This is why you never do these things during a work day! Next time do this over the weekend and close the database off to users by putting it in single user mode. They could have added the data after your backup or during it if you didn't lock them out first.

sql server 2008 restore with transaction log?

I am developer so need your advice on how to plan for it
I am having sql server 2008.
I am going to through what they have in maintance wizard
And found that they have full, differential and transaction log.
So if i take one full back once a week then differential backup every day. Not sure how transaction log fit into this.
I assume sql server is saving transaction log some where so in case of failure I can restore from last differential backup coupled with full backup.
What i need to use transaction log on top of it? Where is transaction log saved?
I need this for application data loss issue, if in case some action made it delete some data so i need ability to go back point in time.
You must backup your log too, explicitly. Schedule a job to backup the log at short intervals (15 minutes to an hour usually). When you do a recovery, you apply the full backup, then the newest differential and then all the log backup after the differential.
Only with log backup can you restore the database at a specific moment, using the 'WITH STOP AT'. See: How to: Restore to a Point in Time.
Also to recover from a crash, you backup the log tail then apply the recovery (full->differential->logs->tail) and hopefully occur no data loss at all.
A Zero loss strategy require the involvement of replication in some form. Then you'll also need a failover server to account for replication time before the "slave" server is fully up to date.
Even with transaction log backups your still at risk for losing X data, where X is your transaction log backup interval.
Maybe edit your question?

The log file for database is full

So our SQL Server 2000 is giving me the error, "The log file for database is full. Back up the transaction log for the database to free up some log space."
How do I go about fixing this without deleting the log like some other sites have mentioned?
Additional Info: Enable AutoGrowth is enabled growing by 10% and is restricted to 40MB.
To just empty it:
backup log <dbname> with truncate_only
To save it somewhere:
backup log <dbname> to disk='c:\somefile.bak'
If you dont really need transactional history, try setting the database recovery mode to simple.
Scott, as you guessed: truncating the log is a bad move if you care about your data.
The following, free, videos will help you see exactly what's going on and will show you how to fix the problem without truncating the logs. (These videos also explain why that's such a dangerous hack and why you are right to look for another solution.)
SQL Server Backups Demystified
SQL Server Logging Essentials
Understanding Backup Options
Together these videos will help you understand exactly what's going on and will show you whether you want to switch to SIMPLE recovery, or look into actually changing your backup routines. There are also some additional 'how-to' videos that will show you exactly how to set up your backups to ensure availability while managing log file sizing and growth.
ether backup your database logs regularly if you need to recover up to the minute or do other fun stuff like log shipping in the future, or set the database to simple mode and shrink the data file.
DO NOT copy, rename, or delete the .ldf file this will break your database and after you recover from this you may have data in an inconsistent state making it invalid.
I don't think renaming or moving the log file will work while the database is online.
Easiest thing to do, IMO, is to open the properties for the database and switch it to Simple Recovery Model. then shrink the database and then go back and set the DB to Full Recoery Model (or whatever model you need).
Changing the logging mode forces SQL Server to set a checkpoint in the database, after which shrinking the database will free up the excess space.
My friend who faced this error in the past recommends:
Try
Backing up the DB. The maintenance plan includes truncation of these files.
Also try changing the 'recovery mode' for the DB to Simple (instead of Full for instance)
Cause:
The transaction log swells up due to events being logged (Maybe you have a number of transactions failing and being rolled back.. or a sudden peaking in transactions on the server )
You may want to check related SO question:
How do you clear the transaction log in a SQL Server 2005 database?
Well you could take a copy of the transaction log, then truncate the log file, which is what the error message suggests.
If disk space is full and you can't copy the log to another machine over the network, then connect a drive via USB and copy it off that way.
You have the answer in your question: Backup the log, then it will be shrunk.
Make a maintenance plan to regularly backup the database and don't forget to select "Backup the transaction log". That way you'll keep it small.
If it's a non production environment use
dump tran <db_name> with no_log;
Once this has completed shrink the log file to free up disk space. Finally switch database recovery mode to simple.
As soon as you take a full backup of the database, and the database is not using the Simple recovery model, SQL Server keeps a complete record of all transactions ever performed on the database. It does this so that in the event of a catastrophic failure where you lose the data file, you can restore to the point of failure by backing up the log and, once you have restored an old data backup, restore the log to replay the lost transactions.
To prevent this building up, you must back up the transaction log. Or, you can break the chain at the current point using the TRUNCATE_ONLY or NO_LOG options of BACKUP LOG.
If you don't need this feature, set the recovery model to Simple.
My dear friend it is vey important for a DBA to check his log file quite frequently. Because if you don't give much attention towards it some day it is going to give this error.
For this purpose you have to periodically take back up so that the logs file would not faced such error.
Other then this the above given suggestion are quite right.
Rename it it. eg:
old-log-16-09-08.log
Then the SQL server can use a new empty one.

Resources