{"id":59,"date":"2006-11-17T14:24:41","date_gmt":"2006-11-17T14:24:41","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=59"},"modified":"2006-11-19T15:01:56","modified_gmt":"2006-11-19T15:01:56","slug":"using-scheduled-tasks-and-batch-files-to-do-automatic-backups","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=59","title":{"rendered":"Using Scheduled Tasks and batch files to do automatic backups"},"content":{"rendered":"<p>As I&#8217;ve started storing all of my project work and GTD notes in my Wiki program, I thought it might be a good idea to take regular backups of the text files it uses for data. And being a geek, I thought I&#8217;d automate it. \ud83d\ude42<\/p>\n<pre><code style=\"font-size: smallest\">@ECHO OFF\r\nREM this makes the batch file less noisy - dont \r\nREM  output commands to screen\r\n<br \/>\r\nREM limit scope for environment variables created here \r\nREM   to within this batch file only\r\nSETLOCAL\r\n<br \/>\r\nREM make a note of where the current directory is \r\nREM   so we can go back there afterwards\r\nREM  (useful when running this batch file manually)\r\nset DIR_TO_RESTORE=%CD%\r\n<br \/>\r\nREM run the   'date \/t' command\r\nREM   this outputs in the format:\r\nREM   19\/11\/2006\r\nREM  (probably different for people with non-UK regional\r\nREM   settings)\r\n<br \/>\r\nREM Using for to look at bits of date individually...\r\nREM  FOR \/F [\"options\"] %variable IN ('command1') DO command\r\nREM   options - \r\nREM      tokens - identify which bits of the date output I want\r\nREM               (3 tokens - day month year), \r\nREM      delimiters - how they are separated  ('\/')\r\nREM                 (users with non-UK regional settings might \r\nREM                   need to change this - e.g. for '-')\r\nREM   command - \r\nREM     1) date \/t  - show date without prompting to change it\r\nREM     2) set  - set environment variables to store each token\r\nFOR \/f \"tokens=1-3 delims=\/ \" %%G IN ('date \/t') DO (\r\n    REM set environment variables to store individual date values\r\n    REM  (assumes date\/month\/year - users with non-UK regional\r\n    REM     settings might want to switch date and month)\r\n\tset dd=%%G\r\n\tset mm=%%H\r\n\tset yy=%%I)\r\n<br \/>\r\nREM this gives us a numeric date - in the format yyyyMMdd\r\nREM  which is useful in filenames for sorting\r\nset TODAY=%yy%%mm%%dd%\r\n<br \/>\r\nREM go to first directory containing something to backup\r\nREM  tar it up, and move it to a backups directory\r\ncd \"C:\\\\Documents And Settings\\\\Administrator\\\\My Documents\\\\bLADE My Documents\\\\\"\r\n\"C:\\\\cygwin\\\\bin\\\\tar.exe\" -cvf %TODAY%_gtd.tar WM_Wiki_Pages\r\nmove %TODAY%_gtd.tar \"..\\\\My Personal\\\\WMWiki Backups\\\\.\"\r\n<br \/>\r\nREM repeat as required\r\ncd \"C:\\\\Documents and Settings\\\\Administrator\\\\My Documents\\\\My Personal\\\\\"\r\n\"C:\\\\cygwin\\\\bin\\\\tar.exe\" -cvf %TODAY%_ref.tar \"My WM Wikis\"\r\nmove %TODAY%_ref.tar \"..\\\\My Personal\\\\WMWiki Backups\\\\.\"\r\n<br \/>\r\nREM finished! go back to where we started\r\ncd %DIR_TO_RESTORE%\r\n<br \/>\r\nREM end scope for environment variables\r\nENDLOCAL<\/code><\/pre>\n<p><!--more-->Okay, so I&#8217;ve cheated&#8230; I&#8217;m using &#8216;tar&#8217; from <a title=\"LifeHacker intro to cygwin\" target=\"_blank\" href=\"http:\/\/www.lifehacker.com\/software\/cygwin\/geek-to-live--introduction-to-cygwin-part-i-179514.php\">cygwin<\/a> to package up and compress the backed-up files. But I couldn&#8217;t find a command-line way to access Windows zip, and I prefer tar files anyway. <\/p>\n<p>Apart from that minor revealing of my UNIX roots, I think it&#8217;s quite a nice Windows solution for a free automated backup. I&#8217;ve saved this file to C:\\bin\\backupwikis.bat and have set up Windows Scheduled Tasks (go to Control Panel -> Scheduled Tasks) to run it at 11am every day. <\/p>\n<p><img decoding=\"async\" src=\"post-images\/061117-schedule.gif\" alt=\"screenshot of Scheduled Tasks\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I&#8217;ve started storing all of my project work and GTD notes in my Wiki program, I thought it might be a good idea to take regular backups of the text files it uses for data. And being a geek, I thought I&#8217;d automate it. \ud83d\ude42 @ECHO OFF REM this makes the batch file less [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=59"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}