SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Urgent help in Script to restore the database by creating empty log file


Urgent help in Script to restore the database by creating empty log file

Author
Message
Mac1986
Mac1986
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1419 Visits: 791
Hi,
I have a situation where in I need to restore a .BAK file and i do not have enough disk space to restore the entire Data and log files from the .BAK file.

Is there a way than I can just restore the data and not restore the log file. OR create a an empty log file while restoring and not considering the huge log file from the .BAK file?

I'm using SQL Server 2008 R2 version.
- Win
- Win
SSChasing Mays
SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)

Group: General Forum Members
Points: 612 Visits: 707
I dont think you can just restore a MDF file avoiding LDF from a full backup file.
Attach, detach will do. You should be able to attach the database with just the MDF file.
It will create one LDF file automatically for you with default size.


Found somthing for you, hope it helps.

--Step 1: Retrive the Logical file name of the database from backup.
RESTORE FILELISTONLY
FROM DISK = ‘G:\TransDB_Full.BKP’
GO

--Step 2: Use the values in the LogicalName Column in following Step.
—-Make Database to single user Mode
ALTER DATABASE TransDB
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE

—-Restore Database
RESTORE DATABASE TransDB
FROM DISK = ‘G:\TransDB_Full.BKP’
WITH
MOVE ‘O1_SITEDB’ TO ‘J:\TransDB_Data.mdf’,
MOVE ‘O1_SITEDB_Log’ TO ‘C:\TransDB_Log.ldf’

/*If there is no error in statement before database will be in multiuser mode.
If error occurs please execute following command it will convert database in multi user.*/

ALTER DATABASE TransDB SET MULTI_USER
GO

Cheers,
- Win
"Dont Judge a Book by its Cover"
GilaMonster
GilaMonster
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221560 Visits: 46281
Mac1986 (2/14/2013)
Is there a way than I can just restore the data and not restore the log file. OR create a an empty log file while restoring and not considering the huge log file from the .BAK file?


No. You'll need to find the disk space to restore the DB. A restore puts the database down as it was at the time of backup, file sizes included.

p.s. Log files aren't optional files that you can just not restore or delete without consequence.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


anthony.green
anthony.green
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24086 Visits: 6519
Mac1986 (2/14/2013)
Hi,
I have a situation where in I need to restore a .BAK file and i do not have enough disk space to restore the entire Data and log files from the .BAK file.

Is there a way than I can just restore the data and not restore the log file. OR create a an empty log file while restoring and not considering the huge log file from the .BAK file?

I'm using SQL Server 2008 R2 version.



As Win said you cant do it. SQL needs to restore the database to as it was when it was backed up. So if you have a 10GB MDF and a 1000GB LDF and thats how it was when it was backed up to the BAK file, SQL has to restore it as such.

As Win said, you could do a detach / attach single file DB, but this can be risky and not always successful, as the log is not a throw away file, so you could detach while things are going on, and when it attaches without the log chain in the log fails and causes you more problems.

The only safe way would be to ensure you have enough disk space on the destination server to ensure you can restore as it was backed up.

Failing that, you could look at shrinking the transaction log, but that again could be dodgy, backing up and then restoring to destination.

Also why is the log so big? Has the DB got proper transaction log maintenance running on it?



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search