Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at: https://www.gnu.org/copyleft/fdl.html.
STF (documentation system) is hosted at https://sourceforge.net/p/simpletextformatter
The PDF version of this document may be downloaded from Source Forge:
https://sourceforge.net/projects/windows-power-utilities/files/Install_Backup_Script/ InstallBacklup.pdf/download
InstallBackup may be downloaded from:
https://sourceforge.net/projects/windows-power-utilities/files/Install_Backup_Script/ InstallBackup.bat/download
I first considered a script to install a customized script several years ago when I needed a local backup for several PC's. Rather than copy across each PC and then re-customize the new script, I decided to just write a simple script to install a simple backup system. That worked very well, until I decided to release it in response to some requests for a simple backup. Suddenly it was necessary to make the customization process clear so that others could use it. Then there was the problem that currently there are several PC architectures in use: One with a Documents folder on the C-Drive, one with the Documents folder replaced by OneDrive\Documents -- also on the C-Drive, and one where user documents are kept on the D-Drive. Suddenly my simple world got complicated. After some machinations, I came up with the present incarnation. I hope it is easy to use and flexible enough to support most installations.
I feel it is necessary to mention the security aspects of a backup process. A cloud backup uses a secure link to upload the user's documents to a cloud server. The documents are encrypted prior to uploading. A good cloud backup then goes through a massive compression process, where commonality across files is used along with other compression techniques to drastically reduce the storage requirements. This cuts the storage costs. It also increases the restore time. This is because the cloud server must unwind all the compression to be able to download the requested documents. It is a secure process both from a security standpoint and from a physical standpoint. Physical in the sense that the backup is geographically distributed to mitigate the risk of a fire on the backup site. So cloud backups are a good idea. (I use I-Drive, but as far as I know, they are all good.) It also seems to take forever to restore large amounts of data from a cloud server, not to mention the cost of downloading a lot of data.
Restore from a local backup is a fairly quick process. It operates at USB-3 speeds and has zero transport costs. Security, on the other hand, relies on the physical security of your house. You can make a local backup secure by using whole disk encryption for the USB drive if you want to. Most people just assume that no one will break-in and steal their backup drive, and most of the time that is correct. If the damage that would incur from someone accessing your data is severe, then by all means use whole disk encryption.
All in all, I hope this is useful. I have found it so.
Barry Stanly
Henderson NV
May 2022
2 Installation
2.1 Required Resources
3 Documents Vs OneDrive\Documents
Table 2-I Control Backup Options
Table 2-II Options for Standard Folders
Table 2-III Advanced Configuration
Figure 5-1 E-Mail Client Server Architecture
Figure 7-2 Operation
This document describes Windows batch script InstallBackup.bat that installs an automated backup system. Documents, Mail, and user defined folders are backed up to an attached device (Internal disk, USB drive, etc.) Daily and monthly backups are supported.
InstallBackup.bat is a command file that installs a simple backup system. The backup system runs five minutes after a Windows PC is started and it copies specified folders to a backup drive. It maintains separate archives for each day of the week and for each month. It is useful as a quick recovery system. It is not a substitute for an off-site backup.
InstallBackup.bat is free software. The source is provided in InstallBackup.zip. Malware detectors usually do not object to its execution (it has no viruses.) However Windows does not recognize it as a certified program. (certification costs money.) So Windows may block execution. If this happens, just click the ignore option.
First double-click on InstallBackup.bat. This will create the two scripts: Begin.bat and Startup.bat. Then go to C:\Users\'you'\Startup, edit Startup.bat (right-click and choose edit)(1) to select the desired options(2).
Scroll down until you reach the configuration section. Then edit the configuration so that it uses the desired options.
The configuration section is identified in the script by:
rem ***********************************
rem * Configure Backup *
rem ***********************************
The first part of the configuration controls the backup script (see Table 2-I.) The second part (Table 2-II) defines what to back up.
Advanced Configuration identifies parameters that are more rarely modified and is identified by:
rem ************************************
rem * Configure Advanced Backup *
rem ************************************
The third part (Table 2-III) defines up
to six additional folders for backup. (See pp 8 for how to add backup folders.)
Identifier | Default | Action |
---|---|---|
Backup drive letter |
DRV=G |
Set to backup drive -- or set with %1 |
Options for standard folders. Yes means to include the folder in the backup. Automatic means that user interaction is not required.
Identifier | Default | Backup Location |
---|---|---|
Doc |
No |
Original documents folder |
By default there are six additional folders available for backup. To use one, set Auxn to the path in quotes and AuxnName to the folder identifier. Special characters, including spaces, are not supported for identifiers. Paths that do not exist are ignored. There are also a few other controls that are rarely modified. These are shown in Table 2-III.
Identifier | Default | Purpose |
---|---|---|
bUser |
|
User specified paths |
Note:
The drive and bPath are combined to form the backup destination = DRV:\bPath. The default destination is G:\0Bac. It is only necessary to set DRV to the correct drive letter, changing bPath is optional.
A separate drive is recommended. Either a dedicated internal drive or an external drive. A example is a 2 TB USB Drive.
If monthly backups are desired using 7-Zip, then install 7-Zip from http://www.7-zip.org/download.html, or from the Microsoft store. (Most systems these days are 64 bit, so choose the 64 bit version, unless you know you are are using a 32 bit system.) If 7-Zip is failing to start, it is most likely because 7-Zip is not specified in the Windows path. Try executing Fix7Zip, see https://sourceforge.net/p/windows-power-utilities/wiki/Fix7Zip/.
Windows started out with a folder called "My Documents" (Space intended) that contained all the user's documents. Unfortunately, most programs stored programmatic data there also. So it was a good idea, but the implementation was flawed. Not only was there stuff that didn't belong with user documents, but space is a printable character and a delimiter. So older programs that used space as a delimiter would fail. I didn't like all the programmatic stuff in the middle of my documents, so I moved all my data to folder "U". This made for shorter file names, removed all the programmatic junk (that was still stored in My Documents), and was easier to spell.
These problems were fixed over time. Gradually programmatic data was moved to other folders, and the name was changed to Documents.
A cloud drive is a folder that is mirrored on a server somewhere in the Internet. Microsoft saw the utility of this approach so they offered a cloud drive called OneDrive. OneDrive, when activated, mirrors your desktop and Documents folder in the cloud. On your PC you gained another Documents folder called OneDrive\Documents. That is the situation today. There is a Documents folder and a OneDrive\Documents folder. OneDrive\Documents is suppose to replace the old Documents folder (and mostly does so.) However there are times when it is necessary to backup both, so in the backup configuration, Doc represents the Documents folder and OneDoc represents the OneDrive\Documents folder, see Table 2-II.
Technology moves on. Modern PC's have two (or more) drives. Usually a solid state (SST) drive as the "C" drive for programs and a larger hard drive (HDD) for user data (usually labeled as "D"). Oops. This does not match the OneDrive model (everything on drive "C".) So the backup script refers to the Documents folder as Doc, and refers to the OneDrive\Documents folder as OneDoc.
Six extra folders, labeled Aux through Aux6 may be defined for backup. These are shown in Table 2-III. It is desirable to have nice names to store data so each "Aux" folder has a corresponding "AuxName", name, to go along with it. For the modern paradigm, InstallBackup automatically checks for "U" on a D-Drive. It also checks for "U" on the C-Drive and for ".nic" on the C-Drive. If Aux points to a non existent folder, it is ignored.
".nic" is where the Nuances In Computing (NIC) utilities store their configuration. This approach is compatible with Linux and makes some of the utilities directly portable to Linux.
Windows is still oriented to having a single Documents folder located on the C-Drive. So when you are dealing with a multiple drive system where user documents are mostly located on a different drive, other than the C-Drive you can enhance the usability of the PC by
adding a shortcut in the Documents (or OneDrive\Documents) folder pointing to D:\U\Documents(4). This assists in storing documents. Also a shortcut to D:\U in the home folder makes it easier to change the file manager focus to "D:\U".
Microsoft introduced a robust file/folder copy program called RoboCopy. RoboCopy copies files and folders without data compression. There is a third party program called 7-Zip that can create a compressed archive of folders and files. Compressed archives occupy significantly less storage than uncompressed files and folders. So it is recommended that 7-Zip be used for monthly backups rather than RoboCopy. Setting Zip to Yes (Zip=Yes) in the backup configuration turns on using 7-zip for monthly backups. (Be sure and install 7-Zip first.) If you turn on Zip, it is recommended that you also turn off RoboCopy (RC=No). Regardless of the settings for RC and Zip. Either 7-Zip or RoboCopy is used for monthly backups; however RoboCopy is Always used for daily backups.
The way mail works is a user sends a text message (maybe with attachments) to a server in the cloud. A different user then views the message (assuming the message is addressed to him.) Thus mail uses a client-server architecture. User number 1, uses his/her client to store a message on the server; user number 2 uses his/her client to view the message. See Figure 5.
Client 2 has a choice, he can leave the message on the server and only view it. This is called using a cloud based email client via a browser. Client 2 can choose to download the message to her PC and view it on the PC. This is called using a desktop email client. Desktop clients are typically used when the server is transitory and you wish to retain a copy. If you access your email via your browser, you are using a cloud based client.
If you are using a desktop based client, then you can backup your mail as part of the backup system. You do this by setting Mail=Yes in the configuration section. If for some reason the backup script can't locate where the email is stored on your PC, do a web search to locate where your email client stores the email and set one of the "aux" files to it. For example
Aux3="C:\Users\'you'\AppData\Local\Microsoft\mail"; Aux3Name=Mail.
The backup script (Startup.bat) maintains a a set of logs. These logs are as follows:
A summary log (C:\Users\'you'\Startup\Bkup.log). Bkup.log contains a high level summary of the actions taken by the backup script. To see what actions were taken during backup, view Bkup.log. If the backup is in progress, displaying the summary log will display the progress. (Normally double-click on Bkup.log. Just don't save when you exit.)
An error summary log (C:\Users\'you'\Startup\Err.log.) Windows commands support a separate error output named syserr. This data stream is captured in Err.log.
Detailed logs for each archive are captured in: (C:\Users\'you'\Startup\Errs.) The Logs folder contains the detailed logs of each action. These logs are never deleted, but may be overwritten. So if you switched from RoboCopy to 7-Zip, the old RoboCopy monthly logs would remain. So check the date to determine how relevant a log is.
Windows has two folders that are used to automate processes on a Windows PC.
The first is:
%Userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup(5).
It may be reached by entering:
<Windows-Key><R>shell:startup<Enter>
Commands located in this folder are executed when the owner of the account logs in.
The Second is
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup.
It may be reached by entering:
<Windows-Key><R>shell:common startup<Enter>(6)
Commands located in this folder are executed when any user logs in.
InstallBackup.bat installs command file Begin.bat in the first folder ("shell:startup") and also installs command file Startup.bat in %Userprofile%\Startup. Begin.bat starts %Userprofile%\Startup\Startup.bat when the user logs in. The process is illustrated in Figure 7-2.
Notes:
RoboCopy is used for daily backups. So after the full set of daily backups have been generated, RoboCopy compares file dates and only copies a file if the file is new or newer to the one saved previously. This speeds up the daily backup process considerably.
By default, backups are stored in 'drv':\0Bac, where "drv" is the drive letter defined in the configuration section, see Table 2-I.
Daily backups are stored in a folder using the day of the week. So if a backup was done on Tuesday, for the OneDrive\Documents folder, it will be stored under 'Drv':\0Bac\OneDoc. Inside of this folder is one folder for each day of the week, say Tue, for example. Tue holds the backup for Tuesday, etc. Along with the folders is a corresponding text file, Tue.txt, in this case. The date of Tue.txt is the date on which the backup was performed. So when searching for the latest backup, sort the txt files by date and the one on top shows which backup is the most current.
%Userprofile%\OneDrive\Documents and, if it exists, folder %Userprofile%\U are automatically backed up.
Near the beginning of Startup.bat is a check for Initialize.bat.If %Userprofile%\Startup\Initialize.bat exists it is invoked using:
cmd/c Initialize.bat. Place desired initialization startup commands there.
Near the end of Startup.bat is a check for Startup2.bat. If %Userprofile%\Startup\Startup2.bat exists it is invoked using:
cmd/c Startup2.bat. Place desired additional commands there.
Having both Zip=No and RC=No disables monthly archives. Setting both to Yes givestwo archives, one for RoboCopy and one for 7-Zip.
"Mail=Yes" specifies to backup local mail folders daily. A check is made for both the Thunderbird and Microsoft mail systems.
Install Backup uses special characters. So User names (login name) cannot contain special characters or the script will not work correctly. This includes spaces (" "), ampersand ("&"), percent ("%"), and Caret ("^"). For example a user name of A&B will cause the script to fail and not operate properly. Use A_B or A_n_B instead.
The reason why the local backup starts five minutes after the user logs in is to avoid burdening the PC with multiple backups in case a cloud backup system is also performing a backup.
Remember when coding Windows scripts that in Windows 10+, an exit command stops all processes in the chain, so avoid the use of exit, use exit/B instead (or simply jump to the end of the script.)
Also it is wise to invoke the command processor (cmd.exe) with the single instance flag (/C) so that if the command fails (or ends with exit), the rest of Startup.bat keeps executing. For example, cmd/c Another-proc.bat, invokes Another-proc.bat with the single instance flag.
The script may be further parameterized so that it can be invoked with multiple configurations by creating another folder besides %Userprofile%\Startup and copying Startup.bat into it and then modifying it to address the desired folders. Be sure to change bPath or Drv to distinguish between backups. Edit Begin.bat(7) to invoke the new script and you can backup multiple devices to different archive folders or devices.
This section is identified by:
rem ************************************
rem * Define folders to be backed up *
rem * User can add additional keys *
rem ************************************
In this section is a line that reads as follows:
set bUser=. This line identifies user folders. Each folder is defined by two symbols: 'Key' and 'Key'Name. The first symbol in the pair contains the location of the folder (or file) to be backed up in quotation marks; the second symbol contains the name of the folder without quotation marks. The folder name is used to identify the folder in the backup. The pair must be named as 'key' and 'key'Name.
An example is
set aux7="D:\ExtraFiles"
set aux7Name=Extra
set MyBac="C:\Users\'you'\MyBacup"
set MyBacName=MyBackup
set bUser=Aux7 MyBac
This will cause folder D:\ExtraFiles and C:\Users\'you'\MyBackup to be included in the backup and stored under the name of Extra and MyBackup.
Near the top of the script is a line Debug=No. Changing it to Debug=Yes Changes the behavior of the script to add additional information to the backup log (Bkup.log) and to block all backup activity from taking place. The result is the backup log contains a list of the actions will take place when Debug is set back to No.
It is a good idea to set Debug to Yes on the first invocation. Then examine Bkup.log and verify the configuration is correct. Then set Debug to No and backups will be enabled.
Literals in the script processor, Cmd.exe, are case sensitive. So Debug=NO is different from Debug=No. Be sure and maintain the correct case for boolean flags "Yes" and "No".
These programs are free software: you can redistribute them and/or modify
them under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
These programs are distributed in the hope that they will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU Lesser General Public License may be downloaded from
http://www.gnu.org/licenses.
(1)
Under W11 right-click, choose more options, and then choose edit
(2)
Pressing the control key and scrolling with the mouse wheel will increase or decrease the font size to make the script easier to read.
(3)
See Figure 5-1
(4)
Assuming that user documents are located on the D-Drive.
(5)
%Userprofile% is a symbol that points to the current user's home folder and is defined during login.
(6)
Sometimes quotation marks are required as in "shell:common startup"
(7)
Enter 'Shell:Startup' from the run dialog to access the system startup folder.
|