I know my MS SQL Server pretty well.
I know the difference between FULL and SIMPLE recovery modes.
I know how to shrink down a bloated transaction log:
ALTER DATABASE TargetDB SET RECOVERY SIMPLE
BACKUP LOG TargetDB WITH TRUNCATEONLY
DBCC SHRINKFILE (TargetDB_log, 1)
And I know that ideally a smart DBA has a disaster recovery plan for a production database in FULL recovery mode that consists of regular FULL and LOG backups that empty the T-log so it doesn't bloat into eternity and wind up consuming the entire disk system of the database server. It just ain't that hard.
I used to do it for a medical records warehousing company and had several million patient records under my fingertips. They were backed up quite thoroughly, and the T-logs were never more than perhaps 250MB to catch the serialized transactions of the busiest periods of activities between log backups. Each of these databases had MDF files that were anywhere from 5 to 100GB, and I had dozens of them to monitor.
However... the people that sometimes send me databases that I work with... do not apparently know these things.
IMO, a DBA that doesn't know how to keep a transaction log manageable should be stoned to death with old SCSI/Fibre Channel drives, but that's a battle for another day.
The battle I'm trying to fight right now, is:
Assume you have a BAK file made on SQL Server.
When you run RESTORE FILELISTONLY FROM DISK = 'E:\Path\to\backup.bak'
you end up getting this:
DBName1 E:\SQLData\DBName.mdf D PRIMARY 20971520
DBName1_log E:\SQLData\DBName_log.ldf L NULL 22454526336
Yes, that log file is 22,454,526,336 bytes (22GB) in size.
Yes, the actual MDF file is only 20MB.
All you have is the BAK file.
This idgit spent hours transmitting what should be a 20MB database to you, sending a worthless 22GB log file.
You don't have the MDF file, so you can't use sp_attach_single_file_db to generate a clean log.
Is there any feasible way at all of doing a partial restore and NOT restoring the LDF file?
I deliberately created a bloated T-log in one of my test databases (in FULL recovery mode and the LDF file set to autogrow) with the following looping code and letting it run for 15 minutes:
declare @i int
set @i = 1
while @i < 2
begin
begin transaction
INSERT INTO junk_table (col1) VALUES ('junk')
commit transaction
begin transaction
DELETE FROM junk_table
WHERE col1 = 'junk'
commit transaction
end
Then I backed up the database to a BAK file.
I tried:
RESTORE DATABASE MDFTEST FILEGROUP = 'PRIMARY'
FROM disk = 'E:\Path\to\backup.bak'
WITH PARTIAL
, MOVE 'DBName1' TO 'E:\SQLData\MDFTEST.mdf'
But that complains that I am not giving a suitable MOVE command for the LDF file.
When I give a MOVE command for the LDF file, then it restores my bloated LDF file in the BAK file.
I tried adding the NORECOVERY flag to the RESTORE command, but I still get the same error about redirecting the LDF file.
Is there any way to issue a RESTORE command that skips population of the LDF file and just creates a new one?