Full Database Backup with no truncate

  • Hello!

    I need write tsql statement for full database backup without truncate log

    Please Help

  • Why, what are you trying to achieve?

    Full and differential backup does not truncate transaction log, it is (almost) independent. Transaction log backup command can truncate transaction log, and usually is desired behavior in full recovery model.

    Documentation might help: http://msdn.microsoft.com/en-us/library/ms186865.aspx

    Or a good tutorial about sql server backup.

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • The recovery model is: simple

    also

    I write the statement something like this:

    Backup Database [db name]

    to disk = N'Path to file'

    with init, Name=N'full database backup', skip, stats=10;

    Is this will not truncate the log and if it do , what statement will do work that I need?

  • alex_zilberman (11/19/2012)


    The recovery model is: simple

    also

    I write the statement something like this:

    Backup Database [db name]

    to disk = N'Path to file'

    with init, Name=N'full database backup', skip, stats=10;

    Is this will not truncate the log and if it do , what statement will do work that I need?

    why you are worrying about truncate_log when you are using simple recovery model ?

    log get truncated every time checkpoint occur in simple recovery model . (Please anyone correct me if I'm wrong)

    -----------------------------------------------------------------------------
    संकेत कोकणे

  • Log truncation does not shrink the file size, it just marks the parts of the log file free for reuse. You have to explicitly shrink the log file. Don't shrink to a size that is smaller than usual log size for that DB (e.g. 1 GB), because you will waist IO by needless shrinking and growing back to normal size.

    In simple recovery model there are two conditions that transaction log (VLF = virtual log file, a logical unit of a transaction log that can be marked for reuse) is truncated:

    1) there are no active (uncommitted) transactions in that VLF

    2) CHECKPOINT has occurred

    In full recovery model there is one more condition:

    3) log backup has occurred

    In simple recovery model your log will grow e.g. if you have a very long transaction that heavily modified the db.

    HTH,

    Vedran

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • alex_zilberman (11/19/2012)


    Is this will not truncate the log and if it do , what statement will do work that I need?

    No, backup will not truncate the log, nor it will shrink the log file.

    This will shrink the log file if conditions from my previous post are met:

    -- find logical name of the log file

    sp_helpdb 'MyDbName'

    -- Shrink the log to 1000 MB

    CHECKPOINT

    DBCC SHRINKFILE('MyTransactionLog', 1000)

    This could also be useful:

    -- log file size and percentage free

    DBCC SQLPERF (LOGSPACE)

    -- Why the log is not truncated

    select name, log_reuse_wait_desc, recovery_model_desc from sys.databases

    -- oldest active transaction

    DBCC OPENTRAN

    HTH,

    Vedran

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • Of course, shrinking a log is not something that should be regularly done.

    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

Viewing 7 posts - 1 through 6 (of 6 total)

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