[SOLVED] Extract Proxmox Database

I used this python3 script to extract all configs, just use it via ```python3 extract.py /the/path/to/config.db```

Python:
import sqlite3
import os
import sys

def main(database_path):
    query = 'SELECT name, data FROM tree;'

    # Check if the SQLite database file exists
    if not os.path.isfile(database_path):
        print(f"Error: Database file '{database_path}' does not exist.")
        print("Usage: python3 script.py <path_to_database>")
        sys.exit(1)

    # Connect to the SQLite database
    conn = sqlite3.connect(database_path)

    # Create a cursor object using the cursor() method
    cursor = conn.cursor()

    # Execute the SQL query
    cursor.execute(query)

    # Fetch all rows from the database
    rows = cursor.fetchall()

    # Loop through the rows and write to files
    for name, data in rows:
        # Check if data is None and replace with an empty bytes object
        if data is None:
            data = b''

        # Sanitize the name to create a valid filename
        # Replace any forward slashes with underscores
        filename = name.replace('/', '_')

        # Write the data to the file in binary mode
        with open(filename, 'wb') as file:
            file.write(data)

        # Print a message indicating the file has been written
        print(f'Data written to file: {filename}')

    # Close the cursor and connection
    cursor.close()
    conn.close()

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("Usage: python3 script.py <path_to_database>")
        sys.exit(1)

    database_file = sys.argv[1]
    main(database_file)
 
  • Like
Reactions: Tomas Waldow

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!