HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

Is it possible to restore sql-server bak and shrink the log at the same time?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
samethelogsqlandtimeshrinkpossibleserverbak

Problem

We have a bak file from a client that we have transferred to our developer offices for problem investigation. The backup is currently 25GB and the restored database is about the same size however it needs 100GB to be restored. I believe this is because there database is set up to have a 75GB transaction log size. After restoring the database we can shrink the log file but is there a way to do this in the restore?

Solution

There is a do-not-ever-do-this-in-a-live-environment hack you can use where space is limited, by restoring the log file to a compressed folder. Attempt this by compressing an existing folder and restoring to it will result in an error, so you have to cheat with a symbolic link.

  • Create a compressed folder D:\LogCompressed\



-
Create a symbolic link to the compressed folder mklink /D /J D:\Log\ D:\LogCompressed\

-
Restore your database with the ldf file pointing at D:\Log\

-
Shrink the log file to an appropriate size

-
Detach the database, move the log file to an uncompressed folder, attach

It's dirty, it's cheating, DO NOT EVER DO IT IN LIVE, but it works. Quick test of a newly created database with a 32MB log file shows it as occupying 330kb on disk when compressed, decompress the folder and on disk size is back to 32MB.

Context

StackExchange Database Administrators Q#6297, answer score: 34

Revisions (0)

No revisions yet.