Home > SQL Server Tips > Database Management and Administration > Copy-only backups: Another useful tool in SQL Server 2005
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE MANAGEMENT AND ADMINISTRATION

Copy-only backups: Another useful tool in SQL Server 2005


Greg Robidoux, Contributor
04.05.2007
Rating: -4.75- (out of 5)


Expert advice on database administration
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


A new feature added to SQL Server 2005 is the ability to create copy-only backups. The advantage to this type of backup is that it doesn't interfere with your regular scheduled backup sequences, if you need to create another backup file outside of your regular backup processing.

Let's say you need to create a full backup in the middle of the day in order to refresh your development or test environments. In most cases if you issue another full backup in between doing your regularly scheduled backups, it does not cause an issue with your transaction log backup sequence numbers. But, it can throw off your differential backups. Also, if you need to run an additional transaction log backup during your regular processing, this could cause an issue when you need to restore your backup files.

So basically, the copy-only function allows you to run a non-regular scheduled backup at any time without causing an issue with the log sequence numbers stored in the backup files.

You probably think these items need to be run in conjunction, i.e. all regular or all copy_only, but this is not the case. The only time you need to use the copy_only option is when you want to run a backup outside of your scheduled process and you don't want to have to include this in your restore process.

Example backup in SQL Server 2005
Here is an example of a backup process and also the interjection of some copy_only backups in between. Also, we are issuing some transactions in between each backup to update data. When this process is complete we will have the following:

  • 1 Full backup
  • 2 Differential backups
  • 6 Log backups
  • 1 Full copy_only backup
  • 1 Log copy_only backup

Click here to view the backup process example and copy-only backups.

Restoring regular backup files
If we want to restore to the most recent ...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
SQL Server Backup and Recovery
SQL Server Mailbag: Data restoration and DB property management
Achieving high availability and disaster recovery with SharePoint databases
How to 'do' SQL Server disaster recovery
The keys to database backup protection for SQL Server
Choosing a SQL Server disaster recovery solution
Licensing a standby server for SQL Server replication
Can I encrypt and restore a database backup in SQL Server 2005?
SQL Server errors, failures and other problems fixed from the trenches
Get SQL Server log shipping functionality without Enterprise Edition
SQL Server 2008 backup compression pros and cons
SQL Server Backup and Recovery Research

Microsoft SQL Server 2005
End of life comes for SQL Server 2005 SP2, 2008
SQL Server Reporting Services Fast Guide
SQL Server Service Broker Tutorial and Reference Guide
Tips for tuning SQL Server 2005 to improve reporting performance
SQL Server consolidation: Why it's an optimization technique
Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
Enforcing data integrity in a SQL Server database
SSIS error message due to installation problem on SQL Server 2005
Should you upgrade to SQL Server 2005 or SQL Server 2008?
Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
Microsoft SQL Server 2005 Research

Database Management and Administration
Password cracking tools for SQL Server
Using traces in SQL Server Profiler
Meet compliance requirements with improved database security practices
Hardening the network and OS for SQL Server security
Securing the server and database in SQL Server
How SQL Server 2008 components impact SharePoint implementations
Troubleshooting Distributed Transaction Coordinator errors in SQL Server
Achieving high availability and disaster recovery with SharePoint databases
Clearing the Windows page file and its effect on server performance
Deploying a SQL Server virtual appliance for Microsoft Hyper-V

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
rollback  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


point in time for the regular backups when restoring the databases, we would issue the following.
Note: There is nothing different here from what you would normally do when restoring your database backups.

RESTORE DATABASE dbutil3 FROM DISK = 'c:\backup\dbutil_full.bak'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil3.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil3_log.ldf', NORECOVERY

RESTORE DATABASE dbutil3 FROM DISK = 'c:\BACKUP\dbutil_diff2.bak'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil3.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil3_log.ldf', NORECOVERY

RESTORE LOG dbutil3 FROM DISK = 'c:\BACKUP\dbutil_log5.trn'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil3.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil3_log.ldf', NORECOVERY

RESTORE LOG dbutil3 FROM DISK = 'c:\sqldata\dbutil_log6.trn'
WITH MOVE 'dbutil' TO 'c:\backup\dbutil3.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil3_log.ldf', RECOVERY

Restoring COPY ONLY backup files
If we want to restore the copy_only backups, you would think you would issue the following to restore just the copy_only backups.

RESTORE DATABASE dbutil2 FROM disk = 'c:\backup\dbutil_full_copy.bak'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil2.mdf', MOVE 'dbutil_log' TO
'c:\backup\dbutil2_log.ldf', NORECOVERY

RESTORE LOG dbutil2 FROM disk = 'c:\BACKUP\dbutil_log1_copy.trn'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil2.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil2_log.ldf', RECOVERY

But when running the above commands you get this error message:

Msg 4305, Level 16, State 1, Line 1
The log in this backup set begins at LSN 28000000033600001, which is
too recent to apply to the database. An earlier log backup that
includes LSN 28000000033300001 can be restored.
Msg 3013, Level 16, State 1, Line 1
RESTORE LOG is terminating abnormally.

To resolve this, you need to issue the following restores. As you can see we need to run the regular transaction log backup #5 that occurred after the full copy_only backup and prior to our copy-only log backup, in order for the restore process to work.

RESTORE DATABASE dbutil2 FROM disk = 'c:\backup\dbutil_full_copy.bak
' WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil2.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil2_log.ldf', NORECOVERY, replace

RESTORE LOG dbutil2 FROM disk = 'c:\backup\dbutil_log5.trn'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil2.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil2_log.ldf', NORECOVERY

RESTORE LOG dbutil2 FROM disk = 'c:\BACKUP\dbutil_log1_copy.trn'
WITH MOVE 'dbutil' TO 'c:\sqldata\dbutil2.mdf', MOVE 'dbutil_log' TO
'c:\sqldata\dbutil2_log.ldf', RECOVERY

Summary
The copy-only option is a new feature of SQL Server 2005 allowing you to run these special backups without affecting the sequence numbers stored in the backup files. There are ways around the copy-only feature. If you issue another full backup during the day and need to do a recovery, just use that full backup and any differential or log files that occurred after. If you issue a special differential backup, you would again just use this backup when doing a restore. Also, if you issued a special transaction log backup you would just need to include this as well. I guess there is some situation where this would make sense, but overall there are other ways to get around this problem. See if you can find a problem where this would be the perfect solution.


ABOUT THE AUTHOR:   

Greg Robidoux is the president and founder of Edgewood Solutions LLC, a technology services company delivering professional services and product solutions for Microsoft SQL Server. He has authored numerous articles and has delivered presentations at regional SQL Server users' groups and national SQL Server events. Robidoux, who also serves as the SearchSQLServer.com Backup and Recovery expert, welcomes your questions.
Copyright 2007 TechTarget


Rate this Tip
To rate tips, you must be a member of SearchSQLServer.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SQL Server Development - .NET, C#, T-SQL, Visual Basic
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts