How to migrate / export / import the database #1529
Replies: 15 comments 13 replies
-
Thank you very much for the thorough guide. I am sure that many users will find this increasingly useful once V3 is released, as it seems SQLite will be the only db used. I followed the guide and was successfully able to migrate from MariaDB to a SQLite. SQLite seems like a better option for this service, and I'm glad its moving in that direction. Additionally, I was stuck on mariadb-aria:10.4 (due to innodb errors: v10.4.12 release notes). Migrating to SQLite still worked, and I imagine users who wish to remain on MariaDB but are similarly stuck on :10.4, could migrate following the import/export sections of this guide. |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you for this detailed guide! I run NPM on an Alpine VPS where I only have CLI access. I would like to migrate from MariaDB to SQLite without DBeaver, do you have any advice or things I should watch out for? |
Beta Was this translation helpful? Give feedback.
-
I have two machines that run Nginx Proxy Manager v2.9.14. I set up my configuration on one of them and have my router pointed at this one. I would like to duplicate / backup & restore / export & import / synchronise the settings from server 1 to server 2. This way if there is an issue with server 1 I can easily change my router forwarding to server 2. If I perform the following steps, am I right in expecting everything to be backed up properly?
For example, this would look something like:
If this is correct, I'm assuming performing the same steps in reverse will restore / import the configuration. Any confirmation would be much appreciated. |
Beta Was this translation helpful? Give feedback.
-
For reference I have created gist versions of my scripts to show how I implemented the database dump and restore. Place these in a suitable location (I use |
Beta Was this translation helpful? Give feedback.
-
This guide had me stumped for a while because the mysqldump command was not found, it turns out NPM (as of Nov 2021) doesn't use mysql anymore, I only found this out by chance when I looked at one of the other 'Show and tell' articles on here. To back up the sqlite database, I use: |
Beta Was this translation helpful? Give feedback.
-
how to fix?
|
Beta Was this translation helpful? Give feedback.
-
If you encounter issues after migration with writing to the DB (like, when altering proxy hosts for example), the SQLite DB table properties are most likely wrong. For me, this happened when migrating from MariaDB to SQLite via DBeaver as per above tutorial. I solved this by using the database.sqlite from a freshly deployed instance and leaving "Truncate tables" unchecked during migration. This makes sure, that the table properties won't get overwritten. See also here: #1643 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tutorial but im running into issues where i cant get letsencrypt certificates no more, the ui shows internal error, and the docker logs shows:
not sure whats wrong here |
Beta Was this translation helpful? Give feedback.
-
I just converted over to SqLite from Mariadb/MySQL. This is how I did it. Keep in mind you need access to a Linux command line that has mysqldump and sqlite3 commands. First, I used the script
|
Beta Was this translation helpful? Give feedback.
-
I have followed the instructions above to migrate from a mysql database to an sqlite database. After restarting the container, I receive the following error for both the SSL Certificates tab and the Proxy Hosts tab - "domain_names.map is not a function" with a box to "Try again". All is functioning properly and I can connect with all my services but I cannot edit proxy hosts nor SSL Certificates. Is this an issue that others see? Can it be related to Docker 26.0 being released which has also caused issues with Portainer? Any suggestions would be highly appreciated. |
Beta Was this translation helpful? Give feedback.
-
I don't know if anybody need to know, but if you migrate from docker to baremetal or lxc, you need to do this: /data/nginx/proxy_host# sed -i "s#conf.d#/etc/nginx/conf.d#g" * Or service keep crashing. |
Beta Was this translation helpful? Give feedback.
-
I migrated from SQLite to MariaDB (I thought it would be a more enterprise setup).
Any suggestion? |
Beta Was this translation helpful? Give feedback.
-
It seems that the field id should be self incrementing and that is defined as a property of the field to be a self incrementing key field in the table.
…________________________________
From: Antonín Chadima ***@***.***>
Sent: Friday, September 27, 2024 3:22:32 PM
To: NginxProxyManager/nginx-proxy-manager ***@***.***>
Cc: Pat ***@***.***>; Comment ***@***.***>
Subject: Re: [NginxProxyManager/nginx-proxy-manager] How to migrate / export / import the database (Discussion #1529)
I migrated from SQLite to MariaDB (I thought it would be a more enterprise setup).
I have used Dbeaver and this tutorial and everything is working great
except adding any new record to npm (and deleting an old record).
I get this error:
[9/27/2024] [11:01:02 AM] [Express ] › ⚠ warning insert into proxy_host (access_list_id, advanced_config, allow_websocket_upgrade, block_exploits, caching_enabled, certificate_id, created_on, domain_names, forward_host, forward_port, forward_scheme, hsts_enabled, hsts_subdomains, http2_support, locations, meta, modified_on, owner_user_id, ssl_forced) values (0, '', true, true, true, 0, NOW(), '[\"npm.ucl.cas.cz\"]', 'npm.localdomain', 81, 'http', false, false, false, '[]', '{\"letsencrypt_agree\":false,\"dns_challenge\":false}', NOW(), 1, false) - ER_NO_DEFAULT_FOR_FIELD: Field 'id' doesn't have a default value
Any suggestion?
—
Reply to this email directly, view it on GitHub<#1529 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AUXEO2VNS4LE7FAO5N25XRTZYVLZRAVCNFSM5G2W6JXKU5DIOJSWCZC7NNSXTOSENFZWG5LTONUW63SDN5WW2ZLOOQ5TCMBXG42TQMJS>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
the error was caused by a stupid mistake: but then you get a new error:
which is caused by the table migrations and the column should i convert this column to the desired format? or? |
Beta Was this translation helpful? Give feedback.
-
Sqllite is perfectly suited for this application.
…________________________________
From: Antonín Chadima ***@***.***>
Sent: Monday, September 30, 2024 7:51:45 AM
To: NginxProxyManager/nginx-proxy-manager ***@***.***>
Cc: Pat ***@***.***>; Comment ***@***.***>
Subject: Re: [NginxProxyManager/nginx-proxy-manager] How to migrate / export / import the database (Discussion #1529)
ok - i will stick with sqlite, after reading this discussion it seems wrong to go for mariadb/mysql...
—
Reply to this email directly, view it on GitHub<#1529 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AUXEO2TLCUHD54DQWYHTUQDZZDYIDAVCNFSM5G2W6JXKU5DIOJSWCZC7NNSXTOSENFZWG5LTONUW63SDN5WW2ZLOOQ5TCMBXHE2DCMZQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Unfortunately there is no built-in way to export or import data from nginxproxymanager. When backing up the
/data
directory, and mounting it in a new instance of npm, it does proxy everything as before, however the admin interface is empty, as the data used there is inside the database. (Unless you use SQLite, then your sqlite file could be inside the data directory). The database exports / imports here are in addition to backing up the/data
and/etc/letsencrypt
volumes!Some steps require a database tool. Those are prefixed with [DBeaver] since I am using DBeaver, which is available for all platforms. I am working on Linux, if your npm instance is hosted on a machine with a different OS you might need to do other things than I have shown to open a terminal and run docker commands.
All commands are executed inside the folder containing the
docker-compose.yml
file, so when opening a terminal make sure to navigate to that folder first e.g. using thecd
command, likecd /home/pi/nginxproxymanager
.🖥️➡️🖥️ Migrate to new npm instance #
/data
and/etc/letsencrypt
volumes to your new instance and mount them into your new instance. If you use the default configdata
andletsencrypt
next to yourdocker-compose.yml
, which you can just copy over.data
folder, otherwise just copy the file over. Also possible using DBeaver.🥳 You have migrated the data to a new system
[DBeaver] Migrate MariaDB to a SQLite database #
Click to view steps
migrate-mariadb-to-sqlite.mp4
🥳 You have successfully migrated from using a MariaDB/MySQL database to using the SQLite database. You can now remove the old database container if you wish.
Export data from a MariaDB/MySQL database #
Click to view steps
Replace the placeholders (remove the square brackets as well) and run
docker exec -it [db-container-name] mysqldump --user=[mysql-user] --password=[mysql-password] [mysql-db-name] -h 127.0.0.1 > npm-export.sql
Replace
[db-container-name]
with the docker container name of your database container. If you are using the official docker-compose it is just calleddb
.Replace
[mysql-user]
,[mysql-password]
and[mysql-db-name]
with the values you have set for the variablesDB_MYSQL_USER
,DB_MYSQL_PASSWORD
andDB_MYSQL_NAME
in your docker-compose file.You can also replace
npm-export.sql
with a path where to save the export to, but make sure it ends in a file with the extension.sql
.🥳 You have successfully exported the database! You should now find a .sql file inside the folder where you executed the command from or where you set the path to.
Import data to a MariaDB/MySQL database #
Click to view steps
Replace the placeholders (remove the square brackets as well) and run
docker exec -i [db-container-name] mysql --user=[mysql-user] --password=[mysql-password] [mysql-db-name] -h 127.0.0.1 < npm-export.sql
Replace
[db-container-name]
with the docker container name of your database container. If you are using the official docker-compose it is just calleddb
.Replace
[mysql-user]
,[mysql-password]
and[mysql-db-name]
with the values you have set for the variablesDB_MYSQL_USER
,DB_MYSQL_PASSWORD
andDB_MYSQL_NAME
in your docker-compose file.Replace
npm-export.sql
with a path where the export you'd like to import is located.🥳 You have successfully imported the database!
[DBeaver] Connect to a MariaDB database #
Click to view steps
connect-to-mariadb.mp4
localhost
if the container is running on the same machine as your DBeaver, or use the IP of the machine hosting the container otherwise. Use port 3306.MYSQL_DATABASE
MYSQL_USER
andMYSQL_PASSWORD
🥳 You are now connected to the database!
[DBeaver] Export data from a MariaDB/MySQL database #
Click to view steps
export-mariadb.mp4
npm
by default unless changed through theMYSQL_DATABASE
environment variable)information_schema
. Click next.🥳 You have successfully exported the database! You should now find a file inside the selected folder similar to the file name pattern.
[DBeaver] Import data into a MariaDB/MySQL database #
Click to view steps
import-mariadb.mp4
npm
by default unless changed through theMYSQL_DATABASE
environment variable)🥳 You have successfully imported the database!
[DBeaver] Download and connect to a SQLite database #
Click to view steps
Unfortunately you can't connect to the database file inside the container directly, but instead you'll have to download the database file from the container and upload it again if you have changed anything.
download-edit-sqlite.mp4
DB_SQLITE_FILE
environment variable, so NPM has generated a SQLite file.docker ps
and copy the container id of your NPM container. You'll find it by searching for imagejc21/nginx-proxy-manager
and it should be a combination of numbers and letters just before it.docker cp <container-id>:/path/as/set/in/DB_SQLITE_FILE path/where/to/save/to
to copy the sqlite file to your local machine. The command will look something like this:database.sqlite
file to the machine with DBeaver on it if it is not the same machinedatabase.sqlite
in the path field🥳 You are now connected to the database file! Please remember to copy the database file back into your container if you have made any changes. Just switch the last two parameters of the
docker cp
command around like this:Beta Was this translation helpful? Give feedback.
All reactions