Unattended automatic hard drive backup using Winzip

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Unattended automatic hard drive backup using Winzip

Post by Marcus Tettmar » Fri Aug 18, 2000 11:00 pm

Contributed By: Curt Hauge [email protected]
Submitted On: 19/08/00

Remark>This is an unattended automatic backup macro designed by Curt Hauge.
Remark>Please distribute and make changes freely, with all remarks intact. I would be
Remark>interested to hear about changes and improvements you make at [email protected].

Remark>This macro copies files from one hard drive to another
Remark>for backup purposes. It is not recommended to use this macro
Remark>to back up to another directory on the same drive (in case of a hard drive
Remark>failure). It can be "considered safe" to use for backups if you have 2
Remark>or more physically "separate" hard drives installed on your computer.
Remark>(NOT to be confused with 2 or more partitions on your hard drive).
Remark>It could very likely be configured to be used with a tape backup as well.

Remark>It retains as many backups as specified and automatically deletes old backups
Remark>(by user specified # of days) and will automatically archive a backup (at end
Remark>of month) to another drive. It notifies the user if the backup failed, or was
Remark>successful, and can notify a backup administrator if the backup failed as well.

Remark>Next procedure deletes all older backups (except the most current
Remark>ones, which you select a few lines down) in the last 30 days
Remark>(in case you don't run this macro for up to 30 days it won't
Remark>"fill up" with old backups in the E:Backup directory).

Year>Date
Month>Month
Day>Day
ConCat>Date,%Month%
ConCat>Date,%Day%

Remark>Change the next line if you wish to retain current backups for more or less days.
Remark>For instance, change to Let>Date=Date-13 if you want to keep backups for 14 days.
Let>Date=Date-6
Let>Cntr=0
Label>Next_1
Let>Cntr=Cntr+1
Let>Date=Date-1

Remark>Next lines check to see if value for day
Remark>is 00 or >31 - if so, it changes day to 31
MidStr>Date,7,2,day_value
If>day_value>31,Change_day
If>day_value=00,Skip1
Goto>Jump
Label>Skip1
Let>Date=Date-1
Label>Change_day
MidStr>Date,1,6,NewDate
Let>Date=NewDate
ConCat>Date,31

Remark>Next lines check to see if value for month is
Remark>00 - if so,it changes year to year-1 and month to 12
MidStr>Date,5,2,month_value
If>month_value=00,Change_month
Goto>Jump
Label>Change_month
Let>Date=Date-8800

Label>Jump
DeleteFile>E:\Backup\\%Date%

Remark>Change the next line if you wish to delete backups older than 30 days.
Remark>For instance, change to If>Cntr,60,Next_1 if you want to delete files
Remark>older than 60 days. This will NOT delete files which you have designated
Remark>above to "retain", only those files which are older than the "retained days".
If>CntrDone deleting older files.

Remark>Create a temporary backup directory (after first deleting the old one)
Remark>and a final destination directory named after todays date.
Year>Date
Month>Month
Day>Day
ConCat>Date,%Month%
ConCat>Date,%Day%

DeleteFile>C:\Backup\Temp
CreateDir>C:\Backup\Temp
CreateDir>E:\Backup\\%Date%

Remark>The following are used to count the number of files backed up.
Let>Total_Source=0
Let>Cnt_Source=0

Remark>Copy Windows Directory files to todays folder.
CreateDir>C:\Backup\Temp\Windows
Let>Target_Dir=C:\Backup\Temp\Windows\
Let>Source_Dir=C:\Windows\*.ini

Remark>If, as in previous line, you select files only (*.ini) and not
Remark>all files and folders (*.*), you must select 0 on the following
Remark>line so as not to count files in all sub-directories.

CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source
Let>Source_Dir=C:\Windows\*.dll
CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source
Let>Source_Dir=C:\Windows\*.dat
CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source
Let>Source_Dir=C:\Windows\*.sys
CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source
Let>Source_Dir=C:\Windows\*.bat
CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source
Let>Source_Dir=C:\Windows\*.pwl
CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source
Let>Source_Dir=C:\Windows\*.pab
CountFiles>Source_Dir,Cnt_Source,0
CopyFile>Source_Dir,Target_Dir

