Facilitates automated backups with restic in a kubernetes cluster. The following documentation is a subsection of the readme from jupyterhub-rci-dev.
If the database gets nuked the backupcontainer can help restore it to a specific state. Backups are
made using pg_dump and then stored in an s3 bucket with restic; restic dump along
with pg_restore can bring the database back. Two scripts are in the container for convenience:
backup.sh and restore.sh, both are stored in /bin so they can be run anywhere.
The s3 bucket is under the tidesupport user with the bucket name sdsu-restic. The credentials for
the sdsu-restic user along with the restic repository password are stored in the secret
s3secret.
Any manual intervention requires remoting onto the backup container to utilize its scripts. Backups are automated and are set to run at 2am.
- Any file currently stored at
/backup/<db_name>_dump.tarwill be moved with a version number for archiving purposes. pg_dumpwith the custom format-F cflags is used to dump the state of the DB.restic backup /backup/<db_name>_dump.tarstores the information in the restic repository, in the s3 bucket.
Restoration is a partly manual process. The admin is required to get the proper version of the
/backup/<db_name>_dump.tar file in place that they want on the database, restore.sh will do
the rest.
- Remote onto the container with
kubectl get podsandkubectl exec -it <backup pod name> -- sh. - See what backups are available with
restic snapshots. - Restore the snapshot you want with
restic dump <snapshot id> /backup/<db_name>_dump.tar > /backup/<db_name>_dump.tar. Note: pg_restore may throw some errors, if you see "Restore.sh complete" that means it exited with a standard exit code and should have worked. - Call
restore.shto install the backup onto the database (usespg_restore).
Environment variables are used to pass configuration information to the container. Three parts must be configured: the postgres information, the S3 key id and access key, and finally the restic repository and password.
PGUSER: The username for the database. PGPASSWORD: The password for the database. PGDATABASE: The name of the database to save. PGHOST: The name of the host, this is passed as the -h flag to pg_dump. AWS_ACCESS_KEY_ID: The S3 bucket access key ID. AWS_SECRET_ACCESS_KEY: The key to the associated S3 bucket. RESTIC_REPOSITORY: The target for the restic repository. RESTIC_PASSWORD: The password for the restic repository.