It creates a file called c:backup.txt that shows all files backed up, where they were backed up and the date the backup was done. I use a scheduled job to print the file every morning so the user can see that in fact their backup is working...
The script uses the "xcopy" command and will back up to a local drive or a network drive.. the backup does files with archive flag set and then clears the archive flag. Change the xcopy option for the archive flag if you want all files backed up the first time around...(remove /m) The destination folder and some other info is stored in an .ini file in the root directory.. You must create the folders wherever you will be backing up. The script still contains some options I do not use anymore.. they are commented out.... It also has an exclude files capability.
THE SCRIPT:
;
; in the root folder (C:) create an ini file named user.ini
; that looks like this (without the semicolon)
;[SETTINGS]
;username=speedi
;dirnumber=1 9/8/2011 changed limit to 3 (three) due to disk being filled search for "if $dirno =" to change
; delete old TEMP filesI used /b and /i to check modified date only THE /a5 specifies files older than 5 days
; download decay here: http://www.linkdata.se/software/archives/
RunWait(@ComSpec & " /c " & 'c:decay.exe /a5 /b /d /i /n "C:Documents and SettingsJim MihalskiLocal SettingsTemp*.*"')
; Copy any *.bat files from root c: for backup
RunWait(@ComSpec & " /c " & 'C:WINDOWSSYSTEM32XCOPY.EXE " C:*.bat "C:Documents and SettingsJim MihalskiMy Documentsdata" /c/m/y')
; Copy any *.txt files from root c: for backup
RunWait(@ComSpec & " /c " & 'C:WINDOWSSYSTEM32XCOPY.EXE " C:*.txt "C:Documents and SettingsJim MihalskiMy Documentsdata" /c/m/y')
; Copy the MS word normal.dot file (macros, etc) to the data folder for backup
RunWait(@ComSpec & " /c " & '"C:WINDOWSSYSTEM32XCOPY.EXE "C:Documents and SettingsJim MihalskiApplication DataMicrosoftTemplatesNormal*.dot*" "C:Documents and SettingsJim MihalskiMy Documentsdata" /c/y"')
; following takes a screen snapshot and saves it as c:capture??.jpg
; so I can see what might have caused the daily backup
; not to run....
; delete any prior capture jpg files
FileDelete("c:capture*.jpg")
; If printscreen was started before, close it
If ProcessExists("printscreen.exe") Then
RunWait("C:Program FilesPrintScreenPrintScreen.exe /exit")
EndIf
; Do special printscreen with parameters to capture full screen and save as capture??.jpg
RunWait("C:Program FilesPrintScreenPrintScreen.exe /cptarea='2' /dir='c:' /image='1' /file='capture' /justnow")
; OK Now run regular printscreen
Run("C:Program FilesPrintScreenPrintScreen.exe /cptarea='3'")
Sleep(5000)
;#comments-end
; now check for any reminder or overdue Outlool windows
; if any exist close them before backup
Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
$loop = 0
While $loop < 2
If WinExists("Overdue -") Then
If Not WinActive("Overdue -") Then WinActivate("Overdue -")
Send("{ALTDOWN}c{ALTUP}1{ALTDOWN}s{ALTUP}")
Sleep(500)
Else
$loop = 1
EndIf
If WinExists("Reminder -") Then
If Not WinActive("Reminder -") Then WinActivate("Reminder -")
Send("{ALTDOWN}c{ALTUP}1{ALTDOWN}s{ALTUP}")
Sleep(500)
Else
$loop = 2
EndIf
WEnd
; next routine will compact Outlook pst file if Outlook is open then cloaes Outlook
; works for Outlook 2003
Opt("WinTitleMatchMode", 2)
If WinExists("Microsoft Outlook") Then
WinActivate("Microsoft Outlook", "")
WinWaitActive("Microsoft Outlook", "")
Send("{ALTDOWN}{f4}")
winWaitClose("Microsoft Outlook", "")
Else
EndIf
; will list all open windows to file c:openwins.txt
; used to determine why outlook.pst isn't being copied
FileDelete("c:openwins.txt")
$file = FileOpen("c:openwins.txt", 1)
; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
$var = WinList()
For $i = 1 To $var[0][0]
; Only display visble windows that have a title
If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
FileWrite($file, "Title=" & $var[$i][0] & @CRLF)
; MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
EndIf
Next
Func IsVisible($handle)
If BitAND(WinGetState($handle), 2) Then
Return 1
Else
Return 0
EndIf
EndFunc ;==>IsVisible
$user = IniRead("c:user.ini", "settings", "username", "")
$dirno = IniRead("c:user.ini", "settings", "dirnumber", "")
$thedir = "I:backup" & $user & "" & $user & "-" & $dirno
; Once in four backups, do not exclude droid videos or my downloads - that will be backup dir #1
If $dirno = 1 Then
FileCopy("C:excludewovideos.txt", "C:exclude.txt", 1)
Else
FileCopy("C:excludewithvideos.txt", "C:exclude.txt", 1)
EndIf
RunWait(@ComSpec & " /c " & 'C:WINDOWSSYSTEM32XCOPY.EXE "' & @MyDocumentsDir & '" "' & $thedir & '" /c/s/m/y/exclude:exclude.txt >c:backup.txt')
; /A Copies files with the archive attribute set, doesn't change the attribute.
; /M Copies files with the archive attribute set, turns off the archive attribute.
; /S Copies directories and subdirectories except empty ones.
; /C Continues copying even if errors occur.
; /Y Overwrites existing files without prompting.
; Use consolewrite to see how the command will look.. can even copy and paste the consolewrite output to a DOS window to see if it works.
;ConsoleWrite('C:WINDOWSSYSTEM32XCOPY.EXE "' & @MyDocumentsDir & '" "' & $thedir & '" /c/s/a/exclude:exclude.txt >c:backup.txt' & @CRLF)
#comments-start
WinWaitActive("C:WINDOWSSYSTEM32XXCOPY.EXE") ; this code is a work around for the netwrok restriction
Sleep(2000) ; two seconds
If WinExists("C:WINDOWSSYSTEM32XXCOPY.EXE", "") Then
WinActivate("C:WINDOWSSYSTEM32XXCOPY.EXE", "")
Send("{Enter}")
EndIf
Sleep(2000) ; two seconds
If WinExists("C:WINDOWSSYSTEM32XXCOPY.EXE", "") Then
WinActivate("C:WINDOWSSYSTEM32XXCOPY.EXE", "")
Send("{Enter}")
EndIf
#comments-end
;RunWait(@ComSpec & " /c " & "c:tm start /L >>c:backup.txt")
; MsgBox(0,"test","dir " & $thedir & " /S >>c:backup.txt")
;RunWait(@ComSpec & " /c " & "dir " & $thedir & " /S >>c:backup.txt")
;RunWait(@ComSpec & " /c " & "c:tm stop /L >>c:backup.txt")
$dirno = $dirno + 1
If $dirno = 4 Then $dirno = 1
IniWrite("c:user.ini", "settings", "dirnumber", $dirno)
; now write a record of the backup end time to the backup.txt file
$file = FileOpen("c:backup.txt", 1) ; (1) is write mode to append
; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
FileWrite($file, @CRLF & "Backup destination " & $thedir & @CRLF & @CRLF)
FileWrite($file, "Backup Finished " & @MON & "/" & @MDAY & "/" & @YEAR & " -- " & @HOUR & ":" & @MIN & @CRLF)
Exit
Edited by speedi, 23 June 2012 - 07:53 PM.