Let>Total_Source=Total_Source+Cnt_Source

Remark>Copy Windows\Profiles\Curt Directory files to todays folder.
Remark>Note that Cnt_Source,1 (not Cnt_Source,0) when using *.*
CreateDir>C:\Backup\Temp\Windows\Profiles
CreateDir>C:\Backup\Temp\Windows\ProfilesCurt
Let>Source_Dir=C:\Windows\Profiles\Curt\*.*
CountFiles>Source_Dir,Cnt_Source,1
Let>Target_Dir=C:\Backup\Temp\Windows\Profiles\Curt
CopyFile>Source_Dir,Target_Dir
Let>Total_Source=Total_Source+Cnt_Source


Remark>Copy Program FilesPeachwCurhauco Directory files to todays folder.
CreateDir>C:\Backup\Temp\Program Files
CreateDir>C:\Backup\Temp\Program Files\Peachw
CreateDir>C:\Backup\Temp\Program Files\Peachw\Curhauco
Let>Source_Dir=C:\Program Files\Peachw\Curhauco\*.dat
CountFiles>Source_Dir,Cnt_Source,0
Let>Target_Dir=C:\Backup\Temp\Program Files\Peachw\Curhauco\
CopyFile>Source_Dir,Target_Dir
Let>Total_Source=Total_Source+Cnt_Source

Remark>Copy Program Files\Peachw Directory files to todays folder.
Let>Source_Dir=C:\Program Files\Peachw\*.frm
CountFiles>Source_Dir,Cnt_Source,0
Let>Target_Dir=C:\Backup\Temp\Program Files\Peachw\
CopyFile>Source_Dir,Target_Dir
Let>Total_Source=Total_Source+Cnt_Source

Remark>Next line (optional) renames the log file to todays date if you have
Remark>logging enabled, otherwise you may "Remark>" it.
CopyFile>C:\Backup\macbac.log,C:\Backup\\%Date%.log

Year>New_Year
Let>Target_Dir=C:\Backup\Temp\*.*
CountFiles>Target_Dir,Total_Target,1
If>Total_Source=Total_Target,Pass
MessageModal>THE BACKUP ON %Month%/%Day%/%New_Year% FAILED! Total number of file(s) in %Target_Dir% is %Total_Target% which does not equal the %Total_Source% file(s) found in the source directory.

Remark>The following line (optional) copies a text file of your choice to the desktop of your
Remark>choice. This is used in case multiple persons use the same computer, but you
Remark>need to get the 'FAILED' message to the person in charge of the backup procedure.
Remark>In this example, an empty text file called BACKUP FAILED!.txt is copied to the
Remark>desktop of Curt.
CopyFile>c:\Backup\BACKUP FAILED!.txt,c:\Windows\Profiles\Curt\Desktop\BACKUP FAILED!.txt

Goto>End
Label>Pass
Message>Backup completed successfully! %Total_Target% file(s) backed up.

Remark>Winzip must be in C:Pkzip25 or change the next line
Run Program>C:\Pkzip25\pkzip25 -add -rec -path=root -include=C:\BackupTemp\*.* C:Backup\Temp\Temp.zip
WaitWindowOpen>pkzip25
WaitWindowClosed>pkzip25
MoveFile>C:\Backup\Temp\Temp.zip,E:\Backup\\%Date%\\%Date%.zip
Goto>End

Remark>Next line copies the current backup back to the orignal drive
Remark>just prior to new month (when it deletes all of the previous
Remark>months data on the first of the new month). This is also
Remark>beneficial because it keeps an archived backup longer.
Year>Date
Month>Month
Day>Day
ConCat>Date,%Month%
ConCat>Date,%Day%
MidStr>%Date%,7,2,MyDay
If>MyDay=28,EndOfMonth
Goto>End
Label>EndOfMonth
CreateDir>C:\Backup\\%Date%
CopyFile>E:\Backup\\%Date%\*.*,C:\Backup\\%Date%\
Label>End

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts