Restore SQL Server DB without transaction log

后端 未结 5 1873
既然无缘
既然无缘 2021-02-06 20:30

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

相关标签:
5条回答
  • 2021-02-06 21:01

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

    0 讨论(0)
  • 2021-02-06 21:02

    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.

    0 讨论(0)
  • 2021-02-06 21:16

    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.

    0 讨论(0)
  • 2021-02-06 21:21

    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.

    0 讨论(0)
  • 2021-02-06 21:24

    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

    0 讨论(0)
提交回复
热议问题