BUTOZIP.BAT (Back Up to Zip) replaces my earlier *BUTO*.BAT tools.
BUTOZIP creates a compressed file, a zip file, containing a designated set of files you want to archive (back up). When you invoke BUTOZIP, you specify the target drive:\directory, e.g., E:\ARCHIVE, where you want the zip file to be placed. In the following text I'll use "directory" in place of "folder", but mean the same thing.
BUTOZIP uniquely names the zip file by using a sequence number (a generation number), the creation date, and a userid. A separate sequence number counter is maintained for each Windows user. With this naming, new backups don't overlay previous backups in the target drive:\directory. This allows multiple generations of backups to exist in the directory and allows multiple users to share that directory. With this zip file naming convention, it is very easy to locate a specific backup. Here is how a group of such files might be named in a target directory, e.g., E:\ARCHIVE, shared by two users:
For example, Bob might execute BUTOZIP.BAT E:\ARCHIVE, where his BUTOZIP.BAT has been edited to back up these directories (and their subdirectories) and files: C:\MISCPROG, C:\USERS\BOB\WORK, C:\USERS\BOB\DOCUMENTS\LETTERS, C:\SAVE\RESUME.DOC, and D:\BOOKS\DRAFTS. This is data which Bob changes frequently and would really hate to lose. The total disk space taken up by this data is not particularly large, maybe a few hundred MB. Note that BUTOZIP is not intended to back up very large directories, such as you might have for music or photos. The result of Bob's execution of BUTOZIP is the creation of a new zip file in E:\ARCHIVE, which might be on an external hard drive or flash drive. Using the sample directory shown above, if Bob ran BUTOZIP on 12/3/12, the new file will be named Bob_#1542__2012-12-03.zip.
To retrieve some archived data, use File Explorer (previously called Windows Explorer) to go to the appropriate zip file and double-click the file to have Windows open that archive. Then use File Explorer to go down thru the directories in the zip file until the desired data is located. Standard Windows procedures can then be used to copy, print, etc., the data.
By setting up a Windows shortcut, you can make running BUTOZIP a single-click operation to archive hundreds or thousands of scattered files into a single, compressed, organized file. Run BUTOZIP as often as needed; all the zip files created (one per BUTOZIP invocation) will nicely coexist in the target directory. You can create multiple shortcuts, each going to a separate target directory, e.g., one on a hard drive and another on a flash drive. Additionally, you can have multiple copies of the BAT file, each with a different name, e.g., BU_WORK.BAT, BU_GAMES.BAT, etc., where each is edited to back up a different set of files if you want to keep the backups separate. Doing regular backups can also be automated via the Windows Task Scheduler.
To make most efficient use of the BUTOZIP, it helps if you have organized data along the lines described in Organizing Your Data To Simplify Backups (mainly just grouping the data into a few directories, but without including many extraneous files), although this organization is not required. More overview information can be found in the "Selective Backups" section of Tools for Making Backups. These references are sections of the jgkhome.name\PC_Info\PC-InetNotes.htm file.
My past testing was on Windows XP, Vista, 7, and 8.1. I am currently using BUTOZIP on Windows 10 and have found no problems.
Before starting to use BUTOZIP, you must do some setup. This has to be done only once.
You must create the directory before running BUTOZIP. It cannot be the root directory, i.e, F:\ in the example above. Precluding the root directory lessens the chance you might accidentally send the backup to the wrong device, e.g., if you have plugged in the wrong flash drive. BUTOZIP will detect unacceptable directories for this and other situations; it will issue an error message and abort before copying any files.
You can specify the target directory as an optional parameter when you invoke BUTOZIP.BAT, e.g., BUTOZIP.BAT F:\DAILYBACKUPS. If you run BUTOZIP without this parameter, the default target directory used by BUTOZIP is D:\BACKUPS.
Although the examples here use a single-level directory, and that is probably what most people will use, you can also specify a multi-level directory as the target, e.g., D:\SAVE\2012\BACKUPS.
The location and name for some Windows directories, e.g., Documents, differs from release to release of Windows, e.g., Windows XP vs. Windows 7. For some directories in some releases, the name required by XCOPY ("Documents") actually differs from the name displayed by Explorer ("My Documents"). A similar thing applies to My Music, My Pictures, etc. This may be dependent on which release or even edition of Windows is involved; you will need to experiment to see what applies for your system. Fortunately the "My" naming confusion seems to have been eliminated in the later Windows release. In any event, you will also need to experiment to find where your applications bury their critical data so you can back it up. Unfortunately some applications may make this more difficult than it should be.
BUTOZIP uses the Windows XCOPY command to copy files. Information about this command is in the table below and in notes in the BAT file. The best idea would be to just use as a model the XCOPY commands in the sample BUTOZIP.BAT; the notes and XCOPY commands are near the bottom of the BAT file, surrounded by comment lines of $$$$$$$$$s. The name of the directory you copy to need not be the same as what you are copying from. This may help you put your backup in a simpler, more meaningful structure than the structure(s) it came from.
You don't have to list all the subdirectories; just list the master directories containing the subdirectories of interest and use the XCOPY /S option to copy the whole directory tree. (That's in fact why you should organize your data as described in Organizing Your Data To Simplify Backups.) You can also list individual files if they are not easily put into your master directories organization. For each directory copied, you can specify the name the copy will have in the backup; thus Windows' very long directory names can be shortened, if desired.
XCOPY cannot copy a locked file, a file opened for exclusive use by some process. If you want to use BUTOZIP to back up such files, you should close them first. If you forget to do so, the associated XCOPY will fail and issue an error message, such as "Sharing violation". Before running BUTOZIP I sometimes forget to close Thunderbird, which has some locked files. To make the XCOPY failure reason obvious, I put logic in BUTOZIP warning me to close Thunderbird and then rerun BUTOZIP. If you have similar files, you might include and modify that code.
The BAT file can be invoked in a number of ways. Here are a few:
If the backup completes successfully, BUTOZIP will display the main report file as its final output in the command window, below all the displayed XCOPY commands. This report normally consists of a number of "xx File(s) copied" lines, one for each XCOPY you had in the BAT file, and a "******* COPY TO TARGET DIRECTORY WAS SUCCESSFUL! *******" if BUTOZIP found no errors. There will also be some lines with timestamps taken at major points in the operation, as well as a display of some key variables. If an error was detected, either Windows or BUTOZIP should report it and then abort the operation. A successful run should produce something similar to this as the final output:
====================================================================== BUTOZIP version 1.4 report on Thu 08/10/2015 ---------------------------------------------------------- 6:00:00.17 21 File(s) copied 310 File(s) copied 1525 File(s) copied 181 File(s) copied 144 File(s) copied 4 File(s) copied 1 File(s) copied 2 File(s) copied 1 File(s) copied 198 File(s) copied ---------------------------------------------------------- 6:00:14.93 Target directory for zip file: X:\BACKUPS Backup: #2771 ******* COPY TO TARGET DIRECTORY WAS SUCCESSFUL! ******* C:\BUTOZIP_TEMP\Jeff_#2771__2015-08-10.zip to X:\BACKUPS ---------------------------------------------------------- 6:00:35.07
CAUTION: If the BAT file cannot complete successfully, e.g., if there is not enough space on the destination medium to hold the zip file, BUTOZIP will abort, either automatically or as a result of your response to a prompt. Then you must do a manual cleanup of the work directory and the target directory. (You can just delete the whole work directory after looking at the contents; it will be rebuilt the next time BUTOZIP is run.) The TDIR subdirectory and zip file in the work directory can be very large and serve no purpose after the BAT file exits. It is not good to leave them around if the BAT file did not erase them.
CAUTION: In Windows 10 I have seen cases where RMDIR erroneously thinks there are some hidden files in the temporary TDIR subdirectory tree. Then it displays warning messages and leaves a TDIR skeleton subdirectory tree in the work directory when doing its cleanup. This seems to happen randomly (some timing problem?). You can just delete these trash subdirectory trees from the work directory at your convenience. You would also need to delete such a tree if there actually had been hidden files in some directory.
NOTE: Color capability has now been added to BUTOZIP, e.g., to display a different background color in the command window if an error has been detected vs. if BUTOZIP completed successfully. If you don't like the colors used, you can change the @COLOR commands when you edit the BAT file.
The following table lists some key variables used by BUTOZIP. You probably will not need to change any of them. (As noted above, the main tailoring you must do to BUTOZIP.BAT is setting up the XCOPY commands.) This table shows you the main components used to construct the zip file name. Knowing the name structure will help you use the backups most effectively. Details are in the How It Works section below.
|environment variable||default value
|ZIP||C:\JGK\7ZIP\7ZA.EXE||ZIP specifies the location and name of the 7-Zip command line program. This program can be downloaded from here. Be sure to download the "7-Zip Command Line Version" zip file. (This 32-bit program works fine on both 32-bit and 64-bit PCs.) Unzip the file, placing the contents into the directory named by the front part of the ZIP variable, e.g., in the C:\JGK\7ZIP directory in this case. If you want to use a different name for this directory, you can do so; be sure to modify this SET variable to match.|
|BUTARGET||D:\BACKUPS||You intend for the zip file created by BUTOZIP to end up in a specific drive:\directory. The BUTARGET variable names the default target drive:\directory. If this default target location is not what you want, you can override it by invoking BUTOZIP.BAT with a parameter, e.g., BUTOZIP.BAT F:\DAILYBACKUPS. In any event, the chosen target drive:\directory must already exist before BUTOZIP.BAT is run.|
|BUWORK||C:\BUTOZIP_TEMP||BUWORK specifies the name of a hard drive directory that can be used as a work area. It should be on a hard drive for speed. The user running BUTOZIP must have full access to the directory contents (read/write/create/erase). This is where the zip file will be built initially before it is moved to its final destination. The BAT file creates this directory if it does not already exist. If the default of C:\BUTOZIP_TEMP is not appropriate for your PC, modify the SET to specify another location.|
|UNAME||%USERNAME%||The %USERNAME% setting for UNAME will resolve to the name of the user running BUTOZIP. That is, it is the user name for the Windows PC account under which the BAT file is run. If multiple users share the PC, using different accounts, they can all make backups in the same target directory. A user name will be made part of each zip file's name, allowing each file to be associated with the proper user.|
|XCOPY commands specify the names of
the directories and files to be archived, as well as the names
to be given to the copied data. Options can be used to say
whether a whole directory tree should be copied (/S) and
whether hidden files (/H) and empty directories (/E) are to be
copied. Output messages are directed to a report file. The /Q
option suppresses some unneeded XCOPY messages.
The general command format is:
XCOPY from-data to-data
options >> report-file 2>&1
CAUTION: If any directory or file names (including parts of the TDIR directory name described below) contain blanks (spaces), be sure to surround the full names with quotes in the XCOPYs. That is the standard Windows requirement for such names when used in a command. For example:
XCOPY "C:\LONG SPACED NAME\*.*" "%TDIR%\MISC\*.*" /S /H /Q >> %BUREPORT% 2>&1
Here is the basic logic flow. The most important actions are echoed to the display while the BAT file is running.
Here are the main changes to date for the BUTOZIP.BAT file and this Overview file.