Back up and move

Back up, restore, and move the database.

What to keep

A backup has two parts:

  1. The database. It keeps workflows, runs, users and credentials.
  2. The .env file. It keeps ZERODOT_SECRET_KEY and BETTER_AUTH_SECRET. Without the same ZERODOT_SECRET_KEY, nobody can open the saved credentials.

Also keep the blob folder if you use one (files and large node outputs). Docker mode keeps blobs in the volume blob-data. Native mode keeps them in /var/lib/NAME/blobs. An S3 bucket has its own backups.

The Valkey queue holds jobs that wait or run now. You do not need to back it up.

Automatic backups

The install script can back up the database and .env each day or each week:

sudo bash install.sh zerodot.example.com --backup daily

The backups go to /var/backups/NAME (macOS: ~/NAME-backups). The script keeps the newest 14. To change this, use --backup-dir PATH and --backup-keep N. To make a backup now, run zerodot backup (see zerodot CLI), or run sudo /usr/local/sbin/NAME-backup (macOS: ~/.zerodot/NAME-backup.sh). See Backups and automatic updates.

The automatic backup does not include the blobs. Back them up as shown below.

Back up the database

When install.sh sets up the install with Zerodot's Postgres, run zerodot backup. See zerodot CLI.

Docker mode, Postgres container:

cd /var/www/zerodot
docker compose exec -T postgres pg_dump -U zerodot zerodot | gzip > zerodot-$(date +%F).sql.gz

Docker mode, Postgres on the server or managed:

cd /var/www/zerodot
pg_dump "$(grep '^DATABASE_URL=' .env | cut -d= -f2- | sed 's/host.docker.internal/127.0.0.1/')" | gzip > zerodot-$(date +%F).sql.gz

Native mode:

sudo runuser -u postgres -- pg_dump zerodot | gzip > zerodot-$(date +%F).sql.gz

Use the database name of your instance. For the instance zerodot-staging, the name is zerodot_staging.

Back up the blobs (Docker mode):

cd /var/www/zerodot
docker compose run --rm --no-deps -T --entrypoint tar web czf - -C /blobs . > blobs-$(date +%F).tar.gz

Back up the blobs (native mode):

sudo tar czf blobs-$(date +%F).tar.gz -C /var/lib/zerodot/blobs .

Keep the backups on another server.

Restore on a new server

When install.sh sets up the install with Zerodot's Postgres, copy your secrets and run zerodot restore. See zerodot CLI. Or follow these steps by hand:

  1. Install Zerodot on the new server with the same mode.

  2. Stop the app.

    Docker mode:

    cd /var/www/zerodot
    docker compose stop web api worker
    

    Native mode:

    sudo systemctl stop zerodot-web zerodot-api zerodot-worker
    
  3. Copy ZERODOT_SECRET_KEY and BETTER_AUTH_SECRET from the old .env to the new .env. Do not change the other values: the new database password is in the new .env.

  4. Load the database dump. Docker mode:

    docker compose exec -T postgres psql -U zerodot -d zerodot -c 'drop schema public cascade; create schema public;'
    gunzip -c zerodot-2026-01-01.sql.gz | docker compose exec -T postgres psql -U zerodot -d zerodot
    

    Native mode:

    sudo runuser -u postgres -- psql -d zerodot -c 'drop schema public cascade; create schema public authorization zerodot;'
    gunzip -c zerodot-2026-01-01.sql.gz | sudo runuser -u postgres -- psql -d zerodot
    
  5. Start the app.

    Docker mode:

    docker compose up -d
    

    Native mode:

    sudo systemctl start zerodot-web zerodot-api zerodot-worker
    

The drop schema command deletes all data in the new database. Run it only on the new server.

Move the database from the container to the server

The installer does not move data between a container and the server. Do these steps by hand.

  1. Dump the database from the container:

    cd /var/www/zerodot
    docker compose exec -T postgres pg_dump --no-owner --no-acl -U zerodot zerodot > zerodot.sql
    

    --no-owner and --no-acl leave out the owner and the grants of the container user. The new user then owns all tables.

  2. Stop the app:

    docker compose stop web api worker
    
  3. Make a user and a database on the server. Use a name that is not used:

    sudo -u postgres createuser -P zerodot_app
    sudo -u postgres createdb -O zerodot_app zerodot_app
    

    createuser -P asks for a password.

  4. Load the dump as the new user:

    psql -h 127.0.0.1 -U zerodot_app zerodot_app < zerodot.sql
    

    On Fedora and RHEL, a TCP login can fail with ident. Add a pg_hba.conf line for the user first. See Databases.

  5. Open .zerodot-install in the install folder. Change PG_MODE=docker to PG_MODE=host.

  6. Run the script with the new database:

    sudo DATABASE_URL='postgres://zerodot_app:<password>@127.0.0.1:5432/zerodot_app' \
      bash scripts/install.sh --update
    

    The script changes 127.0.0.1 to host.docker.internal. It asks to let the containers reach Postgres. See Postgres and Valkey on the server.

  7. The script stops the old Postgres container of the install. It keeps the volume postgres-data, and writes the change to /var/log/zerodot-install.log.

The volume postgres-data stays. Delete it only when you are sure that you do not need it.

To move Valkey, you do not move data. Change RD_MODE=docker to RD_MODE=host in .zerodot-install. Run the script with VALKEY_URL. The script stops the old Valkey container. Jobs that wait in the old queue are lost. Do it when no runs are active.

Move the database from the server to the container

  1. Dump the database on the server with pg_dump --no-owner --no-acl.

  2. Change PG_MODE=host to PG_MODE=docker in .zerodot-install.

  3. Remove the DATABASE_URL line from .env.

  4. Run the script with --update. It starts the Postgres container and the app.

  5. Stop the app:

    cd /var/www/zerodot
    docker compose stop web api worker
    
  6. Empty the new database, then load the dump:

    docker compose exec -T postgres psql -U zerodot -d zerodot -c 'drop schema public cascade; create schema public;'
    docker compose exec -T postgres psql -U zerodot -d zerodot < zerodot.sql
    
  7. Start the app:

    docker compose up -d
    

Change this page on GitHub