init to comit it

This commit is contained in:
Joe S 2020-08-18 15:17:49 -04:00
parent 9872c016d5
commit 15d566f1c9
10 changed files with 222 additions and 80 deletions

View File

@ -2,7 +2,10 @@
# This script written by joe
# This will inject "release" into bconsole
echo release storage=Iron-Autochanger slot=0 | bconsole
echo release storage=Drive-0-LTO-3 drive=0 slot=0 | bconsole
#echo release storage=Drive-0-LTO-3 | bconsole
# Release slot 1 too
echo release storage=Iron-Autochanger slot=1 | bconsole
echo release storage=Drive-1-LTO-3 drive=1 slot=0 | bconsole
#echo release storage=Drive-1-LTO-3 | bconsole

View File

@ -1,24 +1,12 @@
from discord_webhook import DiscordWebhook, DiscordEmbed
from mextract import mextract
from discord_webhook import DiscordWebhook
from bathook import bathook
webhookURL = "https://discordapp.com/api/webhooks/742784012640190565/NBhtbWpDdgMZPx7uCXO8Ofw-o8Lez0V17EBGIvYv7FTIeTENK24GHNL3krUbYnOOIJ63"
maxCharPerMessage = 1994
with open ("/etc/bacula/scripts/webhooks/ChrisProEliteMail.md", "r") as myfile:
cleaned_stdout=myfile.read()
bathook = bathook("/etc/bacula/scripts/webhooks/ChrisProEliteMail.md", "nextcloud")
if "Termination: Backup OK" in cleaned_stdout:
truncated_stdout = ["""Job Backup-Chris completed with status Backup OK, omitting full report.
All data from nextcloud was successfully written to tape on """ + mextract(cleaned_stdout, "End time:") + """.
Backup took """ + mextract(cleaned_stdout, "Elapsed time:") + " And used " + mextract(cleaned_stdout, "SD Bytes Written:") + " bytes."]
else:
# Discord limits each message to 2000 chars, if the message is longer than that, truncate it
truncated_stdout = [cleaned_stdout[i:i+maxCharPerMessage] for i in range(0, len(cleaned_stdout), maxCharPerMessage)]
print (truncated_stdout) # Print the truncated message
for message_part in truncated_stdout: # For every message part in the truncated output, run this loop
for message_part in bathook.get_formatted_message(): # For every message part in the truncated output, run this loop
message_part = "```" + message_part + "```" # Encapsulate the messsage
print(message_part)
webhook = DiscordWebhook(url=webhookURL, content=message_part) # Attach the message

View File

@ -1,28 +1,23 @@
11-Aug 12:41 bacula-dir JobId 310: Start Backup JobId 310, Job=Backup-Chris.2020-08-11_12.41.09_06
11-Aug 12:41 bacula-dir JobId 310: Using Device "Drive-1-LTO-3" to write.
11-Aug 12:41 bacula-iron-sd JobId 310: 3304 Issuing autochanger "load Volume PF6866, Slot 7, Drive 1" command.
11-Aug 12:41 bacula-iron-sd JobId 310: 3305 Autochanger "load Volume PF6866, Slot 7, Drive 1", status is OK.
11-Aug 12:41 bacula-iron-sd JobId 310: Volume "PF6866" previously written, moving to end of data.
11-Aug 12:42 bacula-iron-sd JobId 310: Ready to append to end of Volume "PF6866" at file=76.
11-Aug 12:42 bacula-iron-sd JobId 310: Spooling data ...
11-Aug 12:42 bacula-iron-sd JobId 310: Committing spooled data to Volume "PF6866". Despooling 430 bytes ...
11-Aug 12:42 bacula-iron-sd JobId 310: Despooling elapsed time = 00:00:01, Transfer rate = 430 Bytes/second
11-Aug 12:42 bacula-iron-sd JobId 310: Elapsed time=00:00:01, Transfer rate=0 Bytes/second
11-Aug 12:43 bacula-iron-sd JobId 310: Sending spooled attrs to the Director. Despooling 0 bytes ...
11-Aug 12:43 bacula-dir JobId 310: Bacula bacula-dir 9.4.2 (04Feb19):
18-Aug 02:18 bacula-dir JobId 336: Start Backup JobId 336, Job=Backup-Chris.2020-08-18_02.15.00_53
18-Aug 02:18 bacula-dir JobId 336: Using Device "Drive-1-LTO-3" to write.
18-Aug 02:18 bacula-dir JobId 336: Warning: bsockcore.c:201 Could not connect to Client: Zinc-Client on 10.85.3.31:9102. ERR=No route to host
Retrying ...
18-Aug 02:21 bacula-dir JobId 336: Fatal error: bsockcore.c:208 Unable to connect to Client: Zinc-Client on 10.85.3.31:9102. ERR=No route to host
18-Aug 02:21 bacula-dir JobId 336: Fatal error: No Job status returned from FD.
18-Aug 02:21 bacula-dir JobId 336: Error: Bacula bacula-dir 9.4.2 (04Feb19):
Build OS: x86_64-pc-linux-gnu ubuntu 20.04
JobId: 310
Job: Backup-Chris.2020-08-11_12.41.09_06
Backup Level: Incremental, since=2020-08-11 02:29:34
JobId: 336
Job: Backup-Chris.2020-08-18_02.15.00_53
Backup Level: Incremental, since=2020-08-11 19:47:58
Client: "Zinc-Client" 9.6.3 (09Mar20) amd64-portbld-freebsd11.3,freebsd,11.3-RELEASE-p8
FileSet: "Chris Backup" 2020-06-23 16:46:12
Pool: "Incr-Pool" (From Job IncPool override)
Catalog: "MyCatalog" (From Client resource)
Storage: "Iron-Autochanger" (From Pool resource)
Scheduled time: 11-Aug-2020 12:41:08
Start time: 11-Aug-2020 12:41:12
End time: 11-Aug-2020 12:43:00
Elapsed time: 1 min 48 secs
Scheduled time: 18-Aug-2020 02:15:00
Start time: 18-Aug-2020 02:18:28
End time: 18-Aug-2020 02:21:28
Elapsed time: 3 mins
Priority: 10
FD Files Written: 0
SD Files Written: 0
@ -35,18 +30,62 @@
Encryption: no
Accurate: no
Volume name(s):
Volume Session Id: 13
Volume Session Time: 1596908811
Last Volume Bytes: 239,752,719,360 (239.7 GB)
Volume Session Id: 6
Volume Session Time: 1597371611
Last Volume Bytes: 3,964,391,424 (3.964 GB)
Non-fatal FD errors: 1
SD Errors: 0
FD termination status: Error
SD termination status: Waiting on FD
Termination: *** Backup Error ***
18-Aug 02:21 bacula-dir JobId 336: Rescheduled Job Backup-Chris.2020-08-18_02.15.00_53 at 18-Aug-2020 02:21 to re-run in 43200 seconds (18-Aug-2020 14:21).
18-Aug 02:21 bacula-dir JobId 336: Job Backup-Chris.2020-08-18_02.15.00_53 waiting 43200 seconds for scheduled start time.
18-Aug 14:24 bacula-dir JobId 336: Start Backup JobId 336, Job=Backup-Chris.2020-08-18_02.15.00_53
18-Aug 14:24 bacula-dir JobId 336: Using Device "Drive-1-LTO-3" to write.
18-Aug 14:24 bacula-iron-sd JobId 336: Spooling data ...
18-Aug 14:27 bacula-iron-sd JobId 336: Committing spooled data to Volume "A02106". Despooling 1,512,476,808 bytes ...
18-Aug 14:27 bacula-iron-sd JobId 336: Despooling elapsed time = 00:00:20, Transfer rate = 75.62 M Bytes/second
18-Aug 14:27 bacula-iron-sd JobId 336: Elapsed time=00:03:19, Transfer rate=7.591 M Bytes/second
18-Aug 14:27 bacula-iron-sd JobId 336: Sending spooled attrs to the Director. Despooling 800,805 bytes ...
18-Aug 14:27 bacula-dir JobId 336: Bacula bacula-dir 9.4.2 (04Feb19):
Build OS: x86_64-pc-linux-gnu ubuntu 20.04
JobId: 336
Job: Backup-Chris.2020-08-18_02.15.00_53
Backup Level: Incremental, since=2020-08-11 19:47:58
Client: "Zinc-Client" 9.6.3 (09Mar20) amd64-portbld-freebsd11.3,freebsd,11.3-RELEASE-p8
FileSet: "Chris Backup" 2020-06-23 16:46:12
Pool: "Incr-Pool" (From Job IncPool override)
Catalog: "MyCatalog" (From Client resource)
Storage: "Iron-Autochanger" (From Pool resource)
Scheduled time: 18-Aug-2020 02:15:00
Start time: 18-Aug-2020 14:24:28
End time: 18-Aug-2020 14:27:49
Elapsed time: 3 mins 21 secs
Priority: 10
FD Files Written: 2,796
SD Files Written: 2,796
FD Bytes Written: 1,510,187,829 (1.510 GB)
SD Bytes Written: 1,510,687,298 (1.510 GB)
Rate: 7513.4 KB/s
Software Compression: 52.0% 2.1:1
Comm Line Compression: None
Snapshot/VSS: no
Encryption: no
Accurate: no
Volume name(s): A02106
Volume Session Id: 14
Volume Session Time: 1597371611
Last Volume Bytes: 6,785,823,744 (6.785 GB)
Non-fatal FD errors: 0
SD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Backup OK
11-Aug 12:43 bacula-dir JobId 310: Begin pruning Jobs older than 30 years .
11-Aug 12:43 bacula-dir JobId 310: No Jobs found to prune.
11-Aug 12:43 bacula-dir JobId 310: Begin pruning Files.
11-Aug 12:43 bacula-dir JobId 310: No Files found to prune.
11-Aug 12:43 bacula-dir JobId 310: End auto prune.
18-Aug 14:27 bacula-dir JobId 336: Begin pruning Jobs older than 30 years .
18-Aug 14:27 bacula-dir JobId 336: No Jobs found to prune.
18-Aug 14:27 bacula-dir JobId 336: Begin pruning Files.
18-Aug 14:27 bacula-dir JobId 336: No Files found to prune.
18-Aug 14:27 bacula-dir JobId 336: End auto prune.

View File

@ -3,14 +3,26 @@ from mextract import mextract
webhookURL = "https://discordapp.com/api/webhooks/740630755259973713/CNhxPBJ4C6UZ-m1DVXUQ54KeJQD3I9Di0sAwldmyjw-s7dMPUWplq7rhGXegpWGtKSve"
maxCharPerMessage = 1994
rescheduled = ""
with open ("/etc/bacula/scripts/webhooks/RoboticsMail.md", "r") as myfile:
cleaned_stdout=myfile.read()
if "Termination: Backup OK" in cleaned_stdout:
if "Rescheduled" in cleaned_stdout: # If the job was rescheduled
cleaned_stdout = cleaned_stdout.split("Rescheduled", 1)[-1] # Remove the failed data
rescheduled = "\nJob was rescheduled at least once."
endtime = mextract(cleaned_stdout, "End time:")
elapsedtime = mextract(cleaned_stdout, "Elapsed time:")
byteswritten = mextract(cleaned_stdout, "SD Bytes Written:")
usedvolumes = mextract(cleaned_stdout, "Volume name\(s\):")
if "Backup OK" in cleaned_stdout and "Backup OK -- with warnings" not in cleaned_stdout:
truncated_stdout = ["""Job Backup-Robotics completed with status Backup OK, omitting full report.
All data from 1721's google drive was successfully written to tape on """ + mextract(cleaned_stdout, "End time:") + """.
Backup took """ + mextract(cleaned_stdout, "Elapsed time:") + " And used " + mextract(cleaned_stdout, "SD Bytes Written:") + " bytes."]
All data from 1721's google drive was successfully written to tape on """ + endtime + """.
Backup took """ + elapsedtime + " And used " + byteswritten + " bytes."]
if len(usedvolumes) > 1:
truncated_stdout[0] = truncated_stdout[0] + ("\nWrote data to volume(s) " + usedvolumes + rescheduled)
else:
# Discord limits each message to 2000 chars, if the message is longer than that, truncate it
truncated_stdout = [cleaned_stdout[i:i+maxCharPerMessage] for i in range(0, len(cleaned_stdout), maxCharPerMessage)]

View File

@ -1,48 +1,90 @@
11-Aug 02:56 bacula-dir JobId 308: Start Backup JobId 308, Job=Backup-Robotics.2020-08-11_02.15.00_10
11-Aug 02:56 bacula-dir JobId 308: Using Device "Drive-1-LTO-3" to write.
11-Aug 02:56 bacula-iron-sd JobId 308: Spooling data ...
11-Aug 02:56 bacula-iron-sd JobId 308: Committing spooled data to Volume "PF6866". Despooling 788,279,412 bytes ...
11-Aug 02:56 bacula-iron-sd JobId 308: Despooling elapsed time = 00:00:12, Transfer rate = 65.68 M Bytes/second
11-Aug 02:56 bacula-iron-sd JobId 308: Elapsed time=00:00:27, Transfer rate=29.16 M Bytes/second
11-Aug 02:56 bacula-iron-sd JobId 308: Sending spooled attrs to the Director. Despooling 24,152 bytes ...
11-Aug 02:56 bacula-dir JobId 308: Bacula bacula-dir 9.4.2 (04Feb19):
18-Aug 02:21 bacula-dir JobId 339: Start Backup JobId 339, Job=Backup-Robotics.2020-08-18_02.15.00_56
18-Aug 02:21 bacula-dir JobId 339: Using Device "Drive-1-LTO-3" to write.
18-Aug 02:21 bacula-dir JobId 339: Warning: bsockcore.c:201 Could not connect to Client: Zinc-Client on 10.85.3.31:9102. ERR=No route to host
Retrying ...
18-Aug 02:24 bacula-dir JobId 339: Fatal error: bsockcore.c:208 Unable to connect to Client: Zinc-Client on 10.85.3.31:9102. ERR=No route to host
18-Aug 02:24 bacula-dir JobId 339: Fatal error: No Job status returned from FD.
18-Aug 02:24 bacula-dir JobId 339: Error: Bacula bacula-dir 9.4.2 (04Feb19):
Build OS: x86_64-pc-linux-gnu ubuntu 20.04
JobId: 308
Job: Backup-Robotics.2020-08-11_02.15.00_10
Backup Level: Incremental, since=2020-08-07 15:31:45
JobId: 339
Job: Backup-Robotics.2020-08-18_02.15.00_56
Backup Level: Incremental, since=2020-08-11 02:56:27
Client: "Zinc-Client" 9.6.3 (09Mar20) amd64-portbld-freebsd11.3,freebsd,11.3-RELEASE-p8
FileSet: "Google-Drive Robotics" 2020-08-05 15:36:42
Pool: "Incr-Pool" (From Job IncPool override)
Catalog: "MyCatalog" (From Client resource)
Storage: "Iron-Autochanger" (From Pool resource)
Scheduled time: 11-Aug-2020 02:15:00
Start time: 11-Aug-2020 02:56:27
End time: 11-Aug-2020 02:56:55
Elapsed time: 28 secs
Scheduled time: 18-Aug-2020 02:15:00
Start time: 18-Aug-2020 02:21:28
End time: 18-Aug-2020 02:24:28
Elapsed time: 3 mins
Priority: 10
FD Files Written: 98
SD Files Written: 98
FD Bytes Written: 787,531,312 (787.5 MB)
SD Bytes Written: 787,545,944 (787.5 MB)
Rate: 28126.1 KB/s
FD Files Written: 0
SD Files Written: 0
FD Bytes Written: 0 (0 B)
SD Bytes Written: 0 (0 B)
Rate: 0.0 KB/s
Software Compression: None
Comm Line Compression: 1.2% 1.0:1
Comm Line Compression: None
Snapshot/VSS: no
Encryption: no
Accurate: no
Volume name(s): PF6866
Volume Session Id: 12
Volume Session Time: 1596908811
Last Volume Bytes: 239,752,654,848 (239.7 GB)
Volume name(s):
Volume Session Id: 9
Volume Session Time: 1597371611
Last Volume Bytes: 3,964,391,424 (3.964 GB)
Non-fatal FD errors: 1
SD Errors: 0
FD termination status: Error
SD termination status: Waiting on FD
Termination: *** Backup Error ***
18-Aug 02:24 bacula-dir JobId 339: Rescheduled Job Backup-Robotics.2020-08-18_02.15.00_56 at 18-Aug-2020 02:24 to re-run in 43200 seconds (18-Aug-2020 14:24).
18-Aug 02:24 bacula-dir JobId 339: Job Backup-Robotics.2020-08-18_02.15.00_56 waiting 43200 seconds for scheduled start time.
18-Aug 14:25 bacula-dir JobId 339: Start Backup JobId 339, Job=Backup-Robotics.2020-08-18_02.15.00_56
18-Aug 14:25 bacula-dir JobId 339: Using Device "Drive-1-LTO-3" to write.
18-Aug 14:25 bacula-iron-sd JobId 339: Spooling data ...
18-Aug 14:25 bacula-iron-sd JobId 339: Committing spooled data to Volume "A02106". Despooling 9,155 bytes ...
18-Aug 14:25 bacula-iron-sd JobId 339: Despooling elapsed time = 00:00:01, Transfer rate = 9.155 K Bytes/second
18-Aug 14:25 bacula-iron-sd JobId 339: Elapsed time=00:00:09, Transfer rate=960 Bytes/second
18-Aug 14:25 bacula-iron-sd JobId 339: Sending spooled attrs to the Director. Despooling 419 bytes ...
18-Aug 14:25 bacula-dir JobId 339: Bacula bacula-dir 9.4.2 (04Feb19):
Build OS: x86_64-pc-linux-gnu ubuntu 20.04
JobId: 339
Job: Backup-Robotics.2020-08-18_02.15.00_56
Backup Level: Incremental, since=2020-08-11 02:56:27
Client: "Zinc-Client" 9.6.3 (09Mar20) amd64-portbld-freebsd11.3,freebsd,11.3-RELEASE-p8
FileSet: "Google-Drive Robotics" 2020-08-05 15:36:42
Pool: "Incr-Pool" (From Job IncPool override)
Catalog: "MyCatalog" (From Client resource)
Storage: "Iron-Autochanger" (From Pool resource)
Scheduled time: 18-Aug-2020 02:15:00
Start time: 18-Aug-2020 14:25:49
End time: 18-Aug-2020 14:25:58
Elapsed time: 9 secs
Priority: 10
FD Files Written: 2
SD Files Written: 2
FD Bytes Written: 8,396 (8.396 KB)
SD Bytes Written: 8,647 (8.647 KB)
Rate: 0.9 KB/s
Software Compression: None
Comm Line Compression: 7.1% 1.1:1
Snapshot/VSS: no
Encryption: no
Accurate: no
Volume name(s): A02106
Volume Session Id: 17
Volume Session Time: 1597371611
Last Volume Bytes: 5,273,597,952 (5.273 GB)
Non-fatal FD errors: 0
SD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Backup OK
11-Aug 02:56 bacula-dir JobId 308: Begin pruning Jobs older than 30 years .
11-Aug 02:56 bacula-dir JobId 308: No Jobs found to prune.
11-Aug 02:56 bacula-dir JobId 308: Begin pruning Files.
11-Aug 02:56 bacula-dir JobId 308: No Files found to prune.
11-Aug 02:56 bacula-dir JobId 308: End auto prune.
18-Aug 14:25 bacula-dir JobId 339: Begin pruning Jobs older than 30 years .
18-Aug 14:25 bacula-dir JobId 339: No Jobs found to prune.
18-Aug 14:25 bacula-dir JobId 339: Begin pruning Files.
18-Aug 14:25 bacula-dir JobId 339: No Files found to prune.
18-Aug 14:25 bacula-dir JobId 339: End auto prune.

View File

@ -0,0 +1,43 @@
import re
class bathook:
def __init__(self, path_to_report, data_from):
with open (path_to_report, "r") as messagesfile: # Open the file
self.raw_messages = messagesfile.read() # Extract the data
if "Rescheduled" in self.raw_messages: # If the job was rescheduled
self.raw_messages = self.raw_messages.split("Rescheduled", 1)[-1] # Remove the failed data
self.rescheduled = "\nJob was rescheduled at least once." # We rescheduled
else:
self.rescheduled = "" # We did not reschedule
self.endtime = self.mextract(self.raw_messages, "End time:")
self.elapsedtime = self.mextract(self.raw_messages, "Elapsed time:")
self.byteswritten = self.mextract(self.raw_messages, "SD Bytes Written:")
self.usedvolumes = self.mextract(self.raw_messages, "Volume name\(s\):")
self.jobname = self.mextract(self.raw_messages, "Job:")
self.jobid = self.mextract(self.raw_messages, "JobId:")
self.data_from = data_from
self.maxCharPerMessage = 1994
def mextract(self, report, variable):
try:
result = re.search(variable + '(.*)', report)
print(result)
return(result.group(1).lstrip()) # lstrip removes leading spaces.
except:
return("[Variable Not found]")
def get_formatted_message(self):
if "Backup OK" in self.raw_messages and "Backup OK -- with warnings" not in self.raw_messages:
truncated_stdout = ["""Job {0} (Job {1}) completed with status Backup OK, omitting full report.
All data from {2} was successfully written to tape on {3}.
Backup took {4} And used {5} bytes.""".format(self.jobname, self.jobid, self.data_from, self.endtime, self.elapsedtime, self.byteswritten)]
if len(self.usedvolumes) > 1:
truncated_stdout[0] = truncated_stdout[0] + ("\nWrote data to volume(s) {0} {1}".format(self.usedvolumes, self.rescheduled))
else:
# Discord limits each message to 2000 chars, if the message is longer than that, truncate it
truncated_stdout = [cleaned_stdout[i:i+self.maxCharPerMessage] for i in range(0, len(cleaned_stdout), self.maxCharPerMessage)]
return(truncated_stdout)

View File

@ -3,7 +3,8 @@ import re
def mextract(report, variable):
try:
result = re.search(variable + '(.*)\n', report)
result = re.search(variable + '(.*)', report)
print(result)
return(result.group(1).lstrip()) # lstrip removes leading spaces.
except:
return("[Variable Not found]")

View File

@ -0,0 +1,14 @@
from discord_webhook import DiscordWebhook
from bathook import bathook
webhookURL = "https://discordapp.com/api/webhooks/742784012640190565/NBhtbWpDdgMZPx7uCXO8Ofw-o8Lez0V17EBGIvYv7FTIeTENK24GHNL3krUbYnOOIJ63"
maxCharPerMessage = 1994
rescheduled = ""
bathook = bathook("/etc/bacula/scripts/webhooks/ChrisProEliteMail.md", "nextcloud")
for message_part in bathook.get_formatted_message(): # For every message part in the truncated output, run this loop
message_part = "```" + message_part + "```" # Encapsulate the messsage
print(message_part)
webhook = DiscordWebhook(url=webhookURL, content=message_part) # Attach the message
response = webhook.execute() # Hit send