{"id":973,"date":"2008-11-26T05:43:00","date_gmt":"2008-11-26T05:43:00","guid":{"rendered":"\/blogs\/paul\/post\/Conference-Questions-Pot-Pourri-10-Shrinking-the-database-before-taking-a-backup.aspx"},"modified":"2017-08-01T17:52:31","modified_gmt":"2017-08-02T00:52:31","slug":"conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/","title":{"rendered":"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup"},"content":{"rendered":"<p style=\"text-align: justify;\">Here&#8217;s a question I got from someone who attended our database maintenance workshop at PASS last week (paraphrased):<\/p>\n<p style=\"padding-left: 30px; text-align: justify;\">I attended your pre-conference session on database maintenance and found it to be very informative.\u00a0 From what you told use though, I think I need to change my nightly backup procedure.\u00a0 I like to get my databases back to as small of a size as possible before backing them up, so I run the following commands to do this before taking the full database backup: <em>BACKUP LOG\u00a0[mydbname] WITH NO_LOG<\/em> and then <em>DBCC SHRINKDATABASE (&#8216;mydbname&#8217;)<\/em>. \u00a0Could you help me with a better way of doing this? We&#8217;re on SQL Server 2005.<\/p>\n<p style=\"text-align: justify;\">And here&#8217;s the answer I sent back:<\/p>\n<p style=\"text-align: justify;\">How large is the database? And how long must you keep the backups around? If the cumulative size of the backups takes up a large proportion of your available storage space (and we&#8217;re talking more than just a single direct-attached 100+GB drive), then it may be worth compressing the backups &#8211; otherwise you&#8217;re likely causing yourself more trouble than its worth.<\/p>\n<p style=\"text-align: justify;\">By doing <em>BACKUP LOG WITH NO_LOG<\/em> you&#8217;re effectively throwing away log records and removing the possibility of doing any kind of point-in-time, or up-to-the-second recovery (see <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/backup-log-with-no_log-use-abuse-and-undocumented-trace-flags-to-stop-it\/\" target=\"_blank\" rel=\"noopener noreferrer\">BACKUP LOG WITH NO_LOG &#8211; use, abuse, and undocumented trace flags to stop it<\/a><\/em>). If you&#8217;re running in the FULL recovery model, and you don&#8217;t care about either of these features, then you should switch to the SIMPLE recovery model. If you really want to be in FULL, don&#8217;t ever use <em>WITH NO_LOG<\/em>.<\/p>\n<p style=\"text-align: justify;\">The amount of transaction log that a full backup requires cannot be changed by you truncating the log. The full backup will backup any log it requires to enable the restored database to be a transactionally consistent copy of the database. See <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/debunking-a-couple-of-myths-around-full-database-backups\/\" target=\"_blank\" rel=\"noopener noreferrer\">Debunking a couple of myths around full database backups<\/a><\/em> and <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/more-on-how-much-transaction-log-a-full-backup-includes\/\" target=\"_blank\" rel=\"noopener noreferrer\">More on how much transaction log a full backup includes<\/a><\/em>.<\/p>\n<p style=\"text-align: justify;\">Doing a <em>DBCC SHRINKDATABASE<\/em> (the same exact operation as a database auto-shrink) will cause massive index fragmentation, and cause file-system fragmentation of the data files, as they will likely need to grow again after you&#8217;ve squeezed all the space out of them. See <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/auto-shrink-turn-it-off\/\" target=\"_blank\" rel=\"noopener noreferrer\">Auto-shrink &#8211; turn it OFF!<\/a><\/em> for more details on the effects.<\/p>\n<p style=\"text-align: justify;\">If you&#8217;re really concerned about backup sizes and space is at a premium, I recommend using a 3rd-party backup compression tool so you&#8217;re not affecting the actual database. Remember also that SQL Server 2008+ has native backup compression too &#8211; see my blog post\u00a0<a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-backup-compression\/\">here<\/a> for more details.<\/p>\n<p style=\"text-align: justify;\">Hope this helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a question I got from someone who attended our database maintenance workshop at PASS last week (paraphrased): I attended your pre-conference session on database maintenance and found it to be very informative.\u00a0 From what you told use though, I think I need to change my nightly backup procedure.\u00a0 I like to get my databases [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,14,25,26,31,52,81,98],"tags":[],"class_list":["post-973","post","type-post","status-publish","format-standard","hentry","category-backuprestore","category-bad-advice","category-compression","category-conference-questions-pot-pourri","category-database-maintenance","category-involuntary-dba","category-shrink","category-transaction-log"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup - Paul S. Randal<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"Here&#8217;s a question I got from someone who attended our database maintenance workshop at PASS last week (paraphrased): I attended your pre-conference session on database maintenance and found it to be very informative.\u00a0 From what you told use though, I think I need to change my nightly backup procedure.\u00a0 I like to get my databases [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2008-11-26T05:43:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-08-02T00:52:31+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/\",\"name\":\"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2008-11-26T05:43:00+00:00\",\"dateModified\":\"2017-08-02T00:52:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup - Paul S. Randal","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/","og_locale":"en_US","og_type":"article","og_title":"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup - Paul S. Randal","og_description":"Here&#8217;s a question I got from someone who attended our database maintenance workshop at PASS last week (paraphrased): I attended your pre-conference session on database maintenance and found it to be very informative.\u00a0 From what you told use though, I think I need to change my nightly backup procedure.\u00a0 I like to get my databases [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/","og_site_name":"Paul S. Randal","article_published_time":"2008-11-26T05:43:00+00:00","article_modified_time":"2017-08-02T00:52:31+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/","name":"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2008-11-26T05:43:00+00:00","dateModified":"2017-08-02T00:52:31+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/conference-questions-pot-pourri-10-shrinking-the-database-before-taking-a-backup\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Conference Questions Pot-Pourri #10: Shrinking the database before taking a backup"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=973"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/973\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}