Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti

[es] :: Visual Basic 6 :: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti

[ Pregleda: 3165 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

polke
Beograd

Član broj: 12230
Poruke: 83
*.dhl.com.



+9 Profil

icon VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti11.04.2008. u 10:26 - pre 194 meseci
Pozdrav,

Uspeo sam da nadjem jednu skriptu koja mi bekapuje i brise Security, Application i System logove.
Potrebno mi je da uradim sledece:

-da se napravi folder sa datumom u formatu yyyyMMdd
-da se fajlovi prekopiraju tamo.

Evo je skripta koju imam:

Code:


strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate,(Security,Backup)}!\\" & _
 strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Application'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog("c:\mesar\AppEvent.Evt")
 If errBackupLog <> 0 Then
 Wscript.Echo "The Application event log could not be backed up."
 Else
 objLogFile.ClearEventLog()
 End If
Next

Set colLogFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog("c:\mesar\SecEvent.Evt")
 If errBackupLog <> 0 Then
 Wscript.Echo "The Security event log could not be backed up."
 Else
 objLogFile.ClearEventLog()
 End If
Next

Set colLogFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='System'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog("c:\mesar\SysEvent.Evt")
 If errBackupLog <> 0 Then
 Wscript.Echo "The System event log could not be backed up."
 Else
 objLogFile.ClearEventLog()
 End If
Next



Trenutno mi cuva logove u folderu c:\mesar.

Napravio bih batch file u kome bih stavio md %date% , ali problem je u formatu datuma koji ima "/" separator i to ne radi tako.

Posto nikad nisam programirao, a ovo mi izgleda vrlo zanimljivo, molio bih za pomoc.


Maximalno!
 
Odgovor na temu

Eurora3D Team
Nebojsa - Programer & Vodja tima
Beograd

Član broj: 120376
Poruke: 900
91.148.113.*



+7 Profil

icon Re: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti11.04.2008. u 12:18 - pre 194 meseci
Ovako mozes da napravis folder sa danasnjim datumom (prvih nekoliko redova)
(by the way :) hvala za kod ... ni ja nisam znao kako se ocitavaju ti logovi iz VB Scripta)
Code:

' backup.vbs
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim sDay,sMonth,sYear,sDir
sDay = Day(Now)
sMonth = Month(Now)
sYear = Year(Now)
sDir = "C:\" & sYear & "." & sMonth & "." & sDay
'
'sDir = "C:\" & sYear &  sMonth & sDay

Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder(sDir)

Dim sApp,sSec,sSys
aApp = sDir & "\AppEvent.Evt"
sSec = sDir & "\SecEvent.Evt"
sSys = sDir & "\SysEvent.Evt"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate,(Security,Backup)}!\\" & _
 strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Application'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog(aApp) ' <-
 If errBackupLog <> 0 Then
 Wscript.Echo "The Application event log could not be backed up."
 Else
 objLogFile.ClearEventLog()
 End If
Next

Set colLogFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog(sSec) ' <-
 If errBackupLog <> 0 Then
 Wscript.Echo "The Security event log could not be backed up."
 Else
 objLogFile.ClearEventLog()
 End If
Next

Set colLogFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='System'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog(sSys) ' <-
 If errBackupLog <> 0 Then
 Wscript.Echo "The System event log could not be backed up."
 Else
 objLogFile.ClearEventLog()
 End If
Next

 
Odgovor na temu

polke
Beograd

Član broj: 12230
Poruke: 83
*.dhl.com.



+9 Profil

icon Re: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti11.04.2008. u 12:41 - pre 194 meseci
Odlicno, to je ono sto mi treba! Hvala.


Imam jos jedno pitanje: postoji li mogucnost centralizovanog pokretanja ovakve skripte, znaci da ne moram da pristupam svakom serveru posebno nego da sa jednog pokrenem skriptu i da iz nekog txt fajla procita ip adrese ili imena servera na kojima treba da obavi ovu fju?



[Ovu poruku je menjao polke dana 11.04.2008. u 14:12 GMT+1]
Maximalno!
 
Odgovor na temu

Eurora3D Team
Nebojsa - Programer & Vodja tima
Beograd

Član broj: 120376
Poruke: 900
91.148.113.*



+7 Profil

icon Re: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti11.04.2008. u 14:28 - pre 194 meseci
Imas windows shaduler ... nista drugo mi ne pada na pamet.
Mozda ce jos neko da ti da neku ideju ....

 
Odgovor na temu

stefanpn
Total anonymous
Programer

Član broj: 172809
Poruke: 509
212.200.207.*



+1 Profil

icon Re: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti11.04.2008. u 14:32 - pre 194 meseci
Mozes i da koristis nesto kao VNC Tool ili RADMIN.
 
Odgovor na temu

polke
Beograd

Član broj: 12230
Poruke: 83
*.dhl.com.



+9 Profil

icon Re: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti11.04.2008. u 15:34 - pre 194 meseci
Task Scheduler je opet ono sto mi treba :)
A ja sam krenuo onom domacom: Zasto lako kad moze komplikovano....

Nasao sam ovu skriptu, ali mi ne ide da je upotrebim, tako da cu to preskociti za sada.

Code:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: 
'
' AUTHOR: Jeffery Hicks , SAPIEN Technologies
' DATE  : 11/19/2007
'
' COMMENT: 
'
'==========================================================================
On Error Resume Next
Dim strDate

centralDumpPath = "\\rsbegws10010508\Logs\"
RemoteDumpPath = "C:\Temp\"

'build an array of logs to be backed up
arrLogs=Array("Application","BAD","System","Security")

'Create a FileSystemObject
Set oFS = CreateObject("Scripting.FileSystemObject")

'Open a text file of computer names ON LOCAL MACHINE WHERE SCRIPT'S RUNNING
'with one computer name per line
Set oTS = oFS.OpenTextFile("C:\test\servers.txt")

'Read entire file into memory

arrComputers=Split(Trim(oTS.ReadAll),VbCrLf)

'close the input file
oTS.Close

'go through array of computer names
For Each sComputer In arrComputers

  if Len(sComputer)>0 Then 'skip any blank lines
  
      For Each strLog In arrLogs
      
          strDate = CStr(Date())
          strDate = Replace(strDate, "/", "-")
          
          'dump file on each remote machine
          remoteDumpFile =  UCase(sComputer) &_
           "-" & strLog & "-" & strDate & ".evt"   
           
          rc=BackupLog(strLog,remoteDumpPath & remoteDumpFile,sComputer)
              If rc(0)=0 Then
                'successful backup and clear so copy file to central share
               strSource="\\" & sComputer & "\" & Replace(remoteDumpPath &_
                remoteDumpFile, "C:", "C$")
               strDestination=centralDumpPath & sComputer &_
                "\" & remoteDumpFile
               MoveFile strSource,strDestination
              
              Else
                 'There was an error
               Wscript.Echo "Couldn't get log " & strLog & " from " & sComputer &_
                ".  Error code: " & rc(0) & " " & rc(1)
              End If
      Next
    End If
Next

WScript.Quit 'end of main script

Function BackupLog(sLog,sFile,sComputer)
On Error Resume Next
'strLog is the name of the event log file to backup
'strFile is the name of the backup file to create. The
'filename and path must be relative to the server you
'are backing up
'strComputer is the name of the remote computer

'The function returns an array. Element 0 is an error number
'and element 1 is a description or message

Set oFS = CreateObject("Scripting.FileSystemObject")
'delete event backup if it still exists, otherwise backup 
'method will fail

If oFS.FileExists(sFile) Then oFS.DeleteFile sFile,True

 Set oWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate,(Security,Backup)}!\\" & _
 sComputer & "\root\cimv2")
 
 'query the Security logs
 Set cLogFiles = oWMIService.ExecQuery _
 ("Select * from Win32_NTEventLogFile where " & _
 "LogFileName='" & sLog & "'")
 

If cLogFiles.Count =0 Then
    BackupLog=Array("-1","Nothing to backup for event log " & sLog)
    Exit Function
End If

 'go through the collection of logs

 For Each oLogfile in cLogFiles

  'back up the log to a file LOCAL ON THAT REMOTE MACHINE
   WScript.Echo "Creating " & sFile

    oLogFile.BackupEventLog(sFile)
   
  If Err.number=0 Then
    BackupLog=Array(0,"Successfully backed up " & sLog & " to " & sFile)
 
   'no error - safe to clear the Log
    WScript.Echo "Clearing event log " & strLog & " on " & sComputer
    
    'Uncomment the next line to actually clear the log. I have it 
    'commented out for test purposes
   'oLogFile.ClearEventLog()
  Else
  
    BackupLog=Array(Err.Number,Err.Description)
   
  End If
Next

End Function

Function MoveFile(strSource,strDestination)
On Error Resume Next

Set oFS = CreateObject("Scripting.FileSystemObject")

strParentFolder = oFS.GetParentFolderName(strDestination)

   If oFS.FolderExists(strParentFolder)=False Then
    WScript.Echo "Creating " & strParentFolder
    oFS.CreateFolder strParentFolder
        If Err.Number<>0 Then
            WScript.Echo "Failed to create " & strParentFolder
            Exit Function
        End If
   End If
   
     WScript.Echo "Copying " & strSource & " to " & strDestination
    'Any existing files with same name will be overwritten
    oFS.CopyFile strSource,strDestination,True
    'if successful copy then delete source file
    If Err.Number=0 Then oFS.DeleteFile strSource

End Function


Hvala puno na pomoci!

Pozdrav

Maximalno!
 
Odgovor na temu

[es] :: Visual Basic 6 :: VBScript - Pravljenje Foldera u formatu yyyyMMdd i bekapovanje event logova u isti

[ Pregleda: 3165 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.