Execute the
BACKUP LOG statement to back up the currently active transaction log, specifying the following:
* The name of the database to which the transaction log to back up belongs.
* The backup device where the transaction log backup will be written.
Databases use
SIMPLE, FULL or BULK_LOGGED recovery models. To permit log backups, before taking a full database backup, the database need to be set to use the full recovery model by using:
ALTER DATABASE myDB SET RECOVERY FULL statement, this is an important step.
ALTER DATABASE myDB SET RECOVERY FULL
BACKUP LOG myDB
TO myDB_log1
GO
If
database is damaged & inaccessible, you'd need to use the
NO_TRUNCATE clause, provided that the transaction log file is accessible & undamaged .
ALTER DATABASE myDB SET RECOVERY FULL
BACKUP LOG myDB
TO myDB_log1
WITH NO_TRUNCATE
GO
This
WITH NO_TRUNCATE clause allows the active part of the transaction log to be backed up even if the
database is inaccessible.
You can also
shrink the log (LDF) file without shrinking database (MDF) file by using the
DBCC SHRINKFILE syntax:
Shrink the log file to 1MB:
DBCC SHRINKFILE (myDB_log, 1)[WITH NO_INFOMSGS]
To
empty the log file:
DBCC SHRINKFILE (myDB_log, EMPTYFILE) [WITH NO_INFOMSGS]