2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 01:22:00 +00:00

Allow restore to replace unsupported format

Going from python 2 to python 3, the dbm format
goes from the default to unsupported.

This allows a python3 confluentdbutil restore to handle
a python2 dump of unsupported format.
This commit is contained in:
Jarrod Johnson 2022-06-09 15:49:06 -04:00
parent 44cf56857e
commit 6f484aab53
2 changed files with 33 additions and 5 deletions

View File

@ -69,7 +69,10 @@ if args[0] == 'restore':
if options.interactivepassword:
password = getpass.getpass('Enter password to restore backup: ')
try:
cfm.statelessmode = True
cfm.restore_db_from_directory(dumpdir, password)
cfm.statelessmode = False
cfm.ConfigManager.wait_for_sync(True)
if owner != 0:
for targdir in os.walk('/etc/confluent'):
os.chown(targdir[0], owner, group)

View File

@ -2604,7 +2604,13 @@ class ConfigManager(object):
with _dirtylock:
dirtyglobals = copy.deepcopy(_cfgstore['dirtyglobals'])
del _cfgstore['dirtyglobals']
globalf = dbm.open(os.path.join(cls._cfgdir, "globals"), 'c', 384) # 0600
try:
globalf = dbm.open(os.path.join(cls._cfgdir, "globals"), 'c', 384) # 0600
except dbm.error:
if not fullsync:
raise
os.remove(os.path.join(cls._cfgdir, "globals"))
globalf = dbm.open(os.path.join(cls._cfgdir, "globals"), 'c', 384) # 0600
try:
for globalkey in dirtyglobals:
if globalkey in _cfgstore['globals']:
@ -2617,8 +2623,15 @@ class ConfigManager(object):
globalf.close()
if fullsync or 'collectivedirty' in _cfgstore:
if len(_cfgstore.get('collective', ())) > 1:
collectivef = dbm.open(os.path.join(cls._cfgdir, "collective"),
'c', 384)
try:
collectivef = dbm.open(os.path.join(cls._cfgdir, 'collective'),
'c', 384)
except dbm.error:
if not fullsync:
raise
os.remove(os.path.join(cls._cfgdir, 'collective'))
collectivef = dbm.open(os.path.join(cls._cfgdir, 'collective'),
'c', 384)
try:
if fullsync:
colls = _cfgstore['collective']
@ -2645,7 +2658,13 @@ class ConfigManager(object):
currdict = _cfgstore['main']
for category in currdict:
_mkpath(pathname)
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
try:
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
except dbm.error:
if not fullsync:
raise
os.remove(os.path.join(pathname, category))
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
try:
for ck in currdict[category]:
dbf[ck] = cPickle.dumps(currdict[category][ck], protocol=cPickle.HIGHEST_PROTOCOL)
@ -2665,7 +2684,13 @@ class ConfigManager(object):
currdict = _cfgstore['tenant'][tenant]
for category in dkdict:
_mkpath(pathname)
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
try:
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
except dbm.error:
if not fullsync:
raise
os.remove(os.path.join(pathname, category))
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
try:
for ck in dkdict[category]:
if ck not in currdict[category]: