DATMAN TECHNICAL BULLETIN #020
From: Kan Yabumoto tech@datman.com
To: All
Subject: A System Registry Backup Strategy
Date: 1997-05-09
====================================================================
One of the most important files in the Windows 95 systems is the
is the system registry files.
C:\WINDOWS\SYSTEM.DAT
C:\WINDOWS\USER.DAT
Windows 95 also maintains one set of earlier version of them as
C:\WINDOWS\SYSTEM.DA0 and C:\WINDOWS\USER.DA0. The purpose of these
files is to substitute the current version if they are corrupted or
inaccessible. Quite often, you find the backup version almost as bad
as the current one. So, it is highly desirable to backup these files
as often as possible. But, we are all too busy (or lazy) to remember
doing so by hand.
This article outlines a very simple, yet quite adequate technique of
an automated scheduled backup for system registry files. The technique
uses a batch enhancer utility called HOWOLD.EXE which we wrote in
order to perform various scheduled system maintenance jobs with batch
files. This simple utility compares the date of a file against the
current system time (or another file) and returns the ERRORLEVEL value
which allows you to form a test and branch statement in a batch file.
The backup strategy will maintain the following sets of files.
Daily backup series up to 8 files (at least one day apart)
Weekly backup series up to 5 weeks
Monthly backup series up to 12 months
Yearly backup series up to 100 years (we are kidding :-)
The batch file is intended to be run at every bootup time from the
StartUp window or inside AUTOEXEC.BAT. The intervals and the number
of files in each series can be customized easily.
Following are excerpts of the batch file (for more complete
description, read the actual batch file).
------------ RBU.BAT (Registry BackUp Batch File) ----------------------
First, the most recent file (day00.zip) is checked against the
current system date. If it was created today, do nothing in order
to avoid multiple copies of daily backup for a system which is
rebooted frequently.
howold /d c:\registry\day00.zip
if not errorlevel 2 goto end
Else, run the REGEDIT utility and the output file is immediately
compressed into a zip and delete the original one. (Note: the
regedit's output file will stay inaccessible to other processes for
a few seconds after it was created. So, in the real batch file,
we made a loop for the pkzip statement to handle the denied access).
regedit /e c:\registry\backup.reg
pkzip c:\registry\today.zip c:\registry\backup.reg
del c:\registry\backup.reg
In the daily section, the oldest file in the series is discarded
and the rest of the files are promoted by the rename command.
:daily
del c:\registry\day07.zip
ren c:\registry\day06.zip day07.zip
ren c:\registry\day05.zip day06.zip
ren c:\registry\day04.zip day05.zip
ren c:\registry\day03.zip day04.zip
ren c:\registry\day02.zip day03.zip
ren c:\registry\day01.zip day02.zip
ren c:\registry\day00.zip day01.zip
ren c:\registry\today.zip day00.zip
Then, the most recent weekly backup file (week0.zip) is tested for
weekly maintenance. If it was created within this week, then skip
this section and jump to the monthly section. Otherwise, the weekly
series files are promoted in the same fashion as the daily series.
:weekly
howold /w c:\registry\week0.zip
if not errorlevel 2 goto monthly
del c:\registry\week5.zip
ren c:\registry\week4.zip week5.zip
ren c:\registry\week3.zip week4.zip
ren c:\registry\week2.zip week3.zip
ren c:\registry\week1.zip week2.zip
ren c:\registry\week0.zip week1.zip
copy c:\registry\day00.zip c:\registry\week0.zip
The monthly section follows exactly the same logic as the weekly series.
Only the filenames and labels are different.
:monthly
howold /m c:\registry\mon00.zip
if not errorlevel 2 goto yearly
del c:\registry\mon12.zip
ren c:\registry\mon11.zip mon12.zip
ren c:\registry\mon10.zip mon11.zip
...
ren c:\registry\mon01.zip mon02.zip
ren c:\registry\mon00.zip mon01.zip
copy c:\registry\day00.zip c:\registry\mon00.zip
As you can see, the key to the batch file is the HOWOLD utility. It
checks the age of a file based on various switches.
howold /d tests file date in days
howold /m tests file date in months
howold /w tests file date in weeks
It can also use seconds, minutes, hours, year, as the criteria of
testing as well as defining the starting day of the week other than
Sunday. The usefulness of our HOWOLD utility is not limited to this
simple registry backup applications. It is up to your imagination.
Please send us an E-Mail if you come up with an imaginative batch file
using this utility. We may publish your application in this web page.
Now, final question you may have is where you can obtain the full copy
of the RBU.BAT file and more importantly, HOWOLD.EXE. They are included
in our DATMAN.ZIP Freeware package.