- Back up Earnie, before every upgrade and on a regular schedule.
- Upgrade to a new release.
- Roll back to the previous release if an upgrade goes wrong.
- Restore on a new server to move Earnie or recover after losing a server.
/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.-
Stop the services:
-
Copy the data directory and
tenant.envto your backup location. For example:If you use your own PostgreSQL server, also take a backup of the database with your usual tool, for examplepg_dump, while Earnie is stopped. -
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.-
Dump the database with
pg_dump. For the bundled PostgreSQL:Use the values ofONPREM_PG_USERandONPREM_PG_DBif you changed them fromearnie. For your own PostgreSQL server: -
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. Thepg_dumpfile 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:
- 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.
-
Check
EARNIE_VERSION. If an earlier release had you setEARNIE_VERSIONintenant.env, clear it. The bundle knows its own release, and the installer stops when the two differ. -
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 intoearnie-vX.Y.Zbeside the current one, pulls its images, and runs its installer.If the command ended withready. Next: cd earnie-vX.Y.Z && ./install.shinstead, because it ran without a terminal, run that.
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
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 raiseEARNIE_SHUTDOWN_DRAIN_SECONDS, raise the grace period by the same amount.
Roll Back
You can’t downgrade the database. An older release refuses to start on a database that a newer release has upgraded: itsmigrate 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.
-
Stop Earnie. From the new release’s bundle directory:
This removes the containers but keeps all your data, which is in the data directory.
-
Go to the previous release’s bundle directory, for example
/opt/earnie/earnie-vA.B.C. Run the rest of the rollback from there. -
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.tarstored the paths without the leading/, so extract the data directory from/, and extracttenant.envinto the current bundle directory:Thechownmatters: the installer refuses atenant.envthat belongs toroot. Use the path and name of your backup file. For an Option 2 backup, it’searnie-data-YYYY-MM-DD.tar.gz. -
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_dumpfile into it: -
Your own PostgreSQL server: restore into an empty database with
pg_restoreor your usual tool.
-
Check the version.
EARNIE_VERSIONin the restoredtenant.envmust be empty or name the previous release. -
Run the installer:
- 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:-
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:
-
Restore the data directory and
tenant.env, as in step 3 of Roll back. -
Check the host-specific settings in the restored
tenant.env, because the new server can differ from the old one:DOCKER_GIDandDOCKER_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.
-
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.envfile that Docker Compose needs to start the database, which the installer would otherwise write later. -
Point the DNS name in
EARNIE_HOSTat the new server. If you useEARNIE_TLS=custom, the certificate files are in the data directory unless you setEARNIE_TLS_DIRelsewhere. -
Run
./install.sh, then check that Earnie is healthy, as in Check the Upgrade.
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
- Releases and release notes covers the stable channel, the release feed, and the opt-in release check.
- Installing Earnie covers configuration and TLS.
- Self-hosting requirements lists the disk space your backups need to cover.