Skip to main content
This page applies when you host Earnie yourself. It assumes you installed Earnie as described in Installing Earnie. It covers four tasks: Run every command from the bundle directory, unless a step says otherwise. The examples use the default data directory, /var/lib/earnie. If you set EARNIE_DATA_DIR to another path, use that path instead. The examples write backups into the current directory. Move them off the server, or write them straight to your backup location. A backup holds tenant.env and your data, so keep it as safe as tenant.env itself.

Back Up

Back up three things: Keep tenant.env in a safe place with the same care as a password. Earnie encrypts the GitHub and GitLab credentials and the single sign-on client secret that it stores in the database. The encryption keys are EARNIE_INTEGRATIONS_KEK_HEX and EARNIE_SSO_KEK_HEX in tenant.env. A restored database is only useful with the same two keys. Without them, Earnie can’t read those stored credentials, and you would have to connect your Git servers and single sign-on again. There are two ways to take a backup. Use Option 1 when you can stop Earnie for a few minutes, such as before an upgrade. Use Option 2 for regular backups while Earnie keeps running.

Option 1: Stop Earnie, Then Copy Everything

This gives a backup in which the database and the data directory agree with each other. Earnie is unavailable while it runs.
  1. Stop the services:
  2. Copy the data directory and tenant.env to your backup location. For example:
    If you use your own PostgreSQL server, also take a backup of the database with your usual tool, for example pg_dump, while Earnie is stopped.
  3. Start Earnie again:

Option 2: Back Up While Earnie Runs

Earnie stays available, but the database and the data directory are copied separately, so they can be from slightly different moments if scans run during the backup. Only Option 1 gives you a backup that agrees with itself.
  1. Dump the database with pg_dump. For the bundled PostgreSQL:
    Use the values of ONPREM_PG_USER and ONPREM_PG_DB if you changed them from earnie. For your own PostgreSQL server:
  2. Copy the data directory and tenant.env. With the bundled PostgreSQL, leave out <EARNIE_DATA_DIR>/postgres, because a copy of a running database’s files can be unusable. The pg_dump file from step 1 replaces it:
Test your backup. Restore it on a spare server at least once, so you know the steps work before you need them.

Upgrade

Each release has a version number, vX.Y.Z. SCANOSS publishes a release every week, and recommends that a self-hosted installation upgrade to a stable release about once a month. Releases and release notes explains the stable channel, where to read what changed in a release, how to subscribe to the release feed, and how long a release is supported. Read the notes of the release you’re upgrading to before you start. Earnie is unavailable for a short time while it restarts. A scan that is running at that moment is not lost. It starts again from the beginning, so it finishes later. See Scans during a restart. Schedule the upgrade for a quiet period, when few scans are running. To upgrade:
  1. Back up. Take a full backup first, preferably with Option 1. The upgrade changes the database to the new release’s format, and an older release can’t start on it afterwards. The backup is your only way back. See Roll back.
  2. Check EARNIE_VERSION. If an earlier release had you set EARNIE_VERSION in tenant.env, clear it. The bundle knows its own release, and the installer stops when the two differ.
  3. Get the new release and run the installer. Run the installer command from the directory that holds your bundle directories, such as /opt/earnie. It downloads the newest release into earnie-vX.Y.Z beside the current one, pulls its images, and runs its installer.
    If the command ended with ready. Next: cd earnie-vX.Y.Z && ./install.sh instead, because it ran without a terminal, run that.
The installer takes tenant.env from the bundle directory Earnie runs from, adds any setting the new release introduces at its default, asks nothing, pulls the new images, and restarts Earnie. Database migrations run automatically, before the API starts accepting requests. While EARNIE_INITIAL_ADMIN_PASSWORD is still in tenant.env, the administrator’s password is set to it again. Keep the previous release’s directory until you’re sure the upgrade worked. You need it to roll back.

Check the Upgrade

In the STATUS column, every long-running service must show Up, with (healthy) where it has a health check. /healthz must answer with a success status. Then sign in and open a recent project to confirm that your data is there. If the services don’t come up, see Troubleshooting in Installing Earnie. If you can’t fix the problem, roll back.

Scans During a Restart

When Earnie stops, it first gives running scans time to finish. EARNIE_SHUTDOWN_DRAIN_SECONDS in tenant.env sets that time in whole seconds, and it’s 60 when unset. A scan still running near the end of that time is stopped and put back in the queue, and the interruption doesn’t count against the scan’s retries. If you run more than one Earnie server on the same database, another server picks the scan up within seconds. Otherwise it starts again when Earnie is back. Servers that share the database must also share the scan storage directory. See More than one Earnie server. A folder upload that is still in progress while you upgrade to a version that keeps upload progress in the database starts sending its files again when the client resumes. If no client resumes it, Earnie fails it after an hour without progress. Before it waits for scans, Earnie takes up to 30 seconds to close open connections. Whatever stops Earnie must therefore wait at least 30 seconds plus EARNIE_SHUTDOWN_DRAIN_SECONDS, plus a margin of about 30 seconds, before it kills the process:
  • The bundle. Docker Compose waits 120 seconds, which fits the default. Leave the setting unset.
  • An orchestrator such as Kubernetes. Kubernetes waits only 30 seconds unless you set terminationGracePeriodSeconds. Set it to at least 120 seconds for the default. If you raise EARNIE_SHUTDOWN_DRAIN_SECONDS, raise the grace period by the same amount.
A value that isn’t a whole number from 1 to 9999999 stops Earnie at startup, and the log names the setting.

Roll Back

You can’t downgrade the database. An older release refuses to start on a database that a newer release has upgraded: its migrate service exits with an error such as no migration found for version. While the newer release runs, an older bundle’s install.sh refuses with Earnie vX runs from ... and this bundle is vY, an older release: the database cannot go back. The steps below are the way past it: stop the newer release, restore the backup you took before the upgrade, then run the previous release’s installer. Anything that happened after the backup, such as scans and decisions, is lost. That is why you back up before every upgrade.
  1. Stop Earnie. From the new release’s bundle directory:
    This removes the containers but keeps all your data, which is in the data directory.
  2. Go to the previous release’s bundle directory, for example /opt/earnie/earnie-vA.B.C. Run the rest of the rollback from there.
  3. Restore the data directory and tenant.env. Empty the data directory, then extract the backup into it, so no file from after the backup stays behind. tar stored the paths without the leading /, so extract the data directory from /, and extract tenant.env into the current bundle directory:
    The chown matters: the installer refuses a tenant.env that belongs to root. Use the path and name of your backup file. For an Option 2 backup, it’s earnie-data-YYYY-MM-DD.tar.gz.
  4. Restore the database.
    • Bundled PostgreSQL, Option 1 backup: there is nothing more to do. The database files are in the data directory you just restored.
    • Bundled PostgreSQL, Option 2 backup: start only the database, which creates an empty one, and restore the pg_dump file into it:
    • Your own PostgreSQL server: restore into an empty database with pg_restore or your usual tool.
  5. Check the version. EARNIE_VERSION in the restored tenant.env must be empty or name the previous release.
  6. Run the installer:
  7. Check that Earnie is healthy, as in Check the Upgrade.

Restore on a New Server

To move Earnie to a new server, or to recover after losing one:
  1. Prepare the new server as in Prepare the host, and get the bundle for the release you backed up without running the installer yet. Install from the same release, not a newer one, then upgrade afterwards if you want to. Run the rest of these steps from the new bundle directory. Download and extract the bundle yourself, because the installer command would run the installer before your data is restored:
  2. Restore the data directory and tenant.env, as in step 3 of Roll back.
  3. Check the host-specific settings in the restored tenant.env, because the new server can differ from the old one:
    • DOCKER_GID and DOCKER_BRIDGE_IP. Clear them if they are set. The installer finds the new server’s values.
    • SCANS_SANDBOX_SUBNET, if the new server’s network already uses that range.
    • DB_URL, if the database moved too.
  4. Restore the database, as in step 4 of Roll back. With the bundled PostgreSQL and an Option 2 backup, first run ./render-env.sh. It writes the .env file that Docker Compose needs to start the database, which the installer would otherwise write later.
  5. Point the DNS name in EARNIE_HOST at the new server. If you use EARNIE_TLS=custom, the certificate files are in the data directory unless you set EARNIE_TLS_DIR elsewhere.
  6. Run ./install.sh, then check that Earnie is healthy, as in Check the Upgrade.
Keep the same EARNIE_SSO_KEK_HEX and EARNIE_INTEGRATIONS_KEK_HEX. Without them, Earnie can’t read the Git and single sign-on credentials stored in the restored database.

What’s Next