Search the Community
Showing results for tags 'backuppc'.
-
Hi Gentlemen, I m learning autoit and already have interest in it therefore wanted to create a BackupPC tool which can do following stuff 1) Automatically copy predefined User folders like desktop, My documents, favourites etc 2) Give user option to select one more path to include in backup 3) Option to backup .ost file 4) Option to zip backup 5) Last and the selling thing feature which is to continue copying where it left (due to any issue if interrupted)....that is the main feature where im getting stuck as code is giving some error which im not able to identify. There are three options when copying was interrupted , yes to continue where we left, NO to start from beginning and Cancel to select new backup source. NO option does work perfectly fine but there are issues when i click YES on prompt. Attaching full code here Error which im receiving is : Array variable has incorrect number of subscripts or subscript dimension range exceeded.: MsgBox($MB_SYSTEMMODAL, "Title222", $aFileList[$Fcount]) MsgBox($MB_SYSTEMMODAL, "Title222", ^ ERROR Can anyone of you please help here #;NoTrayIcon #Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=Backup.exe #AutoIt3Wrapper_Compression=4 #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiEdit.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> ;#include <IniToArray.au3> local $sInfo local $Destination Local $Includebackup Local $Flashballoon = True $timer = TimerInit() Local $Currfile Local $Arrfile Global $INIFilePath = @ScriptDir & "\CurrentDir.ini" $Form1_1 = GUICreate("Backup", 627, 384, 267, 121) $Label1 = GUICtrlCreateLabel("Backup Destination:", 4, 12, 175, 19, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Input1 = GUICtrlCreateInput("", 184, 11, 353, 23) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Button1 = GUICtrlCreateButton("Browse", 540, 10, 75, 25) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Edit1 = GUICtrlCreateEdit("", 4, 160, 613, 185) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetBkColor(-1, 0x000000) $BACKUP = GUICtrlCreateButton("Backup", 454, 352, 75, 25) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Exit = GUICtrlCreateButton("Exit", 536, 352, 75, 25) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Checkbox1 = GUICtrlCreateCheckbox("Compress Backup", 16, 356, 157, 17) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") GUICtrlSetTip(-1, "Use to compress data") $Input2 = GUICtrlCreateInput("", 184, 48, 353, 21) $Button2 = GUICtrlCreateButton("Browse", 540, 48, 75, 25) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Label2 = GUICtrlCreateLabel("Include More :", 14, 51, 130, 19) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Label3 = GUICtrlCreateLabel("Select to include Outlook mailbox and lync chat :", 16, 91, 445, 19) GUICtrlSetFont(-1, 11, 400, 0, "Lucida Console") $Checkbox2 = GUICtrlCreateCheckbox("Outlook Mailbox and chat", 16, 128, 185, 17) GUICtrlSetFont(-1, 9, 400, 0, "Lucida Console") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### if _CheckPendingCopy() = True Then ;GuiCtrlSetData($Edit1, " ") ;GuiCtrlSetData($Edit1, "Previous copy seems pending or was interupted " & @CRLF & "Do you want to Continue with previous copy or start copy again from begining") Local $CopyData = MsgBox($MB_YESNOCANCEL, "Alert", "Previous copy seems pending or was interupted " & @CRLF & "Press YES to continue with previous copy or NO to start from Beginining") if $CopyData = 6 then _Desktop(true) ElseIf $CopyData= 7 then _Desktop(False) Else _ProcessForm() EndIf Else _ProcessForm() EndIf func _ProcessForm() MsgBox($MB_SYSTEMMODAL, "Title", "else") If $Flashballoon = False Then TrayTip("Backup Completed", "Your Backup is completed",10) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exitcode() Case $Exit _Exitcode() Case $Button1 _BackupDestination() Case $Button2 _IncludeBackup() Case $BACKUP if _Trim($Destination) = "" Then GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Destination path is not selected...Please select valid Destination path" & @CRLF, 1) $Flag = False Else ;_MyDocuments() ;_SharedDocuments() ;_Favorites() _Desktop(False) ;_MsOutlook() ;_BackupSelection() If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then; Must Always Be Last _Compress() EndIf If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then; Must Always Be Last _MsOutlook() EndIf _EnableControls() If $Flashballoon = False Then TrayTip("Backup Completed", "Your Backup is completed",10) EndIf EndIf EndSwitch WEnd EndFunc Func _Exitcode() GUIDelete() Exit EndFunc Func _Trim ($LocalString) Return StringStripWS($LocalString, $STR_STRIPLEADING + $STR_STRIPTRAILING) EndFunc func _DisableControls() GUICtrlSetState($BACKUP,$GUI_DISABLE) EndFunc func _EnableControls() GUICtrlSetState($BACKUP,$GUI_ENABLE) EndFunc Func _BackupDestination() $Destination = FileSelectFolder("Select backup destination", "" , 7) GUICtrlSetData($Input1 , $Destination) if DriveGetType($Destination) = "Removable" Then GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "The Drive you selected is External one." & @CRLF & " This is against AON policy to copy data to external drives," & @CRLF & " tool will not be held responsible for not adhering AON policies" & @CRLF, 1) ElseIf DriveGetType($Destination) = "Network" Then GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "The Drive you selected is on Network." & @CRLF & "Please make sure you have plenty of space before proceeding with Backup") Else GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "The Drive you selected is Local." & @CRLF & "Please make sure you have plenty of space before proceeding with Backup") EndIf EndFunc Func _IncludeBackup() $IncludeBackup = FileSelectFolder("Select folders to backup", "" , 7) GUICtrlSetData($Input2 , $IncludeBackup) EndFunc Func _BackupSelection() _FileWriteLog(".\Backup.log", $IncludeBackup & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, @CRLF, 1) GuiCtrlSetData($Edit1, "Backing Up other selected folders" & @CRLF, 1) DirCreate($Destination & "\Manual Selected Folders") RunWait(@ComSpec & ' /k robocopy.exe "' & $IncludeBackup & '" "' & $Destination & "\Manual Selected Folders\" & GetSourceFiles($IncludeBackup) & '" /S /E /R:0 /W:0', "", @SW_HIDE) MsgBox(0,"","Done in " & TimerDiff($timer)/1000 & " seconds!") _FileWriteLog(".\Backup.log", $IncludeBackup & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> Manual selected backup Complete" & @CRLF, 1) EndFunc func GetSourceFiles($SourceDir) local $strPos =StringInStr (StringReverse($SourceDir),"\") Return StringMid($SourceDir,StringLen($SourceDir) - $strPos + 2,$strPos +1) EndFunc Func _MyDocuments() _FileWriteLog(".\Backup.log", @MyDocumentsDir & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) local $MyDocuments = @MyDocumentsDir local $FolderArray1 = _FileListToArray($MyDocuments & "\", "*", 2) $1 = _ArraySearch($FolderArray1, "RECYCLER") _ArrayDelete($FolderArray1, $1) $Num = $FolderArray1[0] $FolderArray1[0] = $Num - 1 $2 = _ArraySearch($FolderArray1, "System Volume Information") _ArrayDelete($FolderArray1, $2) $Num = $FolderArray1[0] $FolderArray1[0] = $Num - 1 GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Backing Up Current Users My Documents" & @CRLF, 1) DirCreate($Destination & "\My Documents") ;Call (_Copy("MyDocument")) FileCopy($MyDocuments & "\*.*", $Destination & "\My Documents", 8) For $1 = 1 To $FolderArray1[0] DirCopy($MyDocuments & "\" & $FolderArray1[$1], $Destination & "\My Documents\" & $FolderArray1[$1], 1) Next _FileWriteLog(".\Backup.log", @MyDocumentsDir & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> My Documents Backup Complete" & @CRLF, 1) EndFunc ;~ Func _SharedDocuments() ;~ local $SharedDocuments = @DocumentsCommonDir ;~ GuiCtrlSetData($Edit1, @CRLF, 1) ;~ GuiCtrlSetData($Edit1, "Backing Up Shared Documents" & @CRLF, 1) ;~ DirCreate($Destination & "\Shared Documents") ;~ DirCopy($SharedDocuments, $Destination & "\Shared Documents", 1) ;~ GuiCtrlSetData($Edit1, "---> Complete" & @CRLF, 1) ;~ EndFunc Func _Favorites() _FileWriteLog(".\Backup.log", @UserProfileDir & "\Favorites" & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) local $Favorites = @UserProfileDir & "\Favorites" GuiCtrlSetData($Edit1, @CRLF, 1) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Backing Up Current Users IE Favorites" & @CRLF, 1) DirCreate($Destination & "\Favorites") DirCopy($Favorites, $Destination & "\Favorites", 1) _FileWriteLog(".\Backup.log", @UserProfileDir & "\Favorites" & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> Favorites backup Complete" & @CRLF, 1) EndFunc Func _Desktop($CopyPending) _FileWriteLog(".\Backup.log", @DesktopDir & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) Local $aFileList = _FileListToArrayRec(@DesktopDir, "*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT) GuiCtrlSetData($Edit1, @CRLF, 1) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Backing Up Current Users Desktop" & @CRLF, 1) DirCreate($Destination & "\Desktop") ;_ArrayDisplay($aFileList, "Sorted tree") if $CopyPending = False then Call (_UpdateIniFile("Desktop",$aFileList)) if $CopyPending then $aFileList = IniReadSection($INIfilePath,"Desktop") ;DirCopy(@DesktopDir, $Destination & "\Desktop", 1) Call (_Copy("Desktop",$aFileList,$Destination & "\Desktop")) _FileWriteLog(".\Backup.log", @DesktopDir & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> Desktop backup Complete" & @CRLF, 1) EndFunc Func _OstFileExits () ; List all the files and folders in the desktop directory using the default parameters. Local $aFileList = _FileListToArray(@UserProfileDir & "\AppData\Local\Microsoft\Outlook", "*.ost") Local $FileExists = False If @error = 1 Then GuiCtrlSetData($Edit1, "---> Outlook file path is invalid." & @CRLF, 1) ElseIf @error = 4 Then GuiCtrlSetData($Edit1, "---> Cannot Find .ost file in Outlook profile default path...Please manually choose .ost file to backup" & @CRLF, 1) Else If $aFileList [0] > 0 Then $FileExists = True $FileExits = True EndIf ; Display the results returned by _FileListToArray. ;_ArrayDisplay($aFileList, "$aFileList") Return $FileExists EndFunc Func _MsOutlook() local $Outlook = @UserProfileDir & "\AppData\Local\Microsoft\Outlook" If _OstFileExits() Then If ProcessExists("Outlook.exe") Then ; Check if the Notepad process is running. GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Outlook is still running, will be closed within 10 seconds." & @CRLF, 1) Sleep(10000) Run(@ComSpec & " /c taskkill /F /PID " & "Outlook.exe" & " /T", @SystemDir, @SW_HIDE) ProcessClose ("Outlook.exe") EndIf If ProcessExists("ucmapi.exe") Then ; Check if the Notepad process is running. GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "ucmapi is still running, will be closed " & @CRLF, 1) Sleep(1000) Run(@ComSpec & " /c taskkill /F /PID " & "ucmapi.exe" & " /T", @SystemDir, @SW_HIDE) ProcessClose ("ucmapi.exe") EndIf If ProcessExists("Lync.exe") Then ; Check if the Notepad process is running. GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Lync is still running, will be closed within 10 seconds." & @CRLF, 1) Sleep(10000) Run(@ComSpec & " /c taskkill /F /PID " & "Lync.exe" & " /T", @SystemDir, @SW_HIDE) ProcessClose ("Lync.exe") EndIf If ProcessExists("Communicator.exe") Then ; Check if the Notepad process is running. GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Lync is still running, will be closed within 10 seconds." & @CRLF, 1) Sleep(10000) Run(@ComSpec & " /c taskkill /F /PID " & "Communicator.exe" & " /T", @SystemDir, @SW_HIDE) ProcessClose ("Communicator.exe") EndIf _FileWriteLog(".\Backup.log", @UserProfileDir & "\AppData\Local\Microsoft\Outlook" & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, @CRLF, 1) GuiCtrlSetData($Edit1, "Backing Up Current User's Microsoft Outlook Data" & @CRLF, 1) DirCreate($Destination & "\MSOutlook") MsgBox(0,"","Done in " & $Destination & " seconds!") MsgBox(0,"","Done in " & $Destination & "\MSOutlook" & " seconds!") ;RunWait(@ComSpec & ' /k robocopy.exe "' & $IncludeBackup & '" "' & $Destination & "\Manual Selected Folders\" & GetSourceFiles($IncludeBackup) & '" /S /E /R:0 /W:0', "", @SW_HIDE) ;@UserProfileDir & "\AppData\Local\Microsoft\Outlook" RunWait(@ComSpec & ' /k robocopy.exe "' & $Outlook & '" "' & $Destination & "\MSOutlook" & "*.ost" & '" & /MIR', "", @SW_SHOW) ;FileCopy($Outlook & "\*.ost", $Destination & "\Microsoft Outlook", 1) ;DirCopy($Outlook, $Destination & "\Microsoft Outlook", 1) While 1 Sleep(10) if Filegetsize($Outlook & "\*.ost") = Filegetsize($Destination & "\Microsoft Outlook\*.ost") Then ExitLoop Endif Wend _FileWriteLog(".\Backup.log", @UserProfileDir & "\AppData\Local\Microsoft\Outlook" & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> Outlook backup Complete" & @CRLF, 1) $Flashballoon = False EndIf EndFunc Func _Compress() _FileWriteLog(".\Backup.log", "Compression" & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) local $7zip = $Destination & "\7zip" DirCreate($7zip) FileInstall("tools\7za.exe", $7zip & "\7za.exe", 1) FileInstall("tools\7zCon.sfx", $7zip & "\7zCon.sfx", 1) GuiCtrlSetData($Edit1, @CRLF, 1) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Compressing Backup" & @CRLF, 1) RunWait($7zip & "\7za a -r -y -sfx7zCon.sfx "& $Destination & "\Backup.exe " & $Destination & "\*.* ", "", @SW_HIDE) DirRemove($7zip, 1) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> Compress Data backup Complete" & @CRLF, 1) _FileWriteLog(".\Backup.log", "Compression" & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) $Flashballoon = True EndFunc Func _Firefox() _FileWriteLog(".\Backup.log", @AppDataDir & "\Mozilla" & " ..............Started @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) local $Firefox = @AppDataDir & "\Mozilla" If FileExists($Firefox) = 1 Then GuiCtrlSetData($Edit1, @CRLF, 1) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "Backing Up Firefox Profile" & @CRLF, 1) DirCreate($Destination & "\Firefox") If ProcessExists("firefox.exe") Then ProcessClose("firefox.exe") EndIf DirCopy($Firefox, $Destination & "\Firefox", 1) _FileWriteLog(".\Backup.log", @AppDataDir & "\Mozilla" & " ..............Completed @ " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC) GuiCtrlSetData($Edit1, " ") GuiCtrlSetData($Edit1, "---> Firefox backup Complete" & @CRLF, 1) EndIf $Flashballoon = True EndFunc Func _Copy($SectionName, $aFileList, $Destination) ; List all the files and folders in the desktop directory using the default parameters and return the full path. ;IniWrite($sFilePath, "General", "Title", $aFileList) ;_FileWriteFromArray($sFilePath, $aFileList, 1) ;_ArrayDisplay($aFileList, "$aFileList rrdrrrer") Local $tmpDestination=$Destination For $Fcount = 1 to (Ubound ($aFileList) - 1) MsgBox($MB_SYSTEMMODAL, "Title222", $aFileList[$Fcount]) if (StringInStr($aFileList[$Fcount],".") = 0) then ;if file extention is not available then it is new sub directory $tmpDestination=$Destination & "\" & $aFileList[$Fcount] $test = DirGetSize($Destination & "\" & $aFileList[$Fcount]) ;MsgBox($MB_SYSTEMMODAL, "Title", $test) ;check if new sub directory exists or not. if not then create if (DirGetSize($Destination & "\" & $aFileList[$Fcount]) =-1) then DirCreate($Destination & "\" & $aFileList[$Fcount]) EndIf endIf ;if (StringInStr($aFileList[$Fcount],"\") > 0) then $tmpDestination=$Destination & "\" FileCopy ($aFileList[$Fcount], $tmpDestination) ;alert($aFileList[$Fcount) MsgBox($MB_SYSTEMMODAL, "Title", $aFileList[$Fcount]) IniDelete ($INIfilePath, $SectionName, $aFileList[$Fcount]) Next MsgBox($MB_SYSTEMMODAL, "Title333", "fdffd") EndFunc Func _UpdateIniFile($SectionName,$FileList) ;MsgBox($MB_SYSTEMMODAL, "Title", Ubound($FileList)) ;_arrayToIni($FilePath, $SectionName, $FileList) ;_ArrayDisplay($FileList, "Sorted tree") IniDelete ($INIFilePath, $SectionName) For $FileCount = 1 to UBound($FileList)-1 IniWrite($INIFilePath, $SectionName, $FileList[$FileCount],$FileCount) Next FileClose ($INIFilePath) EndFunc Func _CheckPendingCopy() local $IsCopyPending = False ; Check if any key exists in any section of ini File $PendingKeyList = IniReadSectionNames ($INIFilePath) If UBound($PendingKeyList) > 0 Then For $CurrSection in $PendingKeyList ; MsgBox($MB_SYSTEMMODAL, "Title", $CurrSection) if Ubound(IniReadSection($INIFilePath, "Desktop")) > 0 then $IsCopyPending = True ExitLoop EndIf Next EndIf Return $IsCopyPending EndFunc