Docker CLI commands to export credentials and workflows error

I’m very excited when read [email protected] have * Added CLI commands to export and import credentials and workflows

I’ve updated my n8n to latest version [email protected] and tried to use command

docker run -it --rm -v ~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --backup  --output=root/n8n/backups/lastest

(I’ve create folder /root/n8n/backups/lastest before)

But it show this error:

FILESYSTEM ERROR
====================================
EACCES: permission denied, mkdir '/root/n8n/backups/lastest'
Error: EACCES: permission denied, mkdir '/root/n8n/backups/lastest'
    at Object.mkdirSync (fs.js:987:3)
    at ExportWorkflowsCommand.run (/usr/local/lib/node_modules/n8n/dist/commands/export/workflow.js:37:24)
    at ExportWorkflowsCommand._run (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:43:31)
root@n8nv3:~/n8n# docker run -it --rm -v ~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --backup  --output=root/n8n/backups/lastest

FILESYSTEM ERROR
====================================
EACCES: permission denied, mkdir 'root/n8n/backups/lastest'
Error: EACCES: permission denied, mkdir 'root/n8n/backups/lastest'
    at Object.mkdirSync (fs.js:987:3)
    at ExportWorkflowsCommand.run (/usr/local/lib/node_modules/n8n/dist/commands/export/workflow.js:37:24)
    at ExportWorkflowsCommand._run (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:43:31)

How can i fix this?

*** Added information: when I update to lastest version, it shows

docker-compose up -d
Creating n8n_traefik_1 ... done
Creating n8n_n8n1_1    ... done
Creating n8n_n8n_1     ... done

Is it relate to command “~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow”

When I try to use command

docker run -it --rm -v ~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --all

It show error

›   Error: No workflows found with specified filters.

As the error message states, is the problem that n8n does not has permission to write to the folder you try to write to. So to fix that you have to do two things.

  1. Mount the folder you want to export to /import from. So another one of those -v in the docker command. That could for example be -v ~/n8n-exports:/data-export

  2. Tell n8n to export to/from that folder. That can be done with --output or --input

So the whole command would then probably look like this:

docker run -it --rm -v ~/n8n-exports:/data-export -v ~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --all --output=/data-export

Hope that helps!

Thanks for reply, I’ve tried extract your whole command, it shows this error:

The paramenter --output must be a writeble file

If I create a folder data-export in /root/n8n/data-export and change to command

docker run -it --rm -v /root/n8n/data-export -v ~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --all --output=/root/n8n/data-export

It shows error:

Error: No workflows found with specified filters.

Is my command is missing something?

Then add the option --separate

If I add the option --separate

docker run -it --rm -v ~/n8n-exports:/data-export -v ~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --all --separate --output=/data-export

It shows error

Error: No workflows found with specified filters.

Then there are no workflows to export.

I guess you do not use SQLite as a database, rather something else. That n8n can export/import you have to configure it correctly. So supply all the environment variables so that it can connect to the database where the information is stored (if you simply set the same environment variables as you set when you start n8n “normally” it will work).

I’m sure that I’ve use SQLite as a database like this picture because I follow this instruction: Server Setup | Docs (n8n.io)

image

when I update to newest version, it shows

docker-compose up -d

Creating n8n_traefik_1 ... done
Creating n8n_n8n1_1    ... done
Creating n8n_n8n_1     ... done

Is it relate to command “~/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow”?

Ah OK. So if you use SQLite you have to make sure that this part is identical -v ~/.n8n:/home/node/.n8n with the mount command you use when you run n8n. This line says that it mounts in the .n8n directory from your user into n8n.

According to your screenshot is it however in a subfolder. So you have to change it to -v ~/n8n/.n8n:/data-export if you run the command as root or to -v /root/n8n/.n8n:/data-export if you run it as any other user.

@jan Thanks for more detail information, I’ve change command to

docker run -it --rm -v ~/n8n/.n8n:/home/node/.n8n -v ~/n8n/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --all --pretty

It’s working but only show on cmd, I want to save to folder so I use this command

docker run -it --rm -v ~/n8n/.n8n:/home/node/.n8n -v ~/n8n/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --backup --output=root/n8n/data-export

but it shows error

FILESYSTEM ERROR
====================================
EACCES: permission denied, mkdir 'root/n8n/data-export'
Error: EACCES: permission denied, mkdir 'root/n8n/data-export'
    at Object.mkdirSync (fs.js:987:3)
    at ExportWorkflowsCommand.run (/usr/local/lib/node_modules/n8n/dist/commands/export/workflow.js:37:24)
    at ExportWorkflowsCommand._run (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:43:31)

How can I do to save to folder?

There was a typo in my above example. Fixed it now. So what you would need is:

docker run -it --rm -v ~/n8n:/data-export  -v ~/n8n/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --backup --output=/data-export

You will then see the files in your n8n folder within your user-folder.

This is my Ubuntu version
image

I’ve create data-export folder like this

image

And run your command, it shows error like this

How can I fix this permission o create backup files?

You can run: chmod 777 ~/n8n

It’s working when I run chmod 777 ~/n8n, Thank you.

But files export not in folder data-export, it’s on /root/n8n like this picture

How can I put export file to folder data-export

Command is:
root@n8nv3:~/n8n# docker run -it --rm -v ~/n8n:/data-export -v ~/n8n/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --backup --output=/data-export

Then you can change it to:

docker run -it --rm -v ~/n8n/data-export:/data-export -v ~/n8n/.n8n:/home/node/.n8n n8nio/n8n n8n export:workflow --backup --output=/data-export
1 Like

Hi All, Is it possible to execute it in a running instance?

@jan It’s work like a charm, Thank you so much!

Welcome to community, I’ve run command in a running n8n server, it’s ok!

1 Like

The n8n Instance in the Docker Container runs on Container User node.

So you need to run docker exec -u node …

jeez - I’ve spent a morning trying to work out why I was getting the silly message …

The -u node on the docker line solved it :slight_smile:

2022-10-04T12:36:11.796Z | error    | No workflows found with specified filters. "{ file: 'workflow.js', function: 'run' }"

Can someone maybe add it to the documentation CLI commands - n8n Documentation ?

docker exec -u node -ti n8n-container-name cli-command

2 Likes

I believe we changed the docker user very recently, this is still a good suggestion for the documentation. I’ll make sure to pass on your suggestion to @deborah.

1 Like