Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Urgent help in Script to restore the database by creating empty log file Expand / Collapse
Author
Message
Posted Thursday, February 14, 2013 12:13 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 24, 2014 10:27 PM
Points: 219, Visits: 688
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.

Post #1419834
Posted Thursday, February 14, 2013 12:23 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 24, 2014 2:10 AM
Points: 109, Visits: 460

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"
Post #1419840
Posted Thursday, February 14, 2013 1:43 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 3:46 PM
Points: 42,462, Visits: 35,525
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 2008, MVP
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

Post #1419867
Posted Thursday, February 14, 2013 1:47 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:51 AM
Points: 5,142, Visits: 4,937
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
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

Post #1419871
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse