Page 1 of 1 1
Topic Options
#160971 - 2006-04-21 04:01 AM Backup System State for XP Pro
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Here is a script that will use the built-in Shadow Copy service and NTBACKUP to backup
the System State of a Windows XP Pro workstation.
 
XP Home and XP Media Center don't include the NTBACKUP utility and Servers should use a
more feature rich application, though this script will run properly on Server 2003 if you
modify the version check.
 
WARNING!! You should run an up to date Antivirus scan and an up to date
Anti-Spyware utility and also run a CHKDSK /R on your system first to verify that there are
no problems with the system before you start running this script.
 
This script is quite useful when something you recently installed has messed up your system and
you're having troubles fixing whatever caused it. You simply run the NTBACKUP utility and select
the version of the backup that you feel did not have the issue and restore it.
This will restore the entire REGISTRY and main startup files back to the way they were before the
problem happened. Note though that if you installed some other software since the last restore you
restore back to you will still have the files on your system but the REGISTRY will not know that
you have installed the program and you will need to re-install it again.
 
NOTE: You must be running KiXtart v4.52 beta 2 or newer in order to
properly run this script.
 
You can change the number of days you want to save backups and you can change the folder location
if you like. Currently the script uses $Folder='C:\Backup\' and will remove backup files that
are 7 days or older.
 
A sample of the file name would look something like this
2006-04-20_183620-SystemState.bkf
 
YYYY-MM-DD_HHMMSS allows accurate sorting by name or date
 
Setup a batch file and run it with a daily scheduled task to run at noon or whenever and
it will silently take care of the backups for you automatically.


 
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

If @ProductType='Windows XP Professional'
;Shadow copy service and ntbackup only available on XP Pro
;Servers should use a more robust backup application but it will run
;on Server 2003 if you want it to, just modify the @ProductType condition.
Dim $Folder,$Cleaned,$File
$Folder='C:\Backup\'
If GetFileAttr($Folder) & 16
;Folder found do nothing
Else
MD $Folder
If @ERROR
Quit @ERROR
EndIf
EndIf
$Cleaned=CleanDirectory($Folder,'*.bkf',7)
;Change the 7 to the number of days you want to save the backup files
;If you only want to delete 30 days or older then change to 30
;Note though that each backup takes about 500MB of disk space.
;So 30 days of backups would take about 15GB of disk space storage.
BackupSystemState($Folder)
Else
Quit 10
EndIf

Function BackupSystemState($Folder)
Dim $Job
If Not InStr(Right($Folder,1),'\') Exit 3 EndIf
$Job = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),''))+'-SystemState'
SHELL 'ntbackup backup systemstate /j '+ $Job +' /f ' + $Folder + $Job+'.bkf'
Exit @ERROR
EndFunction

Function CleanDirectory($directories, $filter, optional $olderas, optional $countonly)
Dim $rc, $timediff, $filename, $filefilter, $tempdir
Dim $filecount, $dircount
$dircount=0
$filecount=0
$olderas=IIf(Val($olderas)>0,Val($olderas),0)
$countonly=IIf(Val($countonly),1,0)
If Not (VarType($directories) & 8192)
$directories=Split($directories,'')
EndIf
If Not (VarType($filter) & 8192)
$filter=IIf(Trim($filter),$filter,'*.*')
$filter=Split($filter,'')
EndIf
For Each $tempdir In $directories
If $tempdir<>'' And Exist($tempdir)
For Each $filefilter In $filter
If $filefilter<>''
$filefilter=fullfile($tempdir,$filefilter)
$filename=Dir($filefilter,1)
While $filename<>'' And @ERROR = 0
If $filename<>'.' And $filename<>'..'
$filename=fullfile($tempdir,$filename)
If GetFileAttr($filename) & 16
$rc=cleandirectory($filename,$filter,$olderas,$countonly)
If InStr($rc,',')
$rc=Split($rc,',')
$dircount=$dircount+$rc[0]
$filecount=$filecount+$rc[1]
EndIf
$rc=SetFileAttr($filename,128)
If Not $countonly
RD $filename
If Not @ERROR
$dircount=$dircount+1
EndIf
EndIf
Else
$timediff=datemath(@DATE,Left(GetFileTime($filename),10))
If $timediff>=$olderas
If $countonly
$filecount=$filecount+1
Else
$rc=SetFileAttr($filename,128)
Del $filename /c /f /h
If Not @ERROR
$filecount=$filecount+1
EndIf
EndIf
EndIf
EndIf
EndIf
$filename=Dir('',1)
Loop
EndIf
Next
EndIf
Next
$cleandirectory=''+$dircount+','+$filecount
EndFunction

Function FullFile($path1, optional $path2)
Dim $a, $path3
$a=UBound($path1)
if $a>0
$path3=$path1[$a]
ReDim Preserve $path1[$a-1]
$path1=fullfile($path1,$path3)
EndIf
If UBound($path1)=0
$path1=$path1[0]
EndIf
If Right($path1,1)='\'
$path1=Left($path1,Len($path1)-1)
EndIf
If $path2
If Left($path2,1)='\'
$path2=Right($path2,Len($path2)-1)
EndIf
$fullfile=LCase($path1+'\'+$path2)
Else
$fullfile=$path1
EndIf
EndFunction

Function DateMath($ExpD1,$ExpD2)
Select
Case InStr($ExpD1,'/') And InStr($ExpD2,'/')
; two date passed - return daysbetween integer
$DateMath=SerialDate($ExpD1)-SerialDate($ExpD2)
If $DateMath<0
$DateMath=$DateMath*-1
EndIf
Case InStr($ExpD1,'/') and 1-InStr($ExpD2,'/')
; date and a number passed - return date
$ExpD2=0+$ExpD2
$Datemath=SerialDate(SerialDate($ExpD1)+$ExpD2)
Case 1 ; incorrect parameters passed
EndSelect
EndFunction

Function SerialDate($ExpD)
Dim $z,$h,$a,$b,$c,$y,$m,$d
If InStr($ExpD,'/') ; date passed
$y=Val(SubStr($ExpD,1,4))
$m=Val(SubStr($ExpD,6,2))
$d=Val(SubStr($ExpD,9,2))
If $m<3
$m=$m+12
$y=$y-1
EndIf
; return an integer
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else ; integer passed
$z=0+$ExpD+306 ; cast numeric
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
If $m>12
$y=$y+1
$m=$m-12
EndIf
$m=Right('0'+$m,2)
$d=Right('0'+$d,2)
; return a string date
$SerialDate=''+$y+'/'+$m+'/'+$d
EndIf
EndFunction



 

Top
#160972 - 2006-04-21 04:11 AM Re: Backup System State for XP Pro
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
For a similar idea on backup please review this posting
which backs up more data and information but is not as robust at backing up the full registry, though maybe a combination of the 2 would be useful for some users that get hit by Virus/Spyware/Trojans quite often.
 
SNAPSHOT - System information backup
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Board=UBB2&Number=135181
 

If there is interest I could work on combining the two scripts into a single script method.
 


Edited by NTDOC (2006-04-21 08:14 AM)

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.043 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org