Skip to content

Instantly share code, notes, and snippets.

@gladiopeace
Forked from samicrusader/pmxcfs.py
Created July 24, 2023 20:42
Show Gist options
  • Save gladiopeace/e0d4b9e44e8efc326daf855361bac3f1 to your computer and use it in GitHub Desktop.
Save gladiopeace/e0d4b9e44e8efc326daf855361bac3f1 to your computer and use it in GitHub Desktop.
Proxmox Virtual Environment config.db dump utility
#!/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