Restore SQL Server DB without transaction log

Sql ServerRestoreTransaction Log

Sql Server Problem Overview


Given a SQL Server 2008 .bak file, is there a way to restore the data file only from the .bak file, without the transaction log?

The reason I'm asking is that the transaction log file size of this database is huge - exceeding the disc space I have readily available.

I have no interest in the transaction log, and no interest in any uncompleted transactions. Normally I would simply shrink the log to zero, once I've restored the database. But that doesn't help when I have insufficient disc space to create the log in the first place.

What I need is a way to tell SQL Server to restore only the data from the .bak file, not the transaction log. Is there any way to do that?

Note that I have no control over the generation of the .bak file - it's from an external source. Shrinking the transaction log before generating the .bak file is not an option.

Sql Server Solutions


Solution 1 - Sql Server

The transaction log is an integral part of the backup. You can't tell SQL Server to ignore the transaction log, because there is no way to let's say restore and shrink the transaction log file at the same time. However, you can take a look at DBA post to hack the process, although it is not recommended at all

Alternatively you could try some third party tools for restoring, particularly virtual restoring process that can save a lot of space and time. Check out ApexSQL Restore, RedGate Virtual Restore, Idera Virtual Database.

Disclaimer: I work for ApexSQL as support engineer

Solution 2 - Sql Server

No, the transaction log is required.

Option 1:

An option may be to restore it to a machine that you DO have enough space on. Then on the restored copy change the logging to either bulk logged or simple, shrink the logs, do another backup operation on this new copy and then use that to restore to the target machine with the now much smaller transaction log.

Option 2:

Alternatively, perhaps the contact at the external source could shrink the transaction log before sending it to you (this may not work if the log is large due to a lot of big transactions).

Docs on the command to shrink the log file are available here.

Solution 3 - Sql Server

This is really a question for the ServerFault or DBA sites, but the short answer is no, you can only restore the full .bak file (leaving aside 'exotic' scenarios such as filegroup or piecemeal restores). You don't say what "huge" means, but disk space is cheap; if adding more really isn't an option then you need to find an alternative way of getting the data from your external source.

Solution 4 - Sql Server

This may not work since you have no control over the generation of the .bak file, but if you could convince your source to detach the database and then send you a copy of the .mdf file directly, you could then attach the .mdf and your server would automatically create a new empty transaction log file.

See sp_detach_db and sp_attach_db (or CREATE DATABASE database_name FOR ATTACH depending on your sql server version).

Solution 5 - Sql Server

I know this is an old thread now, but i stumbled across it while I was having transactional log corruption issues, here is how I got around it without any data loss (I did have down time though!)

Here is what I did:--

Stop the sql server instance service make a copy of the affected database .mdf file and .ldf file (if you have an .ndf file, copy that as well!) - Just to be sure, you can always put these back if it doesn't work for you.

restart the service.

Log into sql management studio and change the database mode to simple, then take a full backup.

Change the database type back again and once again take a full backup, then take a transactional log backup.

Detach the database.

Right click on databases and click on restore, select the database name from the drop down list, select the later full database backup created (not the one taken from the simple mode) and also select the transactional log backup.

Click restore and it should put it all back without any corruption in the log files.

This worked for me with no errors and my backups all worked correctly afterwards and there were no more transactional log errors.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLondonPhantomView Question on Stackoverflow
Solution 1 - Sql ServerMarko KrsticView Answer on Stackoverflow
Solution 2 - Sql ServerChris TownsendView Answer on Stackoverflow
Solution 3 - Sql ServerPondlifeView Answer on Stackoverflow
Solution 4 - Sql ServerAaronView Answer on Stackoverflow
Solution 5 - Sql ServerFilfishView Answer on Stackoverflow