π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Unwrap copycat-db README
Manav Rathi236d65f12470
diff --git a/infra/copycat-db/README.md b/infra/copycat-db/README.mdindex dd69b25587..8a1f6d3550 100644--- a/infra/copycat-db/README.md+++ b/infra/copycat-db/README.md@@ -1,23 +1,16 @@# Copycat DB-Copycat DB is a [service](../services/README.md) to take a backup of our-database. It uses the Scaleway CLI to take backups of the database, and uploads-them to an offsite bucket.+Copycat DB is a [service](../services/README.md) to take a backup of our database. It uses the Scaleway CLI to take backups of the database, and uploads them to an offsite bucket.-This bucket has an object lock configured, so backups cannot be deleted before-expiry. Conversely, the service also deletes backups older than some threshold-when it creates a new one to avoid indefinite retention.+This bucket has an object lock configured, so backups cannot be deleted before expiry. Conversely, the service also deletes backups older than some threshold when it creates a new one to avoid indefinite retention.In production the service runs as a cron job, scheduled using a systemd timer.-> These backups are in addition to the regular snapshots that we take, and are-> meant as a second layer of replication. For more details, see our-> [Reliability and Replication Specification](https://ente.com/reliability).+> These backups are in addition to the regular snapshots that we take, and are meant as a second layer of replication. For more details, see our [Reliability and Replication Specification](https://ente.com/reliability).## Quick help-View service status (it gets invoked as a timer automatically, doesn't need to-be started/stopped manually):+View service status (it gets invoked as a timer automatically, doesn't need to be started/stopped manually):```shsudo systemctl status copycat-db@@ -31,28 +24,19 @@ sudo tail /root/var/logs/copycat-db.log## Name-The name copycat-db is a riff on "copycat", which is what we call our museum-instance that does the object replication. This one replicates the DB, so,-copycat-db.+The name copycat-db is a riff on "copycat", which is what we call our museum instance that does the object replication. This one replicates the DB, so, copycat-db.## Backup ModeCopycat DB requires an explicit `BACKUP_MODE`:- `scw-export`: take a Scaleway-managed backup directly from `SCW_RDB_INSTANCE_ID`-- `snapshot-scw-export`: restore the latest snapshot into `copycat-db-temp`, take- a Scaleway-managed backup from that temporary instance, then delete it-- `snapshot-pgdump`: restore the latest snapshot into `copycat-db-temp`, attach- it to `SCW_PRIVATE_NETWORK_ID`, run `pg_dump` over the private endpoint,- package the dump, then delete the temporary instance+- `snapshot-scw-export`: restore the latest snapshot into `copycat-db-temp`, take a Scaleway-managed backup from that temporary instance, then delete it+- `snapshot-pgdump`: restore the latest snapshot into `copycat-db-temp`, attach it to `SCW_PRIVATE_NETWORK_ID`, run `pg_dump` over the private endpoint, package the dump, then delete the temporary instance-To use a snapshot-backed mode in production, set `BACKUP_MODE` accordingly in-`/root/copycat-db.env` and then start the service or let the timer run it.+To use a snapshot-backed mode in production, set `BACKUP_MODE` accordingly in `/root/copycat-db.env` and then start the service or let the timer run it.-This path is intentionally conservative about cleanup. If something fails before-the final explicit delete, the script leaves the temporary instance behind-instead of attempting automatic cleanup during error handling. This is done to-avoid accidental deletions if the script ends up in an unexpected state.+This path is intentionally conservative about cleanup. If something fails before the final explicit delete, the script leaves the temporary instance behind instead of attempting automatic cleanup during error handling. This is done to avoid accidental deletions if the script ends up in an unexpected state.If that happens, clean it up manually in the Scaleway dashboard by deleting the DB instance named `copycat-db-temp`.@@ -60,18 +44,15 @@ If that happens, clean it up manually in the Scaleway dashboard by deleting the##### BACKUP_MODE-Required. See the **Backup Mode** section above for the available values and-their behaviour.+Required. See the **Backup Mode** section above for the available values and their behaviour.##### SCW_CONFIG_PATHPath to the `config.yaml` used by Scaleway CLI.-This contains the credentials and the default region to use when trying to-create and download the database dump.+This contains the credentials and the default region to use when trying to create and download the database dump.-If needed, this config file can be generated by running the following commands-on a shell prompt in the container (using `./test.sh sh`)+If needed, this config file can be generated by running the following commands on a shell prompt in the container (using `./test.sh sh`)scw initscw config dump@@ -84,24 +65,19 @@ The UUID of the Scalway RDB instance that we wish to backup.Required when `BACKUP_MODE=snapshot-pgdump`.-This is the UUID of the Private Network that copycat-db should attach to the-temporary restored Database Instance before running `pg_dump`.+This is the UUID of the Private Network that copycat-db should attach to the temporary restored Database Instance before running `pg_dump`.-The compute instance running copycat-db must also be attached to this Private-Network.+The compute instance running copycat-db must also be attached to this Private Network.##### PGUSER, PGPASSWORD-Not needed in production when taking a backup (since we use the Scaleway CLI to-take backups in production).+Not needed in production when taking a backup (since we use the Scaleway CLI to take backups in production).-These are used when taking a `snapshot-pgdump` backup, and when restoring-backups. The host and port are resolved by the scripts.+These are used when taking a `snapshot-pgdump` backup, and when restoring backups. The host and port are resolved by the scripts.##### RCLONE_CONFIG-Location of the config file, that contains the destination bucket where you want-to use to save the backups, and the credentials to to access it.+Location of the config file, that contains the destination bucket where you want to use to save the backups, and the credentials to to access it.Specifically, the config file contains two remotes:@@ -109,10 +85,7 @@ Specifically, the config file contains two remotes:- A "crypt" remote that wraps the bucket by applying client side encryption.-The configuration file will contain (lightly) obfuscated versions of the-password, and as long as we have the configuration file we can continue using-rclone to download and decrypt the plaintext. Still, it is helpful to retain the-original password too separately so that the file can be recreated if needed.+The configuration file will contain (lightly) obfuscated versions of the password, and as long as we have the configuration file we can continue using rclone to download and decrypt the plaintext. Still, it is helpful to retain the original password too separately so that the file can be recreated if needed.A config file can be generated using `./test.sh sh`@@ -121,26 +94,21 @@ A config file can be generated using `./test.sh sh`When generating the config, we keep file (and directory) name encryption off.-Note that rclone creates a backup of the config file, so Docker needs to have-write access to the directory where it is mounted.+Note that rclone creates a backup of the config file, so Docker needs to have write access to the directory where it is mounted.##### RCLONE_DESTINATION-Name of the (crypt) remote to which the dump should be saved. Example:-`db-backup-crypt:`.+Name of the (crypt) remote to which the dump should be saved. Example: `db-backup-crypt:`.-Note that this will not include the bucket - the bucket name will be part of the-remote that the crypt remote wraps.+Note that this will not include the bucket - the bucket name will be part of the remote that the crypt remote wraps.##### Logging-The service logs to its standard out/error. The systemd unit is configured to-route these to `/var/logs/copycat-db.log`.+The service logs to its standard out/error. The systemd unit is configured to route these to `/var/logs/copycat-db.log`.## Local testing-The provided `test.sh` script can be used to do a smoke test for building and-running the image. For example,+The provided `test.sh` script can be used to do a smoke test for building and running the image. For example,./test.sh bin/bash@@ -150,24 +118,17 @@ For more thorough testing, run this service as part of a local test-cluster.## Restoring-The service also knows how to restore the latest backup into a Postgres-instance. This functionality by a separate service (Phoenix) to periodically-verify that the backups are restorable.+The service also knows how to restore the latest backup into a Postgres instance. This functionality by a separate service (Phoenix) to periodically verify that the backups are restorable.-To invoke this, use "./restore.sh" as the command when running the container-(e.g. `./test.sh ./restore.sh`). This will restore the latest backup into the-Postgres instance whose credentials are provided via the various `PG*`-environment variables.+To invoke this, use "./restore.sh" as the command when running the container (e.g. `./test.sh ./restore.sh`). This will restore the latest backup into the Postgres instance whose credentials are provided via the various `PG*` environment variables.## Preparing the bucket-The database dumps are stored in a bucket that has object lock enabled-(compliance mode), and has a default bucket level retention time of 30 days.+The database dumps are stored in a bucket that has object lock enabled (compliance mode), and has a default bucket level retention time of 30 days.## Deploying-Ensure that promtail is running, and is configured to scrape-`/root/var/logs/copycat-db.log`.+Ensure that promtail is running, and is configured to scrape `/root/var/logs/copycat-db.log`.Create that the config and log destination directories@@ -192,16 +153,12 @@ To start the cron jobsudo systemctl start copycat-db.timer-The timer will trigger the service on the specified schedule. In addition, if-you wish to force the job to service immediately+The timer will trigger the service on the specified schedule. In addition, if you wish to force the job to service immediatelysudo systemctl start copycat-db.service## Updating-To update, run the-[GitHub workflow](../../.github/workflows/copycat-db-release.yaml) to build and-push the latest image to our Docker Registry, then restart the systemd service-on the instance+To update, run the [GitHub workflow](../../.github/workflows/copycat-db-release.yaml) to build and push the latest image to our Docker Registry, then restart the systemd service on the instancesudo systemctl restart copycat-db