Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check creation time for database to sanity check if the incremental is valid #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions fd-plugins/bareos_percona/BareosFdPercona.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from BareosFdPluginBaseclass import *
import BareosFdWrapper
import time
import datetime
import tempfile
import shutil
import json
Expand All @@ -50,6 +51,13 @@ def __init__(self, context, plugindef):
self.max_to_lsn = 0
self.subprocess_stdOut = ''
self.subprocess_stdError = ''
self.MySQLdb = False
try:
import MySQLdb
self.MySQLdb = MySQLdb
bareosfd.DebugMessage(context, 100, "Imported module MySQLdb\n")
except ImportError:
bareosfd.DebugMessage(context, 100, "Import of module MySQLdb failed. Using command pipe instead\n")

def parse_plugin_definition(self, context, plugindef):
'''
Expand Down Expand Up @@ -168,18 +176,9 @@ def start_backup_job(self, context):
if self.max_to_lsn == 0:
JobMessage(context, bJobMessageType['M_FATAL'], "No LSN received to be used with incremental backup\n")
return bRCs['bRC_Error']
# Try to load MySQLdb module
hasMySQLdbModule = False
try:
import MySQLdb
hasMySQLdbModule = True
bareosfd.DebugMessage(context, 100, "Imported module MySQLdb\n")
except ImportError:
bareosfd.DebugMessage(context, 100, "Import of module MySQLdb failed. Using command pipe instead\n")
# contributed by https://github.com/kjetilho
if hasMySQLdbModule:
if self.MySQLdb:
try:
conn = MySQLdb.connect(**self.connect_options)
conn = self.MySQLdb.connect(**self.connect_options)
cursor = conn.cursor()
cursor.execute('SHOW ENGINE INNODB STATUS')
result = cursor.fetchall()
Expand Down Expand Up @@ -394,10 +393,31 @@ def restore_object_data(self, context, ROP):
# Improve: sanity / consistence check of restore object
self.row_rop_raw = ROP.object
self.rop_data[ROP.jobid] = json.loads(str(self.row_rop_raw))
if 'to_lsn' in self.rop_data[ROP.jobid] and self.rop_data[ROP.jobid]['to_lsn'] > self.max_to_lsn:
if (chr(self.level) in ('I', 'D')
and 'to_lsn' in self.rop_data[ROP.jobid]
and self.rop_data[ROP.jobid]['to_lsn'] > self.max_to_lsn):
self.max_to_lsn = int(self.rop_data[ROP.jobid]['to_lsn'])
JobMessage(context, bJobMessageType['M_INFO'],
"Got to_lsn %d from restore object of job %d\n" % (self.max_to_lsn, ROP.jobid))
if self.MySQLdb:
try:
conn = self.MySQLdb.connect(**self.connect_options)
cursor = conn.cursor()
# Look for age of oldest table as a canary for full wipe + reinit
cursor.execute("SELECT MIN(create_time) FROM information_schema.tables")
create_time = cursor.fetchall()[0][0]
conn.close()
except Exception, e:
JobMessage(context, bJobMessageType['M_FATAL'], "Could not get create time for database, Error: %s" % e)
return bRCs['bRC_Error']
job_time = datetime.datetime.utcfromtimestamp(self.since)
if create_time > job_time:
# It would be best to upgrade job, but it is not possible. Fail rather than store useless data.
JobMessage(context, bJobMessageType['M_FATAL'],
"Database was created at %s which is after time of previous backup (%s). Schedule a new Full backup."
% (create_time, job_time))
return bRCs['bRC_Error']

return bRCs['bRC_OK']


Expand Down