Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backupEventLog.py 1.2KB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Generate a base file name
  2. import os
  3. import time
  4. import win32api
  5. import win32evtlog
  6. def BackupClearLog(logType):
  7. datePrefix = time.strftime("%Y%m%d", time.localtime(time.time()))
  8. fileExists = 1
  9. retry = 0
  10. while fileExists:
  11. if retry == 0:
  12. index = ""
  13. else:
  14. index = "-%d" % retry
  15. try:
  16. fname = os.path.join(
  17. win32api.GetTempPath(),
  18. "%s%s-%s" % (datePrefix, index, logType) + ".evt",
  19. )
  20. os.stat(fname)
  21. except os.error:
  22. fileExists = 0
  23. retry = retry + 1
  24. # OK - have unique file name.
  25. try:
  26. hlog = win32evtlog.OpenEventLog(None, logType)
  27. except win32evtlogutil.error as details:
  28. print("Could not open the event log", details)
  29. return
  30. try:
  31. if win32evtlog.GetNumberOfEventLogRecords(hlog) == 0:
  32. print("No records in event log %s - not backed up" % logType)
  33. return
  34. win32evtlog.ClearEventLog(hlog, fname)
  35. print("Backed up %s log to %s" % (logType, fname))
  36. finally:
  37. win32evtlog.CloseEventLog(hlog)
  38. if __name__ == "__main__":
  39. BackupClearLog("Application")
  40. BackupClearLog("System")
  41. BackupClearLog("Security")