Upgrade, backup, and rollback

The pre-upgrade backup checklist, the two upgrade paths for Docker and source, the verification order, and the rollback path after a failure.

Self-hosting means you own upgrades and backups. This page gives a minimal procedure you can follow directly, independent of any specific cloud provider.

1. Four things to do before upgrading

# What to do Why
1 Confirm the target version and the changes it contains Avoid taking incompatible changes straight into production
2 Back up data, configuration, and environment files A new version may migrate the schema automatically, and a downgrade may not restore it
3 Confirm disk and backup space A failed backup is more dangerous than no backup
4 Book a maintenance window and notify users Tasks may be interrupted during the upgrade

Do not upgrade by running git pull, restarting, and dealing with problems later. When an upgrade fails, the backup taken beforehand is the most valuable asset.

2. Backup checklist

Must back up

Path / object Contents If lost
/etc/grape/grape.env JWT, database, OBS, SMTP, and other environment variables Sessions break; credentials cannot be decrypted
/etc/grape/runtime.env The Worker's model keys and other values The Worker reports the model as unconfigured or returns 401
.env Used by Docker / single-process entry points Same as above
data/ SQLite database, logs, backups Tasks, sessions, and Skill bindings are all lost
configs/ Sign-in channels, scene sync, email, security, engine scheduling Must be re-entered from the actual configuration
.grape/skills/ Custom Skill assets Skills are lost
Docker volume grape-data /app/data inside the container Same as data/
MySQL / three databases Business data Same as data/

data/ and grape-data are two locations for the same data: source deployments use the directory, Docker deployments use the volume. Backing up either one is sufficient.

Source deployment backup

Stop writes first, then archive:

cd /path/to/grape

# 1. Back up SQLite (if you use SQLite)
sqlite3 data/sessions.db ".backup 'data/sessions.db.bak-$(date +%F)'"

# 2. Back up configuration and data
sudo tar czf grape-backup-$(date +%F).tar.gz \
  -C / etc/grape \
  -C /path/to/grape .env data configs .grape/skills

# 3. Verify that the archive is readable
tar -tzf grape-backup-$(date +%F).tar.gz >/dev/null && echo "backup ok"

/etc/grape/ is outside the repository directory; -C / etc/grape adds it to the archive as well.

Docker deployment backup

Stop writes first, then archive the volume with a one-off container:

cd deploy
docker compose --env-file ../.env stop

docker compose --env-file ../.env run --rm --no-deps -T grape-server \
  tar czf - -C /app data > ../grape-data-$(date +%F).tar.gz

cd ..
cp .env grape-env-$(date +%F)
[ -f /etc/grape/runtime.env ] && cp /etc/grape/runtime.env grape-runtime-env-$(date +%F)
tar czf grape-config-$(date +%F).tar.gz configs .grape/skills

tar -tzf grape-data-$(date +%F).tar.gz >/dev/null && echo "data backup ok"

configs/ and .grape/skills are host directories; archive them directly.

MySQL / three-database backup

Use mysqldump --single-transaction and write a separate file for each database. Do not put the password in command-line history; use a temporary defaults file with restricted permissions.

mysqldump --defaults-extra-file=<secure-defaults-file> \
  --single-transaction --routines --triggers \
  <database> > grape-<database>-$(date +%F).sql

In three-database mode, back up the mgmt, runtime, and insight databases separately.

3. Upgrade

Docker

git fetch --tags
git checkout <target tag or commit>

cd deploy
docker compose --env-file ../.env up -d --build
docker compose --env-file ../.env ps

Wait until all containers are healthy, then verify.

Source / systemd

git fetch --tags
git checkout <target tag or commit>

source .venv/bin/activate
pip install -r requirements-local.txt    # when dependencies changed

Single-machine SQLite: migration runs when the process starts; a restart completes it.

sudo systemctl restart grape-server grape-event-server grape-worker-server grape-insight-server

Domain-split / multi-database MySQL: the order cannot be reversed.

# Must run in a shell where the production environment variables are loaded
bash scripts/deploy-after-migrate.sh

Restart the four processes only when the script exits with 0. For non-zero exits:

  • 2: unregistered duplicate base tables exist; assign the owner first
  • 3: database unavailable, the database family cannot be determined, or CREATE VIEW permission is missing
  • Any other non-zero: migration or views still have problems

Do not restart first to see what happens. A restart makes the application run with old views and a new schema, which easily produces missing columns and 1146.

4. Post-upgrade verification

Follow this order; process liveness alone is not enough:

  1. Health check
curl -fsS https://<grape-domain>/api/health
  1. All four processes/containers are running
  2. Sign in to the console
  3. Open the repository list
  4. Open a historical Issue/Pipeline
  5. Create a low-risk Issue and confirm that it can be enqueued
  6. Check whether the Worker is online and whether the engine health check passes
  7. Check that the service log has no migration, view, or database connection errors

For Docker deployments, also check:

docker compose --env-file ../.env ps

5. Rollback

When to roll back

  • Startup fails and cannot be fixed in the short term
  • Missing columns or 1146 appear widely after migration
  • Core paths (sign-in, Issue, tasks) are unavailable
  • Data contains unacceptable errors

Rollback order

Stop the service
  → Return the code to the previous version
    → Restore data and configuration
      → Start
        → Verify

Source:

sudo systemctl stop grape-server grape-event-server grape-worker-server grape-insight-server
git checkout <previous version tag or commit>
sudo tar xzf grape-backup-<date>.tar.gz -C / etc/grape
tar xzf grape-backup-<date>.tar.gz -C /path/to/grape .env data configs .grape/skills
sudo systemctl start grape-server grape-event-server grape-worker-server grape-insight-server

Docker:

cd deploy
docker compose --env-file ../.env down
git checkout <previous version tag or commit>
docker compose --env-file ../.env run --rm --no-deps -T grape-server \
  tar xzf - -C /app < ../grape-data-<date>.tar.gz
cd ..
tar xzf grape-config-<date>.tar.gz
cd deploy
docker compose --env-file ../.env up -d --build
docker compose --env-file ../.env ps

Stop the service before restoring data. If SQLite keeps writing through the old connection, the restore has no effect.

After rollback

  1. Run through the verification checklist again
  2. Keep the logs and backups of the failed version; do not clean them up immediately
  3. Record the failure cause and the next fix plan

6. Common failures

Symptom Likely cause Handling
Startup fails immediately Missing dependencies, missing environment variables, or a failed migration Check the startup log; roll back first, then fix
Pages show missing columns or 1146 The post-migration fix was not run in multi-database mode Stop the service, run deploy-after-migrate.sh, do not restart directly
All sign-ins fail JWT/encryption keys were overwritten Restore /etc/grape/grape.env and security.json
Tasks stay queued The Worker did not start or the engine is offline Check the Worker unit and the engine health check
The backup file cannot be opened The service was still writing during the backup, or the disk was full Stop writes and back up again; check the disk first
Data is still wrong after rollback Services were started before data was restored, so old connections kept writing Follow stop → restore → start strictly

7. Completion criteria

  • [ ] Data, configuration, environment files, and databases are backed up
  • [ ] The backup archive lists contents; it is not an empty file
  • [ ] The pre-upgrade version and the target version are recorded
  • [ ] Single-machine SQLite completed the migration on restart
  • [ ] The multi-database migration script exited with 0
  • [ ] Health check, sign-in, historical data, and new tasks were all verified
  • [ ] Rollback commands and backup paths were handed over to the on-call engineer
  • [ ] Logs from the failed version are retained

Architecture and deployment topologies | Database backends and official sync | Security baseline and engine scheduling | Observability stack