Nodes Credentials Setup

Hi guys, quick idea hopefully this can be looked into. I am using the self hosted version. Each time you want to move to another new server, you have to first establish your credentials. Thereafter in case you had backups for all your workflows, you simply import by file. However the painstaking process is you have to visit and open each node to update the header credentials. They typically light up red in color. Some of the nodes share the same credentials so its a very tedious process. What if there was a way to select multiple nodes and select a particular credential you want to use rather than opening each node to update the credential? Food for thought? I know its a bit technical but will really help with migrations as there is no particular migration tool we have in n8n.

Hello Keep_Innovations,
yes, as far as I know there is no complete backup of n8n which you could simply import on another server. However, there are some possibilities. If n8n runs with SQLite, you only have to copy the SQLite file and use the same N8N_ENCRYPTION_KEY in the n8n configuration. About Postgres: Postgres itself offers export and import options. You can also use n8n for this if you wish. If you copy workflows classically from the UI and paste them somewhere else and then have to change a lot of access data, it can be faster if you paste the copied workflow (JSON) into a text file and then change the “credential ID” with “replacements” all at once. If this happens very frequently, you can also tinker with n8n here. Finally, you could also consider using the enterprise version of n8n to manage access data via an external system. I haven’t used it yet - unfortunately I can’t say anything about how well it works there.

Hi Bill, thanks for the feedback. I agree tinkering too much with n8n will cause issues. For me migration would entail creating the credentials in identical format and importing the workflows. Could you give me an idea how to change the JSON file and will there be multiple places I would need to change the JSON Credential ID and how should it look like, naming has to be identical? Also finding the Encryption key is proving to be a challenge, been going through all my folders and still nothing.

If you simply want to move from server A to server B and you have used SQLite and not set any other environments: Simply copy the .n8n folder (Under Linux a hidden folder) into the corresponding directory. The generated encryptionKey is saved under .n8n/config. However, this can also be overwritten using N8N_ENCRYPTION_KEY (env).

If you have used Postgres, simply copy the .n8n folder and use the same environment variables for the Postgres database.

If you need to change the Postgres database, Postgres or pgAdmin offers tools for this.

And what I meant earlier: If you have a lot of time, you can also create a workflow with n8n, which copies the data from the Postgres database to another one.

If you only copy individual workflows from server A to server B, it is quicker to do this manually. In the JSON you can find e.g.

"credentials": {
  "httpHeaderAuth": {
    "id": "2kGPxCx2N6zWaoRG",
    "name": "Header Auth account"
  }
}

Simply enter the corresponding id/name here. Notepad++ >> Replace All

Access data cannot yet be created via the n8n API. To do this, you have to access the SQLite/Postgres database directly.

If you want to see the access data in plain text - for example, you have read the access data from the Postgres database - you can use this code to decrypt it:

const CryptoJS = require("crypto-js");
const bytes = CryptoJS.AES.decrypt(cryptedData, $env.N8N_ENCRYPTION_KEY);
const credentials = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));

The n8n environment variables must of course not be blocked or you replace the variable by the encryption key (string).

Hi Bill thanks again, sincerely appreciated. I wish someone could just come up with a migration document on how to backup all your workflows e.g If moving to like Hetzner. Setup documentation is already available however needs some tweaking. But the Migration process of how to move all your workflows and credentials seamlessly after setting up n8n in a new server would be quite neat I think.

If nothing else is configured, simply copy the .n8n folder from the old server to the new one. The setup of n8n takes the existing .n8n folder into consideration. You can also simply run the n8n setup and then override the folder with your backup folder.

What problem are you facing exactly?

Hi Bill, sorry for delayed feedback. I am just actually looking for a clean method of backing up everything so that in case I need to move to a new server its just a few min process. So I think your advise on editing the json text file would be a better move and just replacing the the IDs. As long as you have the current new ids, its a case of find and replace. Btw, have you ever migrated from SQLlite to Postgres, having a really hard time doing this migration. My postgres server is up and running but moving data from sqlite to postgres is just stress. I have tried so many techniques but so many hidden folders and stuff u cant find. U cant find tables on the sql shell, sqlite db showing 0kbs, stress

I myself have not yet carried out a data migration from SQLite to Postgres. When I was about to make the switch, I took the time to copy everything manually. I immediately got rid of the ones I no longer needed and reworked the workflow. n8n has also had many updates over the years, which have made it possible to structure the workflow better.

If I were faced with the task today, I would have Docker volumes for the file backup and I would open the SQL database with “DB Browser for SQLite” and export the contents and import them back into Postgres - using n8n if necessary. As long as there is no version jump, no problem.

Binary data from the .n8n folder is not actually required - if you do not need the logs. “Only” the SQLite and the config file are located there. I always set the N8N_ENCRYPTION_KEY via the environment. So all that remains is the SQLite database.

I copied the docker volumes for the postgres container and the n8n container to a second vm, setup the dns, and everything booted up working and seemingly complete.

I cam here to find out if there is a community node for settings credentials of a specific type exactly once. If someone knows/ finds/ creates it, let me know!