{"id":89,"date":"2019-04-19T20:46:00","date_gmt":"2019-04-19T20:46:00","guid":{"rendered":"https:\/\/blog.nmoleosoftware.com\/?p=89"},"modified":"2022-12-16T21:58:46","modified_gmt":"2022-12-16T21:58:46","slug":"how-to-schedule-zipped-backups-of-a-folder-on-windows","status":"publish","type":"post","link":"https:\/\/blog.nmoleosoftware.com\/index.php\/2019\/04\/19\/how-to-schedule-zipped-backups-of-a-folder-on-windows\/","title":{"rendered":"How to Schedule Zipped Backups of a Folder on Windows"},"content":{"rendered":"\n<p>I own and operate a<a href=\"https:\/\/web.archive.org\/web\/20190419015004\/http:\/\/nmoleocraft.com\/\"> public Minecraft server<\/a> and one of the things I struggle with is backups. I want to make sure that if the server gets griefed or hacked, my house burns down, or my hard drive dies, my world is still safe. Here is a tutorial on how to build a batch file that will copy and zip those files and move them to Google Drive to be synced to the cloud.<\/p>\n\n\n\n<p>Create a file with the extension of&nbsp;\u201c.bat\u201d. I called mine&nbsp;\u201cbackup.bat\u201d and open it with your preferred text editing software (I used Notepad)<\/p>\n\n\n\n<p>On the first line, type the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@echo off<\/code><\/pre>\n\n\n\n<p>This means to not display every command that is being run in the command prompt window.<\/p>\n\n\n\n<p>Now, create a directory on your hard drive. I used the directory&nbsp;\u201cD:\\tmp.backup\u201d but you can use anything that works for you. This is where your batch file and temporary files will be stored.<\/p>\n\n\n\n<p>On the next line in your batch file, type the text below, replacing my directory with your directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd D:\\tmp.backup<\/code><\/pre>\n\n\n\n<p>This tells the program where to look for and place the temporary files.<\/p>\n\n\n\n<p>Now, type this code, replacing the first path in quotes with the directory you want to copy, and the second path in quotes with your temporary directory, but add a backslash and the name of the folder you are copying.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo d | xcopy \u201cDIRECTORY TO COPY\u201d \u201cTEMPORARY DIRECTORY\\FOLDER NAME\u201d<\/code><\/pre>\n\n\n\n<p>If the directory you are copying has subfolders, add a new line for each of those subdirectories.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo d | xcopy \u201cDIRECTORY TO COPY\\SUBDIRECTORY\u201d \u201cTEMPORARY DIRECTORY\\FOLDER NAME\\SUBFOLDER\u201d<\/code><\/pre>\n\n\n\n<p>The next two lines of code are used for adding a timestamp to the name of the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set hr=%time:~0,2%\nif \u201c%hr:~0,1%\u201d equ \u201c \u201d set hr=0%hr:~1,1%<\/code><\/pre>\n\n\n\n<p>If you do not want the timestamp, do not add these lines to your batch file.<\/p>\n\n\n\n<p>Go to&nbsp;<a href=\"https:\/\/web.archive.org\/web\/20190419015004\/http:\/\/t.umblr.com\/redirect?z=http%3A%2F%2Fwww.7-zip.org%2Fdownload.html&amp;t=ZjA3YTgzNmY5N2YxMzE0MmE0OWYzODFmZDc4Y2Y1MWMwN2QyMWY5MixsanphV0xnSw%3D%3D&amp;b=t%3AXk-izdk_OsJfCit8Y3HwwQ&amp;p=https%3A%2F%2Fnmoleosoftware.tumblr.com%2Fpost%2F157500911277%2Fwindows-how-to-schedule-zipped-backups-of-a&amp;m=0\">http:\/\/www.7-zip.org\/download.html<\/a>&nbsp;and click the download that says&nbsp;\u201c7-Zip Command Line Version\u201d. Copy the executable file out of the downloaded zip folder and put it in your temporary directory. The code for zipping the folder will not work unless you download this!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>7za a -tzip FOLDERNAME_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.zip \u201cFOLDERNAME\u201d<\/code><\/pre>\n\n\n\n<p>Use this code if you want the timestamp. The name of the zip folder will look something like \u201cFOLDERNAME_2017_02_20.zip\u201d.<\/p>\n\n\n\n<p>If you do not want the timestamp, use this code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>7za a -tzip \u201cFOLDERNAME.zip\u201d \u201cworld\u201d<\/code><\/pre>\n\n\n\n<p>Paste the below code in your batch file to copy the zipped directory to Google Drive, or whatever backup service you are using.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo yes | xcopy FOLDERNAME_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.zip \u201cFOLDER-IN-BACKUP-SERVICE\\FOLDERNAME\"<\/code><\/pre>\n\n\n\n<p>If you didn\u2019t use the timestamp, use this code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo yes | xcopy FOLDERNAME.zip \u201cFOLDER-IN-BACKUP-SERVICE\\FOLDERNAME\"<\/code><\/pre>\n\n\n\n<p>Now, use this code to delete the zipped folder that still remains in the temporary folder<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo yes | del FOLDERNAME_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.zip<\/code><\/pre>\n\n\n\n<p>Again, if you didn\u2019t use the timestamp, use this code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo yes | del FOLDERNAME.zip<\/code><\/pre>\n\n\n\n<p>Use this code to delete the copy of the folder in the temporary directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo yes | rmdir \/s \u201cTEMPORARY DIRECTORY\\FOLDER NAME\u201d<\/code><\/pre>\n\n\n\n<p>Last but not least, type the word&nbsp;\u2018pause\u2019 in on the last line. This tells Windows not to close the window after it finishes<\/p>\n\n\n\n<p>pause<\/p>\n\n\n\n<p>Here is a copy of the code file with the timestamps\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@echo off\ncd TEMPORARY DIRECTORY\n\necho d | xcopy \u201cPATH OF FOLDER TO COPY\u201d \u201cTEMPORARY DIRECTORY\\NAME OF FOLDER TO COPY\u201d\necho d | xcopy \u201cPATH OF FOLDER TO COPY\\SUBDIRECTORY\u201d \u201cTEMPORARY DIRECTORY\\NAME OF FOLDER TO COPY\\SUBDIRECTORY\u201d\n\nset hr=%time:~0,2%\nif \u201c%hr:~0,1%\u201d equ \u201c \u201d set hr=0%hr:~1,1%\n\n7za a -tzip FOLDERNAME_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.zip \u201cFOLDER NAME\u201d\n\necho yes | xcopy FOLDERNAME_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.zip \u201cFOLDER IN BACKUP SERVICE\u201d\n\necho yes | del FOLDERNAME_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.zip\n\necho yes | rmdir \/s \u201cTEMPORARY DIRECTORY\\FOLDER NAME\u201d\n\npause<\/code><\/pre>\n\n\n\n<p>Here is a copy without the timestamps:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@echo off\ncd TEMPORARY DIRECTORY\n\necho d | xcopy \"PATH OF FOLDER TO COPY\u201d \u201cTEMPORARY DIRECTORY\\NAME OF FOLDER TO COPY\u201d\necho d | xcopy \u201cPATH OF FOLDER TO COPY\\SUBDIRECTORY\u201d \u201cTEMPORARY DIRECTORY\\NAME OF FOLDER TO COPY\\SUBDIRECTORY\u201d\n\n7za a -tzip FOLDERNAME.zip \u201cFOLDER NAME\u201d\n\necho yes | xcopy FOLDERNAME.zip \u201cFOLDER IN BACKUP SERVICE\u201d\n\necho yes | del FOLDERNAME.zip\n\necho yes | rmdir \/s \u201cTEMPORARY DIRECTORY\\FOLDER NAME\u201d\n\npause<\/code><\/pre>\n\n\n\n<p>Now, open Task Scheduler and click&nbsp;\u201cCreate Basic Task\u201d on the left. Type in a name and description, and choose how often you want the backup to happen.<\/p>\n\n\n\n<p>When you get to Action, click&nbsp;\u201cStart a program\u201d. Click Browse, and find your batch file. Click Next and Finish. Enjoy your backups!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I own and operate a public Minecraft server and one of the things I struggle with is backups. I want to make sure that if the server gets griefed or hacked, my house burns down, or my hard drive dies, my world is still safe. Here is a tutorial on how to build a batch&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":158,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":2,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions\/159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/media\/158"}],"wp:attachment":[{"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nmoleosoftware.com\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}