Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Save all configuration in a json file instead of a SQL DB #2422

iosifnicolae2 started this conversation in Ideas
Discussion options

It would be awesome if we can have all the configurations saved in a JSON file when deploying Nginx Proxy Manager using Docker.

By doing so, we can automate the deployment & container provisioning by just updating that json file.

You must be logged in to vote

Replies: 4 comments · 1 reply

Comment options

I wrote two Python scripts that dumps some configure tables from sqlite to json and back:

#!/usr/bin/env python3
# Generate export

import json
import sqlite3

EXPORTED_TABLES = [
    "proxy_host",
    "setting",
    "stream",
]

if __name__ == "__main__":
    # open database file
    with sqlite3.connect("database.sqlite") as conn:
        # builtin Row object is easy to convert to dict
        conn.row_factory = sqlite3.Row
        c = conn.cursor()
        # get the names of the tables
        c.execute("SELECT name FROM sqlite_master WHERE type='table'")
        tables = [a["name"] for a in c.fetchall()]
        # get content from each table
        # TODO: make this into a dict comprehension (if possible)
        db_content = {}
        for table in tables:
            if table in EXPORTED_TABLES:
                c.execute("SELECT * FROM {0}".format(table))
                db_content[table] = [dict(a) for a in c.fetchall()]
    # dump contents to json file
    with open("nginx.exported.json", "w") as f:
        json.dump(db_content, f, indent=4)
#!/usr/bin/env python3

# Import exported data

import json
import sqlite3

if __name__ == "__main__":
    with open("nginx.exported.json", "r") as f:
        db_content = json.load(f)
        print(db_content)
    # open database file
    with sqlite3.connect("database.sqlite") as conn:
        # builtin Row object is easy to convert to dict
        conn.row_factory = sqlite3.Row
        c = conn.cursor()

        for table, data in db_content.items():
            for row in data:
                cols = ', '.join('"{}"'.format(col) for col in row.keys())
                vals = ', '.join(':{}'.format(col) for col in row.keys())
                update_set = ', '.join('{}=excluded.{}'.format(col, col) for col in row.keys())
                sql = 'INSERT INTO "{0}" ({1}) VALUES ({2}) ON CONFLICT(id) DO UPDATE SET {3}'.format(table, cols,
                                                                                                      vals, update_set)
                conn.cursor().execute(sql, row)
                conn.commit()
You must be logged in to vote
1 reply
@iosifnicolae2
Comment options

You might need to also re-generate/backup nginx configs because Nginx Proxy Manager does not create them at startup.

Comment options

Any idea on how to re-generate nginx configurations after updating the SQLite DB directly?

You must be logged in to vote
0 replies
Comment options

It would be a good idea to implement it, there have been times when the SQLite files have been corrupted, and it would also be easier to modify them.

You must be logged in to vote
0 replies
Comment options

That would be golden. That's the kind a feature reverse proxies like traefik has a bit of an edge over NPM, you can preconfigure everything within the dicker compose files, makes so easy to deploy. I would love to see this on NPM.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💡
Ideas
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.