{"id":136,"date":"2009-01-15T18:17:00","date_gmt":"2009-01-15T23:17:00","guid":{"rendered":"https:\/\/rick.sh\/index.php\/2009\/01\/15\/automate-backups-of-sql-express-database\/"},"modified":"2009-01-15T18:17:00","modified_gmt":"2009-01-15T23:17:00","slug":"automate-backups-of-sql-express-database","status":"publish","type":"post","link":"https:\/\/rick.sh\/index.php\/2009\/01\/15\/automate-backups-of-sql-express-database\/","title":{"rendered":"Automate backups of SQL Express database"},"content":{"rendered":"<p>We have a workorder tracking system that runs on SQL Express 2005 edition. One of the many limitations of SQL Express, is its lack of the SQL Agent found on full versions of SQL, which allows automated tasks to be scheduled, one being scheduled backups.<\/p>\n<div>So to work around this limitation, I created a scheduled task in Windows, which runs the following commands from a batch file to automatically backup the database:<\/div>\n<div>\n<div>\n<div><\/div>\n<div>osql -E -S <span style=\"font-style: italic;\">SERVERSQLINSTANCE<\/span> -Q &#8220;BACKUP DATABASE [<span style=\"font-style: italic;\">DATABASENAME<\/span>] TO \u00a0[<span style=\"font-style: italic;\">BACKUP_DEVICE<\/span>] WITH \u00a0RETAINDAYS = <span style=\"font-style: italic;\">7<\/span>, NOFORMAT, NOINIT, \u00a0NAME = N&#8217;DATABASENAME-Full Database Backup&#8217;, SKIP, NOREWIND, NOUNLOAD, \u00a0STATS = 10&#8243;<\/div>\n<div>osql -E -S <span style=\"font-style: italic;\">SERVERSQLINSTANCE<\/span> -Q &#8220;BACKUP LOG <span style=\"font-style: italic;\">DATABASENAME <\/span>WITH TRUNCATE_ONLY&#8221;<\/div>\n<div>osql -E -S <span style=\"font-style: italic;\">SERVERSQLINSTANCE<\/span> -Q &#8220;DBCC SHRINKDATABASE (<span style=\"font-style: italic;\">DATABASENAME<\/span>, TRUNCATEONLY)&#8221;<\/div>\n<div><\/div>\n<\/div>\n<div>OK, so one thing to do before you go out and use this, is you need to create a &#8220;Backup Device&#8221;, which you can do with <span style=\"font-weight: bold;\">SQL Management Studio Express<\/span>. If you need a copy, just google it; it is a free download from Microsoft. The second and third commands are for basic DB maintenance, but it doesn&#8217;t hurt to run them as well, at the same time.<\/div>\n<div>That&#8217;s about it, just edit the commands above, set your retention period (RETAINDAYS = x), put in a batch file, and create a scheduled task with your time requirements.<\/div>\n<div>Email me if you have any questions or suggestions.<\/div>\n<div>&#8211;Rick Estrada<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We have a workorder tracking system that runs on SQL Express 2005 edition. One of the many limitations of SQL Express, is its lack of the SQL Agent found on full versions of SQL, which allows automated tasks to be scheduled, one being scheduled backups. So to work around this limitation, I created a scheduled &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rick.sh\/index.php\/2009\/01\/15\/automate-backups-of-sql-express-database\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Automate backups of SQL Express database&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6,7,36,37],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/posts\/136"}],"collection":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":0,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"wp:attachment":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}