Error when running CLI command to export wf

Describe the issue/error/question

When trying the n8n export commands on a new instance, i’m running into this error. Not sure how to resolve it.

What is the error message (if any)?

NodeOperationError: Command failed: n8n export:workflow --backup --output=/data/backups/workflows
Error exporting workflows. See log messages for details.

    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/ExecuteCommand/ExecuteCommand.node.js:76:27)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:645:28)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:557:53

Please share the workflow

docker-compose.yml
version: '3.1'
services:
  n8n:
    image: n8nio/n8n    
    container_name: n8n
    restart: always
    env_file:
      - ./n8n/n8n.env
    ports:
      - 5678:5678
    depends_on:
      - postgres
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./n8n/.n8n:/home/node/.n8n
      - ./n8n/files:/files
      - ./n8n/data:/data
      - ./n8n/tmp:/tmp
    networks:
      - n8n
    command: /bin/sh -c "sleep 5; n8n start"

  postgres:
    image: postgres:14
    container_name: postgres
    restart: always
    env_file:
      - ./n8n/n8n.env
    environment:
      - POSTGRES_USER=****
      - POSTGRES_PASSWORD=****
      - POSTGRES_DB=n8n
      - POSTGRES_PORT=7432
      - POSTGRES_NON_ROOT_USER=****
      - POSTGRES_NON_ROOT_PASSWORD=****
    ports:
      - "7432:5432"
    volumes:
      - ./n8n/init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
      - ./n8n/postgres-data:/var/lib/postgresql/data
    networks:
      - n8n

  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    restart: always
    security_opt:
      - no-new-privileges:true
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./portainer-data:/data
    ports:
      - "9000:9000"
      - "9010:8000"

networks:
  n8n:

Information on your n8n setup

  • n8n version: 0.196.0
  • Database you’re using (default: SQLite): postgres
  • Running n8n with the execution process [own(default), main]: main
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @shrey-42, does a command such as n8n export:workflow --all work for you? Or do any CLI commands fail for you?

Hi @MutedJam, yes, n8n export:workflow --all works alright.

It’s particularly n8n export:workflow --backup --output=/data/backups/workflows that’s failing

Did you create a workflow to backup first? I could first reproduce this problem on an instance set up using the simplified docker-compose file attached below, but once I had created both the /data/backups/workflows directory and saved my first workflow the command completed fine:

docker-compose.yml
version: '3.1'
services:
  n8n:
    image: n8nio/n8n:0.196.0
    ports:
      - 5678:5678
    volumes:
      - ./n8n/.n8n:/home/node/.n8n
      - ./n8n/files:/files
      - ./n8n/data:/data
      - ./n8n/tmp:/tmp
    command: /bin/sh -c "sleep 5; n8n start"

Yeah, did that already.

Hm, in that case I’d simply use the API to fetch workflow and store them through the respective nodes rather than bothering with the Execute Command node tbh. The latest n8n version 0.197 introduces a new n8n node which should make this easy and much easier to manage:

After running this workflow you’ll have individual files for each workflow which you can write on the filesystem or upload to a cloud service:

This looks nice. Does the node also export credentials (also in decrypted state) as i’m basically trying to implement a workflow & credential backup scenario?

It doesn’t unfortunately. So the CLI would be the way to go. If writing directly to your filesystem causes trouble for some reason, I’d suggest using n8n export:workflow --all and n8n export:credentials --all --decrypted in the Execute Command node, then store the results in files without the Execute Command node:

Yeah, that’s the approach i shall use then.
Thanks!

No worries, sorry I can’t help with the writing directly to file trouble here :frowning:

1 Like