{"id":12210,"date":"2018-07-26T14:23:18","date_gmt":"2018-07-26T19:23:18","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=12210"},"modified":"2018-07-26T14:23:18","modified_gmt":"2018-07-26T19:23:18","slug":"sql-server-shrink-transaction-logs","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=12210","title":{"rendered":"SQL Server: Shrink Transaction Logs"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Script\">Script<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Script\"><h2>Script<\/h2><\/span>\n<pre lang=\"sql\">\r\n-- Backup database:\r\nUSE master;\r\nBACKUP DATABASE dbname\u00a0 TO DISK = 'D:\\Backup\\dbnameFull.bak' WITH FORMAT; \u00a0\u00a0\r\nGO\r\n\r\n-- Backup transaction log:\r\nBACKUP LOG dbname TO DISK = 'D:\\Backup\\dbnameLog.TRN'\r\nGO\r\n\r\n-- Set recovery mode to SIMPLE:\r\nUSE master;\r\nALTER DATABASE dbname SET RECOVERY SIMPLE;\r\nGO\r\n\r\n-- Shrink transaction log file to 1mb:\r\nUSE dbname;\r\nGO\r\nDBCC SHRINKFILE(2, 1)\r\nGO\r\n\r\n-- Set recovery mode to FULL if needed:\r\nUSE master;\r\nALTER DATABASE dbname SET RECOVERY FULL;\r\nGO\r\n<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"https:\/\/community.spiceworks.com\/topic\/276136-how-to-safely-delete-archive-ldf-files\">https:\/\/community.spiceworks.com\/topic\/276136-how-to-safely-delete-archive-ldf-files<\/a><br \/>\n* <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/backup-restore\/recovery-models-sql-server?view=sql-server-2017\">Recovery Models (SQL Server)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Script &#8212; Backup database: USE master; BACKUP DATABASE dbname\u00a0 TO DISK = &#8216;D:\\Backup\\dbnameFull.bak&#8217; WITH FORMAT; \u00a0\u00a0 GO &#8212; Backup transaction log: BACKUP LOG dbname TO DISK = &#8216;D:\\Backup\\dbnameLog.TRN&#8217; GO &#8212; Set recovery mode to SIMPLE: USE master; ALTER DATABASE dbname &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=12210\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[17],"tags":[],"class_list":["post-12210","post","type-post","status-publish","format-standard","hentry","category-sqlserver"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-3aW","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/12210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12210"}],"version-history":[{"count":1,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/12210\/revisions"}],"predecessor-version":[{"id":12211,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/12210\/revisions\/12211"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}