Created
May 27, 2023 04:44
-
-
Save samicrusader/e8afd0896c3d1a45d10c3069cdd8428d to your computer and use it in GitHub Desktop.
Proxmox Virtual Environment config.db dump utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import sqlite3 | |
import sys | |
try: | |
os.mkdir('config_restore') | |
except: | |
pass | |
db = sqlite3.connect('config.db') | |
cur = db.cursor() | |
fs = cur.execute('select inode, parent, type, name, data from tree').fetchall() | |
# (0, 0, 8, '__version__', None) | |
# inode, parent, type, name, data | |
fsdict = dict() | |
for item in fs: | |
type = None | |
match item[2]: | |
case 4: | |
type = 'd' | |
case 8: | |
type = 'f' | |
case _: | |
raise ValueError('unknown type') | |
if item[1] == 0: | |
path = '' | |
else: | |
path = fsdict[item[1]]['path'] | |
print('parsing inode', item[0], '-', type, os.path.join(path, item[3])) | |
fsdict.update({item[0]: {'name': item[3], 'type': type, 'path': os.path.join(path, item[3]), 'data': item[4]}}) | |
for key, value in fsdict.items(): | |
fspath = os.path.join('config_restore', value['path']) | |
print('writing', fspath) | |
if value['type'] == 'd': | |
os.mkdir(fspath) | |
elif value['type'] == 'f': | |
fh = open(fspath, 'wb') | |
if not value['data'] == None: | |
fh.write(value['data']) | |
fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment