Rest and api

Aha … makes sense … For me though, production may also mean running an n8n workflow on a local (Mac)OS machine without any external (/web) access …

@MutedJam So now I’m still stuck with the backup of the workflows and credentials of my n8n Desktop App. I can not get rest to work, nor can I backup via the CLI, as I can not reset the user-management. Looking at the API, it will probably be easy to migrate the backup of the workflows from REST to API, however, I see no mechanism to backup my credentials. Any suggestions? Thanks again!

As for resetting the user management on n8n desktop, could you try using the UI option Auth > Reset password...?

Extracting credentials is indeed not supported through n8n’s REST API at this stage and you would need the CLI for this (e.g. n8n export:credentials --decrypted --all).

@MutedJam I followed your instructions (/Auth/Reset password…), and the n8n Destop App restarted.

I then tried the CLI and keep getting the error that says that the SQLite package has not been found installed …

dick@MacBook-Pro ~ % /Applications/n8n.app/Contents/Resources/app/node_modules/n8n/bin/n8n export:credentials --decrypted --all
Error exporting credentials. See log messages for details.
SQLite package has not been found installed. Try to install it: npm install sqlite3 --save

For now, I’m going to backup the SQL database via:

sqlite3 /Users/dick/.n8n/database.sqlite ".backup /Users/dick/.n8n/backup.sqlite"

The only thing I’m running into with this, is that you get the following error if an workflow is running:

Error: database is locked

I’m still boggled that something that is so elementary, and should be so simple, is so difficult to achieve … at least for me :wink: … but no worries; we’ll get there eventually :slight_smile:

Error: database is locked

Hm, this error suggests something is still hogging onto the database file. Have you stopped/killed all running n8n processes?

It’s also worth noting that the credentials in a database backup will only be useful if you also backup the encryptionKey from the ~/.n8n/config file.

That is very good to know!

So if I understand correctly, you first need to stop all running processes before you backup your sqlite database. So now my (hopefully last) questions for now are:

  • how do I stop all running processes?
  • how do I start them up again after the backup has finished?
  • or is there a better way to back up all n8n work?

Thanks again, and really appreciated!

So if I understand correctly, you first need to stop all running processes before you backup your sqlite database.

Yes, this is a limitation of SQlite, other databases can handle multiple parallel connections.

  • how do I stop all running processes?’

Check the docker desktop app if any container is still running (and if so, stop & remove it). Then restart your computer to get rid of anything n8n-desktop related that might still be running in the background. That should cover it I think, assuming nothing is set to autostart.

  • how do I start them up again after the backup has finished?

Pretty much the same way you usually start n8n.

or is there a better way to back up all n8n work?

I have three separate backups. One would be the server backups taken by my web hoster. These essentially allow me to go back in time for up to 7 days and are not related to n8n (but would of course include n8n data).

The second kind of backups are backups of my workflows uploaded to a cloud storage. This works fine through a backup workflow consuming the official API. My passwords are stored in a password manager anyway, so I can re-create credentials as needed and don’t bother with backing them up separately.

Lastly, I also dump my full database regularly (though I am using Postgres, meaning I wouldn’t have to worry whether it’s currently being used by n8n or anything else) and store these backups separately.

@MutedJam the upside from Murphy’s law (everything going wrong) is that you actually learn a lot … and so did I on the subject of backing up my n8n work :slight_smile: … I now know a lot more about the api, user management, and SQLite …

I modified my Backup workflow, which now uses the API to backup my workflow to the backups folder in my iCloud Drive daily. The same workflow also copies a dump file from the credentials table to the same folder. And I keep a copy of the encryptionKey from the config file in a save place.

Just in case you’re interested, here’s a copy of my backup workflow:

In order to make it work, you need to enter your own value for the X-N8N-API-KEY in the HTTP nodes, and tweak the file paths in the Execute Command and Write Binary File nodes . And please note that this workflow is running in n8n’s Desktop App on macOS, so it is using port 5679.

Please note: it took me a while to figure out that N8N_USER_MANAGEMENT_DISABLED = true option should not be in the .env file in order for the api to work, and that you first need to login with the admin user.

Please do not hesitate to send your comments in case I’ve got something wrong and/or have missed something.

And finally: thanks again for your help!

3 Likes

You are most welcome, I am really glad to hear you managed to figure out how to approach this in the end :slightly_smiling_face: