-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumpIB.au3
601 lines (581 loc) · 22.5 KB
/
DumpIB.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
;~ #NoTrayIcon
#Include <Array.au3>
#include <Date.au3>
#include <ServiceControl.au3>
#Include <file.au3>
#include <GUIConstants.au3>
#include <FTPEx.au3>
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $Path=@ScriptDir & "\"
$PSD="dumpday"
$FirstStart=false
DeleteBigLog ()
;Ïîëó÷åíèå èç ôàéëà íåîáõîäèìûõ ïàðàìåòðîâ
If not FileExists($Path & "config.ini") Then
;Ñîçäàòü ôàéë config.ini ñ ïàðàìåòðàìè ïî óìîë÷àíèþ
$file = FileOpen($Path & "config.ini", 1)
FileWriteLine($file, "PathProgramm=c:\Program Files\1cv82\common\1cestart.exe")
FileWriteLine($file, "PathServer= íåîáõîäèìî óêàçàòü ÑåðâåðÁÄ")
FileWriteLine($file, "PathServerBase= íåîáõîäèìî óêàçàòü íàçâàíèåÁÄ")
FileWriteLine($file, "FileServer=server")
FileWriteLine($file, "PathDump=" & $Path)
FileWriteLine($file, "user=DumpIB")
FileWriteLine($file, "CloseAll_1c=false")
FileWriteLine($file, "BaseName=óêàçàòü íàçâàíèå ôèëèàëà")
FileWriteLine($file, "mailto=ÿùèê íà êîòîðûé îòñûëàåòñÿ ïèñüìî, â ñëó÷àå íåóäà÷è")
FileWriteLine($file, "CountOfDT=7")
FileWriteLine($file, "FTP_IP=10.0.0.234")
FileWriteLine($file, "PathDumpDB2=C:\Temp")
FileWriteLine($file, "Scheduler=2,6")
FileWriteLine($file, "RestartService=true")
FileClose($file)
$FirstStart=true
EndIf
If $FirstStart Then
Exit
EndIf
;Ñ÷èòûâàåì ïàðàìåòðû èç ôàéëà
$file = FileOpen($Path & "config.ini", 0)
If $file = -1 Then
WriteLog("Unable to open file config.ini","logDumpIB.txt",1)
Exit
EndIf
; Read in lines of text until the EOF is reached
$Size=GetCountOfLines()
Dim $aArray[$Size][2]
$NS=0;
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$poz=StringInStr($Line, "=")
$Parametr = StringLeft($Line, $poz-1)
$Value=StringMid($Line,$poz+1)
$aArray[$NS][0]=$Parametr
$aArray[$NS][1]=$Value
$NS=$NS+1;
Wend
FileClose($file)
$ParametrsLoad=false
$ParametrsLoad=CheckParametr ($aArray,$Size)
;~ Msgbox(0,"",DriveSpaceFree(GetValue("PathDump",$aArray)))
If DriveSpaceFree(GetValue("PathDump",$aArray)) <3000 then
WriteLog("Çàêàí÷èâàåòñÿ ìåñòî " & GetValue("PathDump",$aArray),"logDumpIB.txt",1)
SendMail("Çàêàí÷èâàåòñÿ ìåñòî â - " & GetValue("BaseName",$aArray) & " ñì. ïîäðîáíîñòè â log ôàéëå ",GetValue("mailto",$aArray))
EndIf
If DriveSpaceFree("C:\") <3000 then
WriteLog("Íà ôèëèàëå " & GetValue("BaseName",$aArray) & " çàêàí÷èâàåòñÿ ìåñòî íà äèñêå " & "C:\" ,"logDumpIB.txt",1)
SendMail("Íà ôèëèàëå " & GetValue("BaseName",$aArray) & " çàêàí÷èâàåòñÿ ìåñòî íà äèñêå " & "C:\" ,GetValue("mailto",$aArray))
EndIf
WriteLog("Íà÷àëî âûïîëíåíèÿ ","logDumpIB.txt",1)
if $ParametrsLoad then
$TimeStr=_NowDate()
; Çàâåðøàåì âñå ñåàíñû 1ñ
$TimeStr = StringReplace($TimeStr, ".", "")
$NameDump=GetValue("BaseName",$aArray) & "_" & $TimeStr;
;Âûãðóçêà â DT
$NomerPoputki=1
While $NomerPoputki<=3 And Not FileExists(GetValue("PathDump",$aArray) & $NameDump &".dt")
if GetValue("FileServer",$aArray) = "server" then
$StrokaZapuska=chr(34) & GetValue("PathProgramm",$aArray) & chr(34) & " DESIGNER /S " & GetValue("PathServer",$aArray) & "\" & GetValue("PathServerBase",$aArray) & " /N " & GetValue("user",$aArray) & " /P "& $PSD &" /Out " & GetValue("PathDump",$aArray) & "log.txt" & " /DumpIB " & GetValue("PathDump",$aArray) & $NameDump &".dt" & " /DumpResult " & GetValue("PathDump",$aArray) & "result" & $NomerPoputki&".txt"
Else
$StrokaZapuska=chr(34) & GetValue("PathProgramm",$aArray) & chr(34) & " DESIGNER /F " & GetValue("PathServer",$aArray) & " /N " & GetValue("user",$aArray) & " /P "& $PSD &" /Out " & GetValue("PathDump",$aArray) & "log.txt" & " /DumpIB " & GetValue("PathDump",$aArray) & $NameDump &".dt" & " /DumpResult " & GetValue("PathDump",$aArray) & "result" & $NomerPoputki&".txt"
EndIf
;~ WriteLog($StrokaZapuska,"logDumpIB.txt",1)
;~ exit
;~ WriteLog("Äî âûãîíà","logDumpIB.txt",1)
if StringLower(GetValue("CloseAll_1c",$aArray)) = "true" then
ClosseAll_1c($aArray)
endif
if StringLower(GetValue("RestartService",$aArray)) = "true" then
$sServiceName="MSSQL$SQLEXPRESS"
_StopService("", $sServiceName)
WriteLog("Îñòàíîâêà ñëóæáû - " & $sServiceName,"logDumpIB.txt",1)
Sleep(60000)
_StartService("", $sServiceName)
WriteLog("Çàïóñê ñëóæáû - " & $sServiceName,"logDumpIB.txt",1)
Sleep(60000)
$sServiceName1c="1C:Enterprise 8.2 Server Agent"
_StopService("", $sServiceName1c)
WriteLog("Îñòàíîâêà ñëóæáû - " & $sServiceName1c,"logDumpIB.txt",1)
Sleep(60000)
_StartService("", $sServiceName1c)
WriteLog("Çàïóñê ñëóæáû - " & $sServiceName1c,"logDumpIB.txt",1)
Sleep(60000)
EndIf
WriteLog("Âûãðóçêà â DT ôàéë, ïîïûòêà - " & $NomerPoputki,"logDumpIB.txt",1)
If FileExists(GetValue("PathDump",$aArray) & "result"& $NomerPoputki &".txt") Then
if FileDelete(GetValue("PathDump",$aArray) & "result"& $NomerPoputki &".txt") = 0 then
WriteLog("Íå óäàëîñü óäàëèòü ôàéë, result.txt","logDumpIB.txt",1)
EndIf
endif
if Run($StrokaZapuska)=0 Then
WriteLog("Íå óäàëîñü âûãðóçèòü â DT, ïðîâåðüòå ïðàâèëüíîñòü çíà÷åíèÿ ïàðàìåòðîâ â ôàéëå config.ini","logDumpIB.txt",1)
SendMail("Íå óäàëîñü ñîçäàòü áåêàï áàçû - " & GetValue("BaseName",$aArray) & " ñì. ïîäðîáíîñòè â log ôàéëå ",GetValue("mailto",$aArray))
Exit
EndIf
$MaksTimeCheck=7200000 ;äî 2-õ ÷àñîâ ïðîâåðÿåì íàëè÷èå ôàéëà result.txt
$TekTimeCheck=0;
While not FileExists(GetValue("PathDump",$aArray) & "result"& $NomerPoputki &".txt") and $TekTimeCheck <= $MaksTimeCheck
sleep(5000)
$TekTimeCheck=$TekTimeCheck+5000
Wend
if FileExists(GetValue("PathDump",$aArray) & "result"& $NomerPoputki &".txt") and $TekTimeCheck <= $MaksTimeCheck Then
if not ReadResult(GetValue("PathDump",$aArray) & "result"& $NomerPoputki &".txt") then
WriteLog("Íå óäàëîñü âûãðóçèòü â DT","logDumpIB.txt",1)
;~ SendMail("Íå óäàëîñü ñîçäàòü áåêàï áàçû - " & GetValue("BaseName",$aArray) & " ñì. ïîäðîáíîñòè â log ôàéëå ",GetValue("mailto",$aArray))
Else
WriteLog("Âûãðóçêà â DT ôàéë çàâåðøåíà","logDumpIB.txt",1)
ExitLoop
EndIf
Else
WriteLog("Íå óäàëîñü âûãðóçèòü â DT, result.txt Íåò, TekTime-" & $TekTimeCheck,"logDumpIB.txt",1)
EndIf
;çàäåðæêà ìåæäó ïîïûòêàìè. 5 ìèíóò
sleep(300000)
$NomerPoputki=$NomerPoputki+1
WEnd
Else
WriteLog("Ïàðàìåòðû âûãðóçêè íå çàãðóæåíû.","logDumpIB.txt",1)
SendMail("Íå óäàëîñü ñîçäàòü áåêàï áàçû - " & GetValue("BaseName",$aArray) & " ñì. ïîäðîáíîñòè â log ôàéëå ",GetValue("mailto",$aArray))
endif
if Not FileExists(GetValue("PathDump",$aArray) & $NameDump &".dt") then
SendMail("Íå óäàëîñü ñîçäàòü áåêàï áàçû - " & GetValue("BaseName",$aArray) & " ñì. ïîäðîáíîñòè â log ôàéëå ",GetValue("mailto",$aArray))
Else
If FileExists(GetValue("PathDump",$aArray) & "log.txt") then
WriteLog("Ok",$NameDump & ".txt",1)
$Poz=StringInStr(GetValue("Scheduler",$aArray), _DateToDayOfWeek (@YEAR, @MON, @MDAY))
$fl_DTUpload=True
$TimeBefore=_NowCalc()
if $Poz<>0 then
$fl_DTUpload=FtpUpload($NameDump & ".dt",$aArray,"\backup\DT\",false)
$UploadTime = _DateDiff( 's',$TimeBefore,_NowCalc())
$UploadTime=Round($UploadTime/60,2)
WriteLog("Âðåìÿ çàãðóçêè íà FTP " & $UploadTime & " ìèíóò","logDumpIB.txt",1)
WriteLog("Âðåìÿ çàãðóçêè íà FTP " & $UploadTime & " ìèíóò",$NameDump & ".txt",1)
EndIf
if $fl_DTUpload Then
FtpUpload($NameDump & ".txt",$aArray,"\backup\",true)
EndIf
EndIf
EndIf
if FileExists(GetValue("PathDump",$aArray) & $NameDump &".dt") then
DeleteOldDT($aArray)
EndIf
WriteLog("Êîíåö âûïîëíåíèÿ ","logDumpIB.txt",1)
;~ DeleteOld_DB2_BAP($aArray)
func GetCountOfLines()
$fileSize = FileOpen($Path & "config.ini", 0)
$Size=0
While 1
$line = FileReadLine($fileSize)
If @error = -1 Then ExitLoop
$Size=$Size+1
Wend
FileClose($fileSize)
Return $Size
EndFunc
Func GetValue($Parametr,$aArray)
;~ MsgBox(0, "Error", @error)
$iIndex = _ArraySearch($aArray, $Parametr, 0, 0, 0, 1, 1, 0)
if @error <> 0 Then
if @error=6 then
MsgBox(0, "Error", "Ïàðàìåòð-" & $Parametr & " íå íàéäåí â ìàññèâå")
EndIf
else
Return $aArray[$iIndex][1]
EndIf
EndFunc
Func CheckParametr ($aArray,$Size)
For $i = 0 to $Size-1
$Parametr=$aArray[$i][0]
$Value=$aArray[$i][1]
;~ if $Parametr="FileServer" Then
;~ $Value=StringLower($Value)
;~ if $Value<>"server" And $Value<>"file" Then
;~ WriteLog("Íå ïðàâèëüíî óêàçàí òèï ÁÄ, íåîáõîäèìî óêàçàòü file/server, â ôàéëå config.ini","logConfig.txt",2)
;~ return false
;~ endif
;~ endif
if $Parametr="PathProgramm" or $Parametr="PathDump" or $Parametr="user" or $Parametr="BaseName" Then
$Value=StringReplace($Value, " ", "")
if $Value="" Then
WriteLog("Çàïîëíèòå PathProgramm/PathDump/user/BaseName, â ôàéëå config.ini","logConfig.txt",2)
return false
endif
endif
if $Parametr="PathServer" or $Parametr="PathServerBase" then
$Value=StringReplace($Value, " ", "")
if $Value="" Then
WriteLog("Çàïîëíèòå PathServer/PathServerBase, â ôàéëå config.ini","logConfig.txt",2)
return false
endif
endif
if $Parametr="CloseAll_1c" Then
$Value=StringLower($Value)
if $Value<> "false" and $Value<> "true"then
WriteLog("Íåïðàâèëüíî çàïîëíåí CloseAll_1c,íåîáõîäèìî óêàçàòü true/false, â ôàéëå config.ini","logConfig.txt",2)
return false
endif
EndIf
;~ if $Parametr="SQLService" Then
;~ $Value=StringLower($Value)
;~ if $Value<> "db2" and $Value<> "mssqlserver"then
;~ WriteLog("Íåïðàâèëüíî çàïîëíåí SQLService,íåîáõîäèìî óêàçàòü db2/mssqlserver, â ôàéëå config.ini","logConfig.txt",2)
;~ return false
;~ endif
;~ EndIf
;~ if $Parametr="1cAgent" Then
;~ $Value=StringLower($Value)
;~ if $Value<> "1c:enterprise 8.2 server agent" then
;~ WriteLog("Íåïðàâèëüíî çàïîëíåí 1cAgent,íåîáõîäèìî óêàçàòü 1c:enterprise 8.2 server agent, â ôàéëå config.ini","logConfig.txt",2)
;~ return false
;~ endif
;~ EndIf
Next
If FileExists($Path & "logConfig.txt") Then
FileDelete($Path & "logConfig.txt")
endif
return true
EndFunc
Func WriteLog($Text,$NameLog,$Mode)
$Time=_Date_Time_GetLocalTime()
$Time=_Date_Time_SystemTimeToDateTimeStr($Time)
$logfile = FileOpen($Path & $NameLog, $Mode)
FileWriteLine($logfile,$Time & "-" & $Text)
FileClose($logfile)
EndFunc
Func DeleteBigLog ()
If FileExists($Path & "logDumpIB.txt") Then
$sizelog = FileGetSize($Path & "logDumpIB.txt")
$sizelog=$sizelog/1000000
if $sizelog >=2 then
FileDelete($Path & "logDumpIB.txt")
EndIf
endif
endfunc
Func ReadResult($FileResult)
$fileRes = FileOpen($FileResult, 0)
; Check if file opened for reading OK
If $fileRes = -1 Then
;~ MsgBox(0, "Error", "Unable to open file.")
WriteLog("Unable to open file result.txt","logDumpIB.txt",1)
return false
EndIf
$lineResult = FileReadLine($fileRes)
If @error = -1 Then
return false
EndIf
if $lineResult=1 then
Return False
EndIf
return true
endfunc
Func ClosseAll_1c($aArray)
;~ WriteLog("Ñîçäàíèå v82.COMConnector" ,"logDumpIB.txt",1)
$oShell = ObjCreate("v82.COMConnector")
;~ WriteLog("$oShell.ConnectAgent" ,"logDumpIB.txt",1)
;~ WriteLog(GetValue("PathServer",$aArray) ,"logDumpIB.txt",1)
$Agent=$oShell.ConnectAgent(GetValue("PathServer",$aArray));
;~ WriteLog("$Agent.GetClusters()" ,"logDumpIB.txt",1)
$Klasters=$Agent.GetClusters();
$BaseName=GetValue("PathServerBase",$aArray)
WriteLog("Îòêëþ÷åíèå ñåàíñîâ îò áàçû - " & $BaseName ,"logDumpIB.txt",1)
For $Klaster In $Klasters
$Name=GetValue("user",$aArray)
;~ $Agent.AuthenticateAgent("", "")
$Agent.Authenticate($Klaster,"", "")
;~ $Agent.Authenticate($Klaster,$Name, "")
$Proceses=$Agent.GetWorkingProcesses($Klaster)
For $Process In $Proceses
$Port=$Process.MainPort
$WorkingProcess= $oShell.ConnectWorkingProcess(GetValue("PathServer",$aArray) & ":" & $Port)
$WorkingProcess.AddAuthentication($Name,$PSD)
$InfoBase=""
$Bases=$Agent.GetInfoBases($Klaster)
For $Base in $Bases
if $Base.Name=$BaseName Then
$InfoBase=$Base
;~ $Base.DeniedFrom=StringReplace(_NowCalcDate(),"/","")
;~ $Base.DeniedFrom=_NowCalc()
;~ $Base.DeniedTo=_DateAdd( 'n',30,_NowCalc())
;~ $Base.DeniedMessage="Áàçà ñ " & $Base.DeniedFrom & " äî " & $Base.DeniedTo & " äîñòóïíà íå áóäåò"
;~ $Base.PermissionCode="77"
;~ $Base.SessionsDenied=0
;~ $Base.ScheduledJobsDenied=
;~ MsgBox(0,"", $Base.SessionsDenied)
;~ MsgBox(0,"","Áëîê-" & $Base.DeniedTo)
;~ $Base.Descr="adsf"
;~ Exit
ExitLoop
EndIf
Next
if $InfoBase="" Then
WriteLog("Áàçà íå îáíàðóæåíà - " & $BaseName ,"logDumpIB.txt",1)
else
$Sessions=$Agent.GetInfoBaseSessions($Klaster, $InfoBase)
For $Session in $Sessions
$Agent.TerminateSession($Klaster, $Session)
Next
$Connections=$Agent.GetInfoBaseConnections($Klaster, $InfoBase)
For $Connection in $Connections
$WorkingProcess.Disconnect($Connection)
Next
EndIf
Next
Next
WriteLog("Ñåàíñû îòêëþ÷åíû îò áàçû - " & $BaseName ,"logDumpIB.txt",1)
EndFunc
;~ ÎòïðàâêàÏî÷òû
Func SendMail($Text,$ToAddress)
$SmtpServer = "smtp.mail.ru" ; address for the smtp-server to use - REQUIRED
$FromName = "Dump" ; name from who the email was sent
$FromAddress = "BlizzardAnton@mail.ru" ; address from where the mail should come
;~ $ToAddress = "BlizzardAnton@mail.ru" ; destination address of the email - REQUIRED
$Subject = $Text ; subject from the email - can be anything you want it to be
$Body = $Text ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
if $ToAddress <> "BlizzardAnton@mail.ru" then
$CcAddress = "BlizzardAnton@mail.ru" ; address for cc - leave blank if not needed
Else
$CcAddress = ""
EndIf
$BccAddress = "" ; address for bcc - leave blank if not needed
$Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
$Username = "BlizzardAnton" ; username for the account used from where the mail gets sent - REQUIRED
$Password = "ghtptyn ajh . 31" ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 25 ; port used for sending the mail
$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
$IPPort=465 ; GMAIL port used for sending the mail
$ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
_SendMail ($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
EndFunc
Func _SendMail ($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
;~ MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
WriteLog("Íå óäàëîñü îòïðàâèòü ñîîáùåíèå íà ïî÷òó","logDumpIB.txt",1)
EndIf
endfunc
;
; The UDF
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
Local $objEmail = ObjCreate("CDO.Message")
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
Local $i_Error = 0
Local $i_Error_desciption = ""
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
$objEmail.HTMLBody = $as_Body
Else
$objEmail.Textbody = $as_Body & @CRLF
EndIf
If $s_AttachFiles <> "" Then
Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
For $x = 1 To $S_Files2Attach[0]
$S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
If FileExists($S_Files2Attach[$x]) Then
ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
$objEmail.AddAttachment($S_Files2Attach[$x])
Else
ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
SetError(1)
Return 0
EndIf
Next
EndIf
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
If Number($IPPort) = 0 then $IPPort = 25
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
;Authenticated SMTP
If $s_Username <> "" Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
EndIf
If $ssl Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
;Update settings
$objEmail.Configuration.Fields.Update
; Set Email Importance
Switch $s_Importance
Case "High"
$objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
Case "Normal"
$objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
Case "Low"
$objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
EndSwitch
$objEmail.Fields.Update
; Sent the Message
$objEmail.Send
If @error Then
SetError(2)
Return $oMyRet[1]
EndIf
$objEmail=""
EndFunc ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
Func DeleteOld_DB2_BAP($aArray)
$SizeDT=GetCountFilesDT(GetValue("PathDumpDB2",$aArray) & "*.001")
if $SizeDT <= 5 then
return 0
EndIf
Dim $arrayDB2[$SizeDT][3]
$search = FileFindFirstFile(GetValue("PathDumpDB2",$aArray) & "*.001")
If $search = -1 Then
WriteLog("No files/directories matched the search pattern","logDumpIB.txt",1)
Exit
EndIf
$NS=0;
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$t=FileGetTime(GetValue("PathDumpDB2",$aArray) & $file, 1)
If Not @error Then
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
EndIf
$arrayDB2[$NS][0]=$yyyymd
$arrayDB2[$NS][1]=GetValue("PathDumpDB2",$aArray) & $file
if _DateToDayOfWeek ($t[0] , $t[1], $t[2]) =1 then
$arrayDB2[$NS][2]=True
Else
$arrayDB2[$NS][2]=false
EndIf
$NS=$NS+1
WEnd
FileClose($search)
;~ _ArrayDisplay($arrayDB2)
$FiveDayEarly=_DateAdd( 'd',-5,_NowCalcDate())
For $i = 0 to $SizeDT -1
$FileDelete=False
if $FiveDayEarly > $arrayDB2[$i][0] Then
$FileDelete=True
EndIf
if $FileDelete Then
WriteLog("Óäàëåí ñòàðûé áåêàï - " & $arrayDB2[$i][1],"logDumpIB.txt",1)
FileDelete($arrayDB2[$i][1])
EndIf
Next
EndFunc
Func DeleteOldDT($aArray)
;~ $SizeDT=GetCountFilesDT("C:\Temp\samara*.dt")
$SizeDT=GetCountFilesDT(GetValue("PathDump",$aArray) & GetValue("BaseName",$aArray) & "*.dt")
if $SizeDT <= GetValue("CountOfDT",$aArray) then
return 0
EndIf
Dim $arrayDT[$SizeDT][3]
$search = FileFindFirstFile(GetValue("PathDump",$aArray) & GetValue("BaseName",$aArray) & "*.dt")
If $search = -1 Then
WriteLog("No files/directories matched the search pattern","logDumpIB.txt",1)
Exit
EndIf
$NS=0;
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$t=FileGetTime(GetValue("PathDump",$aArray) & $file, 1)
If Not @error Then
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
EndIf
$arrayDT[$NS][0]=$yyyymd
$arrayDT[$NS][1]=GetValue("PathDump",$aArray) & $file
if _DateToDayOfWeek ($t[0] , $t[1], $t[2]) =1 then
$arrayDT[$NS][2]=True
Else
$arrayDT[$NS][2]=false
EndIf
$NS=$NS+1
WEnd
FileClose($search)
_ArraySort($arrayDT, 1 , 0, 0, 0)
$MaxKolvoVoskr=4
$NVoskr=0
$SevenDayEarly=_DateAdd( 'd',-7,_NowCalcDate())
For $i = 0 to $SizeDT -1
$FileDelete=False
if $SevenDayEarly > $arrayDT[$i][0] Then
;~ MsgBox(-1,"",StringRight($arrayDT[$i][0],2))
if StringRight($arrayDT[$i][0],2)<>"01" AND StringRight($arrayDT[$i][0],2)<>"02" then
if $arrayDT[$i][2] Then
$NVoskr=$NVoskr+1
If $NVoskr>4 Then
$FileDelete=True
EndIf
Else
$FileDelete=True
EndIf
EndIf
EndIf
if $FileDelete Then
WriteLog("Óäàëåí ñòàðûé áåêàï - " & $arrayDT[$i][1],"logDumpIB.txt",1)
FileDelete($arrayDT[$i][1])
EndIf
Next
EndFunc
Func GetCountFilesDT($StrSearch)
$CountOfDT=0;
$search = FileFindFirstFile($StrSearch)
If $search = -1 Then
;~ MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
;~ MsgBox(4096, "File:", $file)
$CountOfDT=$CountOfDT+1
WEnd
Return $CountOfDT
EndFunc
Func FtpUpload($NameFile,$aArray,$FolderFTP,$flDeleteFile)
;~ $server = '80.254.106.235'
$server = GetValue("FTP_IP",$aArray)
$username = "ftp_almaz"
$pass = "qw12ftp061"
$Open = _FTP_Open("almazFTP")
$Conn = _FTP_Connect($Open, $server, $username, $pass,1)
if $Conn=0 Then
WriteLog("Íå ïîëó÷èëîñü ïîäêëþ÷èòñÿ ê FTP.","logDumpIB.txt",1)
endIf
$CurrentDir="backup/"
if $FolderFTP = "\backup\DT\" then
$CurrentDir="backup/DT/"
EndIf
if _FTP_DirSetCurrent($Conn, $CurrentDir)=0 Then
WriteLog("Íå ïîëó÷èëîñü óñòàíîâèòü òåêóùèé êàòàëîã FTP.","logDumpIB.txt",1)
EndIf
$s_LocalFile=$Path & $NameFile
$s_RemoteFile=$FolderFTP & $NameFile
if _FTP_FilePut($Conn, $s_LocalFile, $s_RemoteFile) =0 Then
;~ MsgBox(-1,"",@ERROR)
if $FolderFTP = "\backup\DT\" then
$Ftpc = _FTP_Close($Open)
WriteLog("Íå óäàëîñü ñêîïèðîâàòü "& $NameFile &" íà FTP.","logDumpIB.txt",1)
Return False
EndIf
Else
WriteLog("Ñêîïèðîâàí " & $NameFile & " íà FTP.","logDumpIB.txt",1)
EndIf
$Ftpc = _FTP_Close($Open)
if $flDeleteFile then
FileDelete($Path & $NameFile)
endif
Return true
EndFunc