speedi Posted June 23, 2012 Posted June 23, 2012 (edited) This script is what I developed for a business to backup mydocs files saving up to 3 iterations of any changed file... First it copies any .bat & .txt files from the root folder (for logs and such) to a mydocs folder named "data". It also copies any office dot files to mydocs. It also does a screen capture for debugging in case it doesn't work as expected. It deletes old "temp" files also. It closes outlook before copy begins. It also saves the name of all open windows in a file named c:openwins.txt. 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 backupRunWait(@ComSpec & " /c " & 'C:\Windows\System32\XCOPY.EXE " C:*.bat "C:Documents and SettingsJim MihalskiMy Documentsdata" /c/m/y'); Copy any *.txt files from root c: for backupRunWait(@ComSpec & " /c " & 'C:\Windows\System32\XCOPY.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 backupRunWait(@ComSpec & " /c " & '"C:\Windows\System32\XCOPY.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 filesFileDelete("c:capture*.jpg"); If printscreen was started before, close itIf ProcessExists("printscreen.exe") ThenRunWait("C:Program FilesPrintScreenPrintScreen.exe /exit")EndIf; Do special printscreen with parameters to capture full screen and save as capture??.jpgRunWait("C:Program FilesPrintScreenPrintScreen.exe /cptarea='2' /dir='c:' /image='1' /file='capture' /justnow"); OK Now run regular printscreenRun("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 backupOpt("WinWaitDelay", 100)Opt("WinTitleMatchMode", 4)$loop = 0While $loop < 2If WinExists("Overdue -") ThenIf Not WinActive("Overdue -") Then WinActivate("Overdue -")Send("{ALTDOWN}c{ALTUP}1{ALTDOWN}s{ALTUP}")Sleep(500)Else$loop = 1EndIfIf WinExists("Reminder -") ThenIf Not WinActive("Reminder -") Then WinActivate("Reminder -")Send("{ALTDOWN}c{ALTUP}1{ALTDOWN}s{ALTUP}")Sleep(500)Else$loop = 2EndIfWEnd; next routine will compact Outlook pst file if Outlook is open then cloaes Outlook; works for Outlook 2003Opt("WinTitleMatchMode", 2)If WinExists("Microsoft Outlook") ThenWinActivate("Microsoft Outlook", "")WinWaitActive("Microsoft Outlook", "")Send("{ALTDOWN}{f4}")winWaitClose("Microsoft Outlook", "")ElseEndIf; will list all open windows to file c:openwins.txt; used to determine why outlook.pst isn't being copiedFileDelete("c:openwins.txt")$file = FileOpen("c:openwins.txt", 1); Check if file opened for writing OKIf $file = -1 ThenMsgBox(0, "Error", "Unable to open file.")ExitEndIf$var = WinList()For $i = 1 To $var[0][0]; Only display visble windows that have a titleIf $var[$i][0] <> "" And IsVisible($var[$i][1]) ThenFileWrite($file, "Title=" & $var[$i][0] & @CRLF); MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])EndIfNextFunc IsVisible($handle)If BitAND(WinGetState($handle), 2) ThenReturn 1ElseReturn 0EndIfEndFunc ;==>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 #1If $dirno = 1 ThenFileCopy("C:excludewovideos.txt", "C:exclude.txt", 1)ElseFileCopy("C:excludewithvideos.txt", "C:exclude.txt", 1)EndIfRunWait(@ComSpec & " /c " & 'C:\Windows\System32\XCOPY.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:\Windows\System32\XCOPY.EXE "' & @MyDocumentsDir & '" "' & $thedir & '" /c/s/a/exclude:exclude.txt >c:backup.txt' & @CRLF)#comments-startWinWaitActive("C:\Windows\System32\XXCOPY.EXE") ; this code is a work around for the netwrok restrictionSleep(2000) ; two secondsIf WinExists("C:\Windows\System32\XXCOPY.EXE", "") Then WinActivate("C:\Windows\System32\XXCOPY.EXE", "") Send("{Enter}")EndIfSleep(2000) ; two secondsIf WinExists("C:\Windows\System32\XXCOPY.EXE", "") Then WinActivate("C:\Windows\System32\XXCOPY.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 + 1If $dirno = 4 Then $dirno = 1IniWrite("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 OKIf $file = -1 Then MsgBox(0, "Error", "Unable to open file.") ExitEndIfFileWrite($file, @CRLF & "Backup destination " & $thedir & @CRLF & @CRLF)FileWrite($file, "Backup Finished " & @MON & "/" & @MDAY & "/" & @YEAR & " -- " & @HOUR & ":" & @MIN & @CRLF)Exit Edited June 23, 2012 by speedi
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now