Backing up and restoring CanDIG data
There are three kinds of data stored in CanDIG that we recommend backing up regularly.
- Clinical and Genomic metadata stored in CanDIG’s postgres databases
- Authorization data stored in vault that details user’s authorization to access/edit ingested data as well as the connection information for other nodes in the CanDIG network.
- Logs
For data types 1 and 2, we recommend taking back ups after each ingest event and to store one or more copies of your backups on a separate secure server from your CanDIG installation. We also recommend encrypting your backup so that it cannot be accessed by an unauthorized user.
Logs can be backed up on a regular schedule and at a minimum, should be saved elsewhere when performing a rebuild of the stack.
Backing up postgres databases
Section titled “Backing up postgres databases”Backups of the postgres databases can be created by running the make backup-all-postgres command. These will be created in the location specified by the value BACKUP_LOCATION in your .env file.
make backup-all-postgresYou should copy these from $BACKUP_LOCATION to a secure location and consider encrypting them or otherwise ensuring that unauthorized users will not have access to the information.
Restoring postgres databases
Section titled “Restoring postgres databases”You can restore the postgres databases using make commands as well. However, because the files in question can be very large and because overwriting the existing data can be very consequential, we have implemented a slightly more complex procedure.
There are currently four CanDIG modules that use postgres databases; these can be found in the CANDIG_DB_MODULES value in your .env file. They correspond to the following locations in your CanDIGv2 repo:
| Module | Database name | Directory location |
|---|---|---|
| drs | drs | lib/drs |
| htsget | genomic | lib/htsget |
| katsu | clinical | lib/katsu |
| rnaget | rnaget_db | lib/rnaget |
To restore each of these databases:
- The backup file to be restored must be de-encrypted and expanded into a
.sqlfile. - Create a file called
restore.txtin the module’s directory location, e.g.lib/drs/restore.txt. - The
restore.txtfile should contain the full path of the location of the backup file.
You can either run make restore-postgres-<module> to restore an individual database prepared in this way, or run make restore-all-postgres to restore all databases prepared in this way.
You should be able to see the restored data in the data portal.
Backing up Secrets and Authorization data
Section titled “Backing up Secrets and Authorization data”Secrets and Authorization data in CanDIG are stored within Vault. These should be backed up regularly so that they can be restored should there be a system crash and before the CanDIG stack is rebuilt. To back up Vault, run the command:
make backup-vaultThis command creates a tar ball at tmp/vault/backup.tar.gz. This should be saved into a secure location outside the server your CanDIG deployment is running. You may want to change the name of the backup to include the date and type of backup for future reference, e.g. YYYY-MM-DD-vault-backup.tar.gz
To restore the vault backup, copy the backup tarball into the vault directory in the CanDIG stack and rename it to restore.tar.gz:
cp /path/to/backup.tar.gz path/to/CanDIGv2/lib/vault/restore.tar.gzThen run
make restore-vaultAll previous secrets and authorizations should be restored to the stack. The tarball is renamed to restored.tar.gz and can be deleted.
Backing up logs
Section titled “Backing up logs”Logs are stored in tmp/logs. The contents of this folder should be saved periodically.
