| Line-No. / Ref. | Code Line |
| 0001 | Public Sub Backup_Ctrl() |
| 0002 | Dim fs As Object |
| 0003 | Dim OK As String |
| 0004 | Dim Start_Time As Date |
| 0005 | Dim rst As Recordset |
| 0006 | Dim rst2 As Recordset |
| 0007 | Dim db As Database |
| 0008 | Dim Run_Duration As Single |
| 0009 | Dim Run_Duration_Text As String |
| 0010 | Dim strQuery As String |
| 0011 | Dim i As Integer |
| 0012 | Dim j As Integer |
| 0013 | Dim strMsg As String |
| 0014 | Dim Backup_Depth As Integer |
| 0015 | Dim strSubDirectory As String |
| 0016 | Dim RecordsPrior As Long |
| 0017 | Dim RecordsPost As Long |
| 0018 | Dim Check_Directory As String |
| 0019 | Dim Backup_Inconsistent_Msg As String |
| 0020 | Dim Backup_Last_Run_Time As Single |
| 0021 | Backup_Errors = 0 |
| 0022 | Backup_Errors_Full = 0 |
| 0023 | Set db = CurrentDb |
| 0024 | Start_Time = Now() |
| 0025 | Files_Processed = 0 |
| 0026 | Backup_Errors_Stop = False |
| 0027 | Backup_Files_Backed_Up = 0 |
| 0028 | Backup_Copy_Time = 0 |
| 0029 | DoCmd.RunSQL ("DELETE Backup_Directory_Structure_Temp.* FROM Backup_Directory_Structure_Temp;") |
| 0030 | DoCmd.RunSQL ("DELETE Backup_Site_Map_Temp.* FROM Backup_Site_Map_Temp;") |
| 0031 | Set rst2 = db.OpenRecordset("SELECT Backup_Control.* FROM Backup_Control;") |
| 0032 | If Not rst2.EOF Then |
| 0033 | rst2.MoveFirst |
| 0034 | Backup_Last_Run_Date = rst2.Fields(0).Value |
| 0035 | Backup_Changes_Since_Last_Run_Only = rst2.Fields(1).Value |
| 0036 | Backup_Last_Run_Time = rst2.Fields(3).Value |
| 0037 | Backup_Source_Root_Directory = rst2.Fields(5).Value |
| 0038 | Backup_Root_Directory = rst2.Fields(6).Value |
| 0039 | Backup_Index_Only = rst2.Fields(7).Value |
| 0040 | Backup_Mb_Check = rst2.Fields(8).Value |
| 0041 | Backup_Database = rst2.Fields(9).Value |
| 0042 | Backup_Website = rst2.Fields(10).Value |
| 0043 | Backup_Website_Root_Directory = rst2.Fields(11).Value |
| 0044 | Else |
| 0045 | MsgBox ("Backup_Control table missing: process terminated. ") |
| 0046 | End |
| 0047 | End If |
| 0048 | Set rst2 = Nothing |
| 0049 | 'Check for (and supply if necessary) trailing "\"s |
| 0050 | If Right(Backup_Source_Root_Directory, 1) <> "\" Then |
| 0051 | Backup_Source_Root_Directory = Backup_Source_Root_Directory & "\" |
| 0052 | End If |
| 0053 | If Right(Backup_Root_Directory, 1) <> "\" Then |
| 0054 | Backup_Root_Directory = Backup_Root_Directory & "\" |
| 0055 | End If |
| 0056 | Backup_Access_Root_Directory = Backup_Source_Root_Directory |
| 0057 | Backup_Root_Directory = Backup_Root_Directory & "Backup - " & Right(Year(Now()) + 100, 2) & Right(Month(Now()) + 100, 2) & Right(Day(Now()) + 100, 2) & "\" |
| 0058 | Check_Directory = Backup_Source_Root_Directory |
| 0059 | Backup_Inconsistent_Msg = "" |
| 0060 | If Left(Backup_Source_Root_Directory, 1) = Left(Backup_Root_Directory, 1) Then |
| 0061 | Backup_Inconsistent_Msg = "WARNING: Drives must differ. " |
| 0062 | End If |
| 0063 | If Left(Backup_Source_Root_Directory, 1) <> "C" Then |
| 0064 | Backup_Inconsistent_Msg = Backup_Inconsistent_Msg & "WARNING: Backup must be from C:drive. " |
| 0065 | End If |
| 0066 | Set rst = db.OpenRecordset("SELECT Count(Backup_Site_Map.FIle_Name) AS CountOfFIle_Name FROM Backup_Site_Map WHERE (((Backup_Site_Map.Directory) Like ""*" & Check_Directory & "*""));") |
| 0067 | rst.MoveFirst |
| 0068 | RecordsPrior = rst.Fields(0) |
| 0069 | Set rst = Nothing |
| 0070 | strMsg = "Backup: Parameters are:- " & Chr$(10) |
| 0071 | strMsg = strMsg & Chr$(10) & "Backup_Last_Run_Date = " & Backup_Last_Run_Date |
| 0072 | strMsg = strMsg & Chr$(10) & "Backup_Last_Run_Time = " & Round(Backup_Last_Run_Time, 1) & " hours" |
| 0073 | strMsg = strMsg & Chr$(10) & "Backup_Changes_Since_Last_Run_Only = " & Backup_Changes_Since_Last_Run_Only |
| 0074 | strMsg = strMsg & Chr$(10) & "Backup_Source_Root_Directory = " & Backup_Source_Root_Directory |
| 0075 | strMsg = strMsg & Chr$(10) & "Backup_Root_Directory = " & Backup_Root_Directory |
| 0076 | strMsg = strMsg & Chr$(10) & "Backup_Access_Root_Directory = " & Backup_Access_Root_Directory |
| 0077 | strMsg = strMsg & Chr$(10) & "Backup_Index_Only = " & Backup_Index_Only |
| 0078 | If Backup_Index_Only = "Yes" Then |
| 0079 | strMsg = strMsg & ". WARNING: No files will be backed-up or restored." |
| 0080 | End If |
| 0081 | strMsg = strMsg & Chr$(10) & "Backup_Mb_Check = " & Backup_Mb_Check |
| 0082 | strMsg = strMsg & Chr$(10) & "Backup_Database = " & Backup_Database |
| 0083 | strMsg = strMsg & Chr$(10) & "Backup_Website_Root_Directory = " & Backup_Website_Root_Directory |
| 0084 | If Backup_Website = True Then |
| 0085 | strMsg = strMsg & Chr$(10) & "Backup_Website = True" |
| 0086 | Else |
| 0087 | strMsg = strMsg & Chr$(10) & "Backup_Website = False" |
| 0088 | End If |
| 0089 | strMsg = strMsg & Chr$(10) & "RecordsPrior = " & RecordsPrior |
| 0090 | If Backup_Inconsistent_Msg <> "" Then |
| 0091 | strMsg = strMsg & Chr$(10) & Backup_Inconsistent_Msg |
| 0092 | End If |
| 0093 | strMsg = strMsg & Chr$(10) & Chr$(10) & "Proceed?" |
| 0094 | If MsgBox(strMsg, vbYesNo) = vbNo Then |
| 0095 | End |
| 0096 | Else |
| 0097 | DoCmd.Close acTable, "Backup_Control" |
| 0098 | DoCmd.Close acTable, "Backup_Directory_Structure" |
| 0099 | DoCmd.Close acTable, "Backup_Site_Map" |
| 0100 | End If |
| 0101 | MsgBox ("Off we go ... this MsgBox allows the tables to close!") |
| 0102 | Debug.Print Now() & " - Backup_Ctrl: Backup started" |
| 0103 | If Backup_Index_Only = "No" Then |
| 0104 | On Error Resume Next |
| 0105 | Set fs = CreateObject("Scripting.FileSystemObject") |
| 0106 | fs.CreateFolder (Left(Backup_Root_Directory, Len(Backup_Root_Directory) - 1)) |
| 0107 | 'Create Root Subdirectories |
| 0108 | i = InStr(Backup_Source_Root_Directory, "\") |
| 0109 | j = InStr(i + 1, Backup_Source_Root_Directory, "\") |
| 0110 | strSubDirectory = "" |
| 0111 | Do Until j = 0 Or i = 0 |
| 0112 | strSubDirectory = strSubDirectory & Mid(Backup_Source_Root_Directory, i + 1, j - i) |
| 0113 | fs.CreateFolder (Backup_Root_Directory & strSubDirectory) |
| 0114 | i = j |
| 0115 | j = InStr(i + 1, Backup_Source_Root_Directory, "\") |
| 0116 | Loop |
| 0117 | End If |
| 0118 | i = 1 |
| 0119 | Backup_Depth = 0 |
| 0120 | 'Find depth of Backup_Source_Root_Directory |
| 0121 | i = 1 |
| 0122 | Do While i < Len(Backup_Source_Root_Directory) + 1 |
| 0123 | If Mid(Backup_Source_Root_Directory, i, 1) = "\" Then |
| 0124 | Backup_Depth = Backup_Depth + 1 |
| 0125 | End If |
| 0126 | i = i + 1 |
| 0127 | Loop |
| 0128 | If Backup_Depth > 1 Then |
| 0129 | Backup_Depth = Backup_Depth - 2 |
| 0130 | End If |
| 0131 | strQuery = "SELECT Backup_Directory_Structure.* FROM Backup_Directory_Structure WHERE Backup_Directory_Structure.Directory = """ & Backup_Access_Root_Directory & """;" |
| 0132 | Set rst2 = db.OpenRecordset(strQuery) |
| 0133 | If rst2.EOF Then |
| 0134 | 'Insert a record for the root directory if one doesn't exist |
| 0135 | rst2.AddNew |
| 0136 | i = InStr(Backup_Access_Root_Directory, "\") |
| 0137 | j = InStr(i, Backup_Access_Root_Directory, "\") |
| 0138 | Do Until j = Len(Backup_Access_Root_Directory) |
| 0139 | i = j |
| 0140 | j = InStr(i + 1, Backup_Access_Root_Directory, "\") |
| 0141 | Loop |
| 0142 | rst2.Fields(0) = Backup_Access_Root_Directory |
| 0143 | rst2.Fields(1) = Mid(Backup_Access_Root_Directory, i + 1, j - i - 1) |
| 0144 | rst2.Fields(2) = Backup_Depth |
| 0145 | rst2.Fields(3) = Now() |
| 0146 | rst2.Fields(4) = "No" |
| 0147 | rst2.Fields(5) = "No" |
| 0148 | rst2.Update |
| 0149 | End If |
| 0150 | Set rst2 = Nothing |
| 0151 | Debug.Print Now() & " - Backup Scurry started" |
| 0152 | Debug.Print Now() & " - Backup_Ctrl: entering Backup_Scurry" |
| 0153 | OK = Backup_Scurry(Backup_Source_Root_Directory, Backup_Depth) |
| 0154 | 'To get round the "Insufficient memory or disk space, you won't be able to undo; continue?" problem in the following update queries:- |
| 0155 | 'a) Set the query property UseTransaction to "No" (this still produces the message, but speeds things up) |
| 0156 | 'b) Set warnings off, as below |
| 0157 | Debug.Print Now() & " - Backup_Ctrl: returned from Backup_Scurry" |
| 0158 | DoCmd.SetWarnings (False) |
| 0159 | 'Update & Tidy Up any no-longer-existent items in Directory_Structure, ... |
| 0160 | If Backup_Changes_Since_Last_Run_Only = "No" Then |
| 0161 | 'Only delete if it's not a "changes only" run (any deletions will be resolved next time there's a full run) |
| 0162 | DoCmd.RunSQL ("DELETE Backup_Directory_Structure_Zapper.* FROM Backup_Directory_Structure_Zapper;") |
| 0163 | DoCmd.OpenQuery ("Backup_Directory_Structure_Zapper_GEN") |
| 0164 | DoCmd.OpenQuery ("Backup_Directory_Structure_Prune") |
| 0165 | End If |
| 0166 | DoCmd.OpenQuery ("Backup_Directory_Structure_Add") |
| 0167 | DoCmd.OpenQuery ("Backup_Directory_Structure_Updt") |
| 0168 | Debug.Print Now() & " - Backup_Ctrl: Directory Structure changes complete" |
| 0169 | DoCmd.RunSQL ("DELETE Backup_Directory_Structure_Temp.* FROM Backup_Directory_Structure_Temp;") |
| 0170 | DoCmd.RunSQL ("INSERT INTO Backup_Directory_Structure_Temp ( Directory, Directory_Short, Directory_Level, Timestamp_Indexed, Do_Not_Backup, Changes_Only, Timestamp_Backed_Up ) SELECT [Directory] & ""\"" AS Expr1, Backup_Directory_Structure.Directory_Short, Backup_Directory_Structure.Directory_Level, Backup_Directory_Structure.Timestamp_Indexed, Backup_Directory_Structure.Do_Not_Backup, Backup_Directory_Structure.Changes_Only, Backup_Directory_Structure.Timestamp_Backed_Up FROM Backup_Directory_Structure;") |
| 0171 | Debug.Print Now() & " - Backup_Ctrl: Backup_Directory_Structure_Temp created" |
| 0172 | '... Site_Map, ... |
| 0173 | DoCmd.OpenQuery ("Backup_Site_Map_Add") |
| 0174 | DoCmd.OpenQuery ("Backup_Site_Map_Updt") |
| 0175 | If Backup_Changes_Since_Last_Run_Only = "No" Then |
| 0176 | 'Only delete it it's not a "changes only" run (any deletions will be resolved next time there's a full run) |
| 0177 | DoCmd.RunSQL ("DELETE Backup_Site_Map_Zapper.* FROM Backup_Site_Map_Zapper;") |
| 0178 | DoCmd.OpenQuery ("Backup_Site_Map_Zapper_GEN") |
| 0179 | DoCmd.OpenQuery ("Backup_Site_Map_Zapper_DirectoryGone_GEN") |
| 0180 | DoCmd.OpenQuery ("Backup_Site_Map_Prune") |
| 0181 | End If |
| 0182 | Debug.Print Now() & " - Backup_Ctrl: Backup Site Map updated" |
| 0183 | 'Tidy up Temp tables |
| 0184 | DoCmd.RunSQL ("DELETE Backup_Directory_Structure_Temp.* FROM Backup_Directory_Structure_Temp;") |
| 0185 | DoCmd.RunSQL ("DELETE Backup_Site_Map_Temp.* FROM Backup_Site_Map_Temp;") |
| 0186 | DoCmd.SetWarnings (True) |
| 0187 | Set rst = db.OpenRecordset("SELECT Count(Backup_Site_Map.FIle_Name) AS CountOfFIle_Name FROM Backup_Site_Map WHERE (((Backup_Site_Map.Directory) Like ""*" & Check_Directory & "*""));") |
| 0188 | rst.MoveFirst |
| 0189 | RecordsPost = rst.Fields(0) |
| 0190 | Set rst = Nothing |
| 0191 | Set rst2 = db.OpenRecordset("SELECT Backup_Control.* FROM Backup_Control;") |
| 0192 | Run_Duration = Now() - Start_Time |
| 0193 | If Not rst2.EOF Then |
| 0194 | rst2.MoveFirst |
| 0195 | rst2.Edit |
| 0196 | rst2.Fields(0) = Start_Time |
| 0197 | rst2.Fields(3) = Round(Run_Duration * 24, 2) |
| 0198 | rst2.Fields(4) = Files_Processed |
| 0199 | rst2.Update |
| 0200 | End If |
| 0201 | 'Add a record to the Backup History file |
| 0202 | Set rst = db.OpenRecordset("SELECT Backup_History.* FROM Backup_History WHERE Backup_History.Input_Root = """";") |
| 0203 | rst.AddNew |
| 0204 | For i = 0 To rst.Fields.Count - 1 |
| 0205 | rst.Fields(i) = rst2.Fields(i) |
| 0206 | Next i |
| 0207 | rst.Update |
| 0208 | Set rst = Nothing |
| 0209 | Set rst2 = Nothing |
| 0210 | Run_Duration = Run_Duration * 24 |
| 0211 | Debug.Print Now() & " - Backup_Ctrl: Backup complete" |
| 0212 | If Run_Duration < 1 Then |
| 0213 | Run_Duration_Text = Round(Run_Duration * 60, 2) & " minutes" |
| 0214 | Else |
| 0215 | Run_Duration_Text = Round(Run_Duration, 2) & " hours" |
| 0216 | End If |
| 0217 | strMsg = "Backup completed at " & Now() & " in " & Run_Duration_Text & "." |
| 0218 | strMsg = strMsg & Chr$(10) & "Files processed = " & Files_Processed & ", Files backed-up = " & Backup_Files_Backed_Up & "." |
| 0219 | strMsg = strMsg & Chr$(10) & "Records Prior = " & RecordsPrior & ", Records Post = " & RecordsPost & ", difference = " & RecordsPost - RecordsPrior & "." |
| 0220 | Backup_Copy_Time = Round(Backup_Copy_Time * 24 * 60, 1) |
| 0221 | strMsg = strMsg & Chr$(10) & "Time spent copying files = " & Backup_Copy_Time & " minutes." |
| 0222 | If (Backup_Errors + Backup_Errors_Full) > 0 Then |
| 0223 | DoCmd.RunSQL ("SELECT Backup_Site_Map_List.Backup_Site_Map_Object, Backup_Errors.Object_Timestamp, Backup_Errors.Object_Timestamp FROM Backup_Errors INNER JOIN Backup_Site_Map_List ON Backup_Errors.Backup_Object = Backup_Site_Map_List.Backup_Site_Map_Object WHERE (((Backup_Errors.Object_Timestamp) > " & Start_Time & "And ((Backup_Errors.Object_Timestamp) <> [Backup_Site_Map_List]![File_Timestamp])) ORDER BY Backup_Site_Map_List.Backup_Site_Map_Object;") |
| 0224 | strMsg = strMsg & Chr$(10) & "There were " & (Backup_Errors + Backup_Errors_Full) & " errors. Please investigate the Backup_Error_Table. " |
| 0225 | DoCmd.OpenTable ("Backup_Errors") |
| 0226 | End If |
| 0227 | Debug.Print Now() & " - Backup_Ctrl: " & strMsg |
| 0228 | MsgBox (strMsg) |
| 0229 | End Sub |
| Line-No. / Ref. | Code Line |
| 0001 | Public Function Backup_Scurry(DirectoryName, DirectoryLevel_In, Optional No_Backup) |
| 0002 | Dim rst As Recordset |
| 0003 | Dim rst2 As Recordset |
| 0004 | Dim db As Database |
| 0005 | Dim OK As String |
| 0006 | Dim Check_File As String |
| 0007 | Dim fs As Object |
| 0008 | Dim fso As FileSystemObject |
| 0009 | Dim Directory_Out As String |
| 0010 | Dim MainFolder |
| 0011 | Dim FileCollection |
| 0012 | Dim File |
| 0013 | Dim File_Name As String |
| 0014 | Dim x As Long |
| 0015 | Dim DirectoryLevel As Integer |
| 0016 | Dim File_Timestamp As Date |
| 0017 | Dim Updates_Only As String |
| 0018 | Dim File_Wanted As String |
| 0019 | Dim Start_Parsing_Time As Single |
| 0020 | Dim End_Parsing_Time As Single |
| 0021 | Dim Where_Are_We As String |
| 0022 | Dim No_Backup_Now |
| 0023 | Dim No_Backup_Later |
| 0024 | Dim strMsg As String |
| 0025 | Dim Response |
| 0026 | Dim TransferName As String |
| 0027 | Dim TempDirectory As String |
| 0028 | Dim SiteMapDirectory As String |
| 0029 | Dim From_Date_Found As String |
| 0030 | Dim From_Date As Date |
| 0031 | Dim Check_Directory As String |
| 0032 | Dim Wanted_for_Backup As Boolean |
| 0033 | Dim Backup_Time As Double |
| 0034 | Const Backup_Errors_Max As Integer = 50 |
| 0035 | 'This is a recursive Sub - ie. it calls itself |
| 0036 | Backup_Scurry = "OK" |
| 0037 | Where_Are_We = "Top" |
| 0038 | DirectoryLevel = DirectoryLevel_In + 1 |
| 0039 | Set fs = CreateObject("Scripting.FileSystemObject") |
| 0040 | Set fso = CreateObject("Scripting.FileSystemObject") |
| 0041 | On Error GoTo Report_Error |
| 0042 | Set db = CurrentDb |
| 0043 | 'Allow for stopping the Backup mid-flight (eg. if it's taking ages) while allowing an orderly shut-down |
| 0044 | 'Note: Need a second copy of MS Access open for this to work |
| 0045 | Set rst2 = db.OpenRecordset("SELECT Backup_Control.* FROM Backup_Control;") |
| 0046 | If Not rst2.EOF Then |
| 0047 | rst2.MoveFirst |
| 0048 | If rst2.Fields(2).Value = "Yes" Then |
| 0049 | Stop |
| 0050 | Exit Function |
| 0051 | End If |
| 0052 | End If |
| 0053 | Set rst2 = Nothing |
| 0054 | 'Backup |
| 0055 | TempDirectory = DirectoryName |
| 0056 | If Backup_Changes_Since_Last_Run_Only = "Yes" Then |
| 0057 | 'Changes-Only backup ... need to determine the "From Date" for this directory |
| 0058 | Set rst2 = db.OpenRecordset("SELECT Backup_History.Input_Root, Backup_History.Backup_Run_Date FROM Backup_History WHERE (((Backup_History.Index_Only) = ""No"")) ORDER BY Backup_History.Backup_Run_Date DESC;") |
| 0059 | If Not rst2.EOF Then |
| 0060 | rst2.MoveFirst |
| 0061 | From_Date_Found = "No" |
| 0062 | From_Date = Backup_Last_Run_Date |
| 0063 | Do Until From_Date_Found = "Yes" |
| 0064 | Check_Directory = rst2.Fields(0) |
| 0065 | If Right(Check_Directory, 1) <> "\" Then |
| 0066 | Check_Directory = Check_Directory & "\" |
| 0067 | End If |
| 0068 | If Len(Check_Directory) <= Len(DirectoryName) Then |
| 0069 | If Left(DirectoryName, Len(Check_Directory)) = Check_Directory Then |
| 0070 | From_Date_Found = "Yes" |
| 0071 | From_Date = rst2.Fields(1) |
| 0072 | End If |
| 0073 | End If |
| 0074 | If Not rst2.EOF Then |
| 0075 | rst2.MoveNext |
| 0076 | Else |
| 0077 | From_Date_Found = "Yes" |
| 0078 | End If |
| 0079 | Loop |
| 0080 | End If |
| 0081 | End If |
| 0082 | Set rst2 = db.OpenRecordset("SELECT Backup_Directory_Structure.Do_Not_Backup, Backup_Directory_Structure.Changes_Only FROM Backup_Directory_Structure WHERE Backup_Directory_Structure.Directory =""" & TempDirectory & """;") |
| 0083 | 'Backup items in this directory? |
| 0084 | If IsMissing(No_Backup) Then |
| 0085 | No_Backup_Now = "No" |
| 0086 | Else |
| 0087 | No_Backup_Now = No_Backup |
| 0088 | End If |
| 0089 | If Not rst2.EOF Then |
| 0090 | If rst2.Fields(0).Value = "Yes" Or No_Backup_Now = "Yes" Then 'We don't ... |
| 0091 | 'Sub-directories are "No_Backup" if a direcory is, except for the main directory (else nothing would be done!) |
| 0092 | If DirectoryLevel_In = 0 Then |
| 0093 | No_Backup_Later = "No" |
| 0094 | Else |
| 0095 | No_Backup_Later = "Yes" |
| 0096 | End If |
| 0097 | Set MainFolder = fso.GetFolder(DirectoryName) |
| 0098 | GoTo Recursion |
| 0099 | End If |
| 0100 | End If |
| 0101 | No_Backup_Later = "No" 'Ie. We do want to Backup sub-directories, unless specifically over-ridden |
| 0102 | 'We do ... ! Now note if "Updates Only" for this Directory |
| 0103 | If Not rst2.EOF Then |
| 0104 | Updates_Only = rst2.Fields(1).Value |
| 0105 | Else |
| 0106 | Updates_Only = "No" |
| 0107 | End If |
| 0108 | Set rst2 = Nothing |
| 0109 | Set MainFolder = fso.GetFolder(DirectoryName) |
| 0110 | Set FileCollection = MainFolder.Files |
| 0111 | 'Main Folders |
| 0112 | On Error Resume Next |
| 0113 | 'This is a backup, so "lose" the "C:\" prefix |
| 0114 | TempDirectory = Backup_Root_Directory & Mid(DirectoryName, 4, Len(DirectoryName)) |
| 0115 | 'Create backup (or restore) directory |
| 0116 | fs.CreateFolder (TempDirectory) |
| 0117 | On Error GoTo Report_Error |
| 0118 | For Each File In FileCollection |
| 0119 | File_Wanted = "Yes" |
| 0120 | File_Name = File.Name |
| 0121 | File_Timestamp = File.DateLastModified |
| 0122 | If Updates_Only = "Yes" And Backup_Changes_Since_Last_Run_Only = "Yes" Then |
| 0123 | If File_Timestamp < From_Date Then |
| 0124 | File_Wanted = "No" |
| 0125 | End If |
| 0126 | End If |
| 0127 | If File_Wanted = "Yes" Then |
| 0128 | 'Check if large files are to be backed up |
| 0129 | If File.Size / 1000000 > Backup_Mb_Check Then |
| 0130 | Set rst2 = db.OpenRecordset("SELECT Backup_Site_Map.* FROM Backup_Site_Map WHERE (((Backup_Site_Map.Directory)=""" & DirectoryName & """) AND ((Backup_Site_Map.File_Name)=""" & File_Name & """));") |
| 0131 | If Not rst2.EOF Then |
| 0132 | rst2.MoveFirst |
| 0133 | If rst2.Fields(4).Value = "Yes" Then 'Check if file (as distinct from the directory) is not to be processed |
| 0134 | File_Wanted = "No" |
| 0135 | End If |
| 0136 | End If |
| 0137 | End If |
| 0138 | Set rst2 = Nothing |
| 0139 | End If |
| 0140 | Start_Parsing_Time = Now() |
| 0141 | 'Log file stats |
| 0142 | SiteMapDirectory = DirectoryName |
| 0143 | Set rst2 = db.OpenRecordset("SELECT Backup_Site_Map_Temp.* FROM Backup_Site_Map_Temp WHERE (((Backup_Site_Map_Temp.Directory)=""" & SiteMapDirectory & """) AND ((Backup_Site_Map_Temp.File_Name)=""" & File_Name & """));") |
| 0144 | If rst2.EOF Then |
| 0145 | On Error GoTo Report_Error |
| 0146 | Where_Are_We = "Bug_1" |
| 0147 | rst2.AddNew |
| 0148 | rst2.Fields(0) = SiteMapDirectory |
| 0149 | rst2.Fields(1) = File_Name |
| 0150 | rst2.Fields(2) = Now() |
| 0151 | rst2.Fields(3) = File.Size |
| 0152 | rst2.Fields(4) = "No" |
| 0153 | If File_Wanted = "Yes" Then |
| 0154 | End_Parsing_Time = Now() 'Used to be "Timer"; why? |
| 0155 | rst2.Fields(5) = (End_Parsing_Time - Start_Parsing_Time) * 1000 |
| 0156 | Else |
| 0157 | rst2.Fields(5) = 0 |
| 0158 | End If |
| 0159 | rst2.Fields(6) = SiteMapDirectory & File_Name |
| 0160 | rst2.Fields(7) = File_Timestamp |
| 0161 | rst2.Update |
| 0162 | Files_Processed = Files_Processed + 1 |
| 0163 | Bug_1_Return: |
| 0164 | End If |
| 0165 | Set rst2 = Nothing |
| 0166 | Where_Are_We = "Bug_3" |
| 0167 | If File_Wanted = "Yes" Then |
| 0168 | 'We'll start the backup here ... |
| 0169 | On Error GoTo Report_Error |
| 0170 | 'Only back-up Website files if the parameters so indicate ... |
| 0171 | Wanted_for_Backup = True |
| 0172 | If Left(DirectoryName, Len(Backup_Website_Root_Directory)) = Backup_Website_Root_Directory Then |
| 0173 | If Backup_Website = False Then |
| 0174 | Wanted_for_Backup = False |
| 0175 | End If |
| 0176 | End If |
| 0177 | 'Don't try to backup transfer files! |
| 0178 | TransferName = TempDirectory & File_Name |
| 0179 | If Left(DirectoryName & File_Name, Len("C:\Theo's Files\Websites\Transfer\")) = "C:\Theo's Files\Websites\Transfer\" Then |
| 0180 | Wanted_for_Backup = False |
| 0181 | End If |
| 0182 | If Wanted_for_Backup = True Then |
| 0183 | Backup_Time = Now() |
| 0184 | If Dir(TransferName) <> "" Then 'If we already have a file in the backup directory, then zap it |
| 0185 | Kill TransferName |
| 0186 | End If |
| 0187 | Where_Are_We = "Bug_4" |
| 0188 | fs.CopyFile DirectoryName & File_Name, TransferName |
| 0189 | Backup_Time = Now() - Backup_Time |
| 0190 | Backup_Copy_Time = Backup_Copy_Time + Backup_Time |
| 0191 | Backup_Files_Backed_Up = Backup_Files_Backed_Up + 1 |
| 0192 | End If |
| 0193 | Where_Are_We = "Bug_5" |
| 0194 | Bug_3_Return: |
| 0195 | End If |
| 0196 | Next File |
| 0197 | Recursion: |
| 0198 | Set FileCollection = MainFolder.SubFolders |
| 0199 | For Each File In FileCollection |
| 0200 | Where_Are_We = "Bug_2" |
| 0201 | Err.Clear |
| 0202 | On Error GoTo Report_Error |
| 0203 | File_Name = File.Name |
| 0204 | Directory_Out = DirectoryName & File_Name & "\" |
| 0205 | TempDirectory = DirectoryName |
| 0206 | 'Write out a record (to Backup_Directory_Structure_Temp) for each sub-directory ... if not already there (can it be?) |
| 0207 | Set rst2 = db.OpenRecordset("SELECT Backup_Directory_Structure_Temp.* FROM Backup_Directory_Structure_Temp WHERE Backup_Directory_Structure_Temp.Directory =""" & TempDirectory & File_Name & "\" & """;") |
| 0208 | If rst2.EOF Then |
| 0209 | rst2.AddNew |
| 0210 | rst2.Fields(0) = TempDirectory & File_Name & "\" |
| 0211 | rst2.Fields(1) = File_Name |
| 0212 | rst2.Fields(2) = DirectoryLevel |
| 0213 | rst2.Fields(3) = Now() |
| 0214 | rst2.Fields(6) = Now() |
| 0215 | rst2.Fields(7) = File.DateLastModified |
| 0216 | rst2.Update |
| 0217 | End If |
| 0218 | Set rst2 = Nothing |
| 0219 | 'Recursion ... |
| 0220 | OK = Backup_Scurry(Directory_Out, DirectoryLevel, No_Backup_Later) |
| 0221 | On Error GoTo Report_Error |
| 0222 | Bug_2_Return: |
| 0223 | Next File |
| 0224 | GoTo Tidy_Up |
| 0225 | Report_Error: |
| 0226 | Backup_Errors = Backup_Errors + 1 |
| 0227 | 'Update error file |
| 0228 | Set rst = db.OpenRecordset("SELECT Backup_Errors.* FROM Backup_Errors;") |
| 0229 | rst.AddNew |
| 0230 | rst.Fields(1) = Err.Number |
| 0231 | rst.Fields(2) = Err.Description |
| 0232 | rst.Fields(3) = SiteMapDirectory & File_Name |
| 0233 | Select Case Where_Are_We |
| 0234 | Case "Bug_1" |
| 0235 | rst.Fields(4) = Where_Are_We & ": Backup_Site_Map_Temp" |
| 0236 | Case "Bug_2" |
| 0237 | rst.Fields(4) = Where_Are_We & ": Backup_Directory_Structure_Temp" |
| 0238 | Case "Bug_3" |
| 0239 | rst.Fields(4) = Where_Are_We & ": Back-up File - Kill" |
| 0240 | Case "Bug_4" |
| 0241 | rst.Fields(4) = Where_Are_We & ": Back-up File - Copy" |
| 0242 | Case Else |
| 0243 | End Select |
| 0244 | rst.Fields(5) = Now() |
| 0245 | rst.Fields(6) = File_Timestamp |
| 0246 | rst.Update |
| 0247 | Set rst = Nothing |
| 0248 | If Backup_Errors_Stop = False Then |
| 0249 | If Backup_Errors > Backup_Errors_Max Then |
| 0250 | Backup_Errors_Full = Backup_Errors_Full + Backup_Errors |
| 0251 | strMsg = Now() & ": Backup_Scurry - There have been " & Backup_Errors & " errors since the last of these messages (if any) - respond ""Yes"" to continue with more of these messages, ""No"" to continue without any more of these messages or ""Cancel"" to abort. " |
| 0252 | Response = MsgBox(strMsg, vbYesNoCancel) |
| 0253 | If Response = vbCancel Then |
| 0254 | Stop |
| 0255 | End |
| 0256 | Else |
| 0257 | If Response = vbNo Then |
| 0258 | Backup_Errors_Stop = True |
| 0259 | End If |
| 0260 | End If |
| 0261 | Backup_Errors = 0 |
| 0262 | End If |
| 0263 | End If |
| 0264 | Err.Clear |
| 0265 | On Error GoTo Report_Error |
| 0266 | Select Case Where_Are_We |
| 0267 | Case "Bug_1" |
| 0268 | Resume Bug_1_Return |
| 0269 | Case "Bug_2" |
| 0270 | Resume Bug_2_Return |
| 0271 | Case "Bug_3", "Bug_4" |
| 0272 | Resume Bug_3_Return |
| 0273 | Case Else |
| 0274 | Stop |
| 0275 | End Select |
| 0276 | Tidy_Up: |
| 0277 | Set rst2 = Nothing |
| 0278 | Set rst = Nothing |
| 0279 | Set MainFolder = Nothing |
| 0280 | Set FileCollection = Nothing |
| 0281 | End Function |