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

  • 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.

  • 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"

  • 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
  • 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?

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply