Skip to main content

Backup and Restore

Backups are copied off the machine they protect: to another disk, an NFS mount or an S3 bucket. A backup that sits on the failed disk is no backup, which is why every install must choose a destination.

What a backup holds​

Each run writes one set, odin-backup-<UTC timestamp>/, which lands whole or not at all:

PartWhat it is
odin-postgres.dump, odin-postgres-globals.sqlA pg_dump of the application database, and its roles with their password hashes
minio/Every bucket of the bundled MinIO: the uploaded files
escrow/The generated-credentials manifest, the k3s server/token and /etc/odin/install.env, which rebuilding on new hardware needs. File mode 0600
set-info.envThe host and k3s node the set was taken on
k3s-server-db/, k3s-server-tokenk3s's own datastore, which needs k3s stopped for a few seconds
COMPLETEWritten last; a set without it is ignored by a restore

Parts that live outside the cluster, your own S3 (--s3-endpoint) or your own PostgreSQL (--db-url), are not in the sets. Your own backups cover them. Where the bundled PostgreSQL and MinIO are in use, a failed dump or file mirror fails the whole run, so a set is never completed without them.

warning

A backup set contains secrets and customer data. Protect the destination like a credential store, and keep the escrow/ copy where the loss of the machine's site cannot reach it.

Scheduled backups​

With --backup-dest, the installer creates two systemd timers:

TimerRunsEffect
odin-backup.timerDaily, or hourly with --backup-schedule hourlyDatabase and files. Never stops k3s
odin-backup-datastore.timerDaily, whatever the scheduleAdds the k3s datastore, which stops k3s for a few seconds. Expect a short outage at that time

The timers keep the newest 7 sets of each kind. sudo ./install.sh status shows both timers and the age of the last good backup, and reports a backup older than 26 hours (2 hours when hourly) as unhealthy.

systemctl list-timers 'odin-backup*'
journalctl -u odin-backup -u odin-backup-datastore

Choosing a destination

  • A directory on another disk or an NFS mount, or s3://bucket/prefix together with --backup-s3-creds FILE. With your own S3 (--s3-endpoint), an s3:// destination is on that same S3; otherwise it is on AWS S3, which an air-gapped machine cannot reach. There is no separate endpoint for the backups.
  • Give each install a destination of its own.
  • If /etc/fstab mounts a directory destination, the installer insists it is mounted, so a backup cannot silently fill the machine's own disk.
  • With an s3:// destination, a set is staged under /var/tmp before upload (the files go straight from MinIO). Keep free space there for one set.

Back up now​

Run backup.sh from the extracted tarball directory, as root:

sudo ./backup.sh --dest /mnt/odin-backups
sudo ./backup.sh --dest s3://bucket/prefix --s3-creds /root/backup-s3.env \
--s3-endpoint https://s3.corp.example

Run by hand, backup.sh goes to AWS S3 unless you give --s3-endpoint. The scheduled backups pass your install's endpoint themselves, so give the same one here; leave it out only when the destination really is on AWS. After a backup to S3, backup.sh prints the restore.sh command that fits.

--datastore=skip leaves the k3s datastore out (so k3s keeps running), --minio=skip leaves the files out, and --keep N keeps the newest N sets.

Restore​

warning

restore.sh is destructive. It overwrites the application database, and writes every file in the set over the file of the same name. Use it for disaster recovery, not routine use.

sudo ./restore.sh --from /mnt/odin-backups
sudo ./restore.sh --from /mnt/odin-backups/odin-backup-<timestamp>
sudo ./restore.sh --from s3://bucket/prefix --s3-creds /root/backup-s3.env \
--s3-endpoint https://s3.corp.example

An s3:// source is looked up on AWS S3 unless --s3-endpoint names another S3. On an install with its own S3, that is where the scheduled backups are, so give its endpoint.

restore.sh restores a set into the install that is running. --from takes a set, or a destination, in which case the newest complete set is restored. It asks before it overwrites anything, and the answer defaults to No; --yes skips the question, which is what a scripted disaster-recovery drill wants. --minio=skip leaves the uploaded files out. A restore that stops part way says which parts it had already overwritten; running it again with the same set is safe.

What it puts back:

  • The database: its roles first, then the dump. EKB's services are stopped while the database is replaced and started again afterwards, also when the restore fails.
  • The uploaded files, into the bundled MinIO. This needs the MinIO client, which the tarball ships as tools/mc.
  • The k3s datastore, only if you ask for it with --datastore=restore, and only on the machine the set was taken on. A datastore names the machine and its volumes, so it does not fit another one.

restore.sh refuses, before it changes anything, to restore a database into an install whose generated credentials are not the ones the backup was taken with. The stored toolkit credentials in the database are encrypted with those credentials, so the result would not work. It prints the steps below instead, and names the keys that differ (never their values). A key that only this install has, one added after the backup was taken such as the mail encryption key, does not count: the backup is still accepted, with one informational line.

Recovering from the loss of the machine​

A replacement machine is rebuilt from the credentials saved in the backup set. The order matters: they go in before the install, so the new install keeps the old one's keys instead of generating its own.

# on the replacement machine, from the extracted tarball of the same release
sudo ./restore.sh --extract-secrets --from /mnt/odin-backups
sudo ./install.sh --domain odin.corp.example \
--tls-cert /etc/ssl/odin.crt --tls-key /etc/ssl/odin.key \
--backup-dest /mnt/odin-backups
sudo ./restore.sh --from /mnt/odin-backups
sudo ./install.sh status
  1. --extract-secrets restores nothing. It puts the set's saved credentials where the installer looks for them, moves a leftover /etc/odin/site-values.yaml of the removed install to site-values.yaml.previous so the new install does not apply its values, and holds this machine's backups until step 3 is done.
  2. Install the same release, with the settings of the original install. The set's escrow/install.env lists them, and the certificate and credential files it names must exist on the new machine (see Install). Wait until status shows the chart rolled out and every workload Ready.
  3. Restore the database and the files. This lifts the hold on the backups.
  4. Check status, log in, and spot-check an uploaded file.

Between steps 1 and 3 the new install is empty, while its backup timers already point at the old install's destination. A backup of it would look like a good one and push out the sets that hold your data. So step 1 writes /etc/odin/restore-pending, and backup.sh refuses to run while that file exists: scheduled backups fail during the rebuild, and so does the backup an upgrade takes first. This is intended. A restore that leaves the files out (--minio=skip) keeps the hold and says how to lift it: restore the files too, or delete the file if the install is meant to go on without them.

note

This procedure has not been rehearsed on real machines by Automation Anywhere yet. Rehearse it on a spare machine, from a real backup set, before you need it, and involve Support for a real recovery.

What you can lose​

On a single machine, a restore returns the database to the last pg_dump: up to a day with the daily schedule, up to an hour with the hourly one. There is no point-in-time restore. Choose the hourly schedule if a day is too much.

Clusters​

On a cluster every server has the two backup timers, and one server runs each window's backup: it takes a k3s etcd snapshot and a pg_dump from the database's primary (never through the pooler), and the others find the window taken. The window is the host's local day (or hour), so give every server the same time zone. The window's lock is one ConfigMap per destination, so servers that back up to different destinations do not wait for each other. A server that finds the window already backed up does nothing. One that finds it taken and still at work waits for it (up to 2 hours with the daily schedule, 40 minutes with the hourly one) and then fails, which raises the odin-backup-failed alert until the holder's backup lands; a window whose holder died is taken over by the next run once it is more than 6 hours old, or at once if the dead run was on the same server. k3s also snapshots etcd every 6 hours on every server, and uploads the snapshots to your S3 when the backup destination is an s3:// one. A backup set's escrow/ holds the generated secrets (including the key that encrypts saved mail passwords, read from the cluster's own Secrets, not from a file on the first server), the cluster's settings and the tokens: protect the destination like a credential store.

A directory destination must be shared storage. Only one server makes each window's backup, so a directory --backup-dest has to be the same storage on every server: mount the same NFS export at the same path on each one (/etc/fstab). Then give --backup-dest once, on any one server where it is mounted (sudo ./install.sh --backup-dest /mnt/odin-backups): that server vouches for the mount and writes a small marker, .odin-install-<cluster id>, into it, as soon as the cluster has an id. The other servers only check for it. A server that joins, and its scheduled backups, refuse a directory without it, because on a disk of its own the window's only set would be missing from the real destination; a joining server waits up to 2 minutes (ODIN_BACKUP_MARKER_WAIT_SECONDS) for the marker before it stops. This also works after the first server has been replaced. If a server stops with "is not shown to be the storage the other servers back up to", mount the share, run sudo ./install.sh --backup-dest <dir> on one server where it is mounted, and run the failed command again. An s3:// destination needs no marker. For a bucket outside k3s's default region, give --backup-s3-region at install (and --s3-region to backup.sh and restore.sh).

If a backup fails with "the window's backup is not complete", look at systemctl status odin-backup.service on the server it names. If that run is gone, kubectl -n kube-system delete configmap odin-backup-<full|data>-<window>-<destination tag> frees the window (there is one lock per destination; the full name is in the error message, or in kubectl -n kube-system get configmap | grep odin-backup-), and sudo systemctl start odin-backup.service takes it.

To restore into the clustered database, restore.sh --pg-target=auto (the default) puts the dump into its primary. To restore etcd, restore.sh --etcd-snapshot <file> runs on one server after k3s has been stopped on every other server; that server becomes the cluster's first server, and the others rejoin with rm -rf /var/lib/rancher/k3s/server/db and sudo ./install.sh --join <API address>. This has not been drilled on real machines yet. Point-in-time restore of the clustered database is planned and does not exist yet. See High availability (summary).