{"id":27014962,"url":"https://github.com/nuvo/cain","last_synced_at":"2025-08-03T03:38:00.769Z","repository":{"id":33326757,"uuid":"147207547","full_name":"nuvo/cain","owner":"nuvo","description":"Backup and restore tool for Cassandra on Kubernetes","archived":false,"fork":false,"pushed_at":"2024-06-12T16:52:19.000Z","size":128,"stargazers_count":31,"open_issues_count":13,"forks_count":21,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-30T12:45:53.047Z","etag":null,"topics":["abs","aws","azure","azure-blob-storage","backup","cain","cassandra","go","golang","helm","kubernetes","restore","s3","schema","snapshot"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuvo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-03T13:18:04.000Z","updated_at":"2024-12-14T15:35:24.000Z","dependencies_parsed_at":"2024-04-21T15:06:53.854Z","dependency_job_id":"550ba0fb-8a54-4ebb-96ad-0268492a5289","html_url":"https://github.com/nuvo/cain","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuvo%2Fcain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuvo%2Fcain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuvo%2Fcain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuvo%2Fcain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuvo","download_url":"https://codeload.github.com/nuvo/cain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190253,"owners_count":20898702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abs","aws","azure","azure-blob-storage","backup","cain","cassandra","go","golang","helm","kubernetes","restore","s3","schema","snapshot"],"created_at":"2025-04-04T14:15:42.407Z","updated_at":"2025-04-04T14:15:42.875Z","avatar_url":"https://github.com/nuvo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Release](https://img.shields.io/github/release/nuvo/cain.svg)](https://github.com/nuvo/cain/releases)\n[![Travis branch](https://img.shields.io/travis/nuvo/cain/master.svg)](https://travis-ci.org/nuvo/cain)\n[![Docker Pulls](https://img.shields.io/docker/pulls/nuvo/cain.svg)](https://hub.docker.com/r/nuvo/cain/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nuvo/cain)](https://goreportcard.com/report/github.com/nuvo/cain)\n[![license](https://img.shields.io/github/license/nuvo/cain.svg)](https://github.com/nuvo/cain/blob/master/LICENSE)\n\n# Cain\n\nCain is a backup and restore tool for Cassandra on Kubernetes. It is named after the DC Comics superhero [Cassandra Cain](https://en.wikipedia.org/wiki/Cassandra_Cain).\n\nCain supports the following cloud storage services:\n\n* AWS S3\n* Minio S3\n* Azure Blob Storage\n\nCain is now an official part of the Helm [incubator/cassandra](https://github.com/helm/charts/tree/master/incubator/cassandra) chart!\n\n## Install\n\n### Prerequisites\n\n1. git\n2. [dep](https://github.com/golang/dep)\n\n### From a release\n\nDownload the latest release from the [Releases page](https://github.com/nuvo/cain/releases) or use it with a [Docker image](https://hub.docker.com/r/nuvo/cain)\n\n### From source\n\n```\nmkdir -p $GOPATH/src/github.com/nuvo \u0026\u0026 cd $_\ngit clone https://github.com/nuvo/cain.git \u0026\u0026 cd cain\nmake\n```\n\n## Commands\n\n### Backup Cassandra cluster to cloud storage\n\nCain performs a backup in the following way:\n1. Backup the `keyspace` schema (using `cqlsh`).\n1. Get backup data using `nodetool snapshot` - it creates a snapshot of the `keyspace` in all Cassandra pods in the given `namespace` (according to `selector`).\n2. Copy the files in `parallel` to cloud storage using [Skbn](https://github.com/nuvo/skbn) - it copies the files to the specified `dst`, under `namespace/\u003ccassandrClusterName\u003e/keyspace/\u003ckeyspaceSchemaHash\u003e/tag/`.\n3. Clear all snapshots.\n\n#### Usage\n\n```\n$ cain backup --help\nbackup cassandra cluster to cloud storage\n\nUsage:\n  cain backup [flags]\n\nFlags:\n  -a, --authentication                     use authentication for nodetool and clqsh. Overrides $CAIN_AUTHENTICATION\n  -b, --buffer-size float                  in memory buffer size (MB) to use for files copy (buffer per file). Overrides $CAIN_BUFFER_SIZE (default 6.75)\n      --cassandra-data-dir string          cassandra data directory. Overrides $CAIN_CASSANDRA_DATA_DIR (default \"/var/lib/cassandra/data\")\n  -u, --cassandra-username string          cassandra username. Overrides $CAIN_CASSANDRA_USERNAME (default \"cain\")\n  -c, --container string                   container name to act on. Overrides $CAIN_CONTAINER (default \"cassandra\")\n      --dst string                         destination to backup to. Example: s3://bucket/cassandra. Overrides $CAIN_DST\n  -h, --help                               help for backup\n  -k, --keyspace string                    keyspace to act on. Overrides $CAIN_KEYSPACE\n  -n, --namespace string                   namespace to find cassandra cluster. Overrides $CAIN_NAMESPACE (default \"default\")\n      --nodetool-credentials-file string   path to nodetool credentials file. Overrides $CAIN_NODETOOL_CREDENTIALS_FILE (default \"/home/cassandra/.nodetool/credentials\")\n  -p, --parallel int                       number of files to copy in parallel. set this flag to 0 for full parallelism. Overrides $CAIN_PARALLEL (default 1)\n  -m, --s3-max-upload-parts int            maximum number of parts to upload in parallel for s3 multipart upload. Overrides $CAIN_S3_MAX_UPLOAD_PARTS (default 10000)\n  -s, --s3-part-size int                   size of each part in bytes for s3 multipart upload. Overrides $CAIN_S3_PART_SIZE (default 134217728)\n  -l, --selector string                    selector to filter on. Overrides $CAIN_SELECTOR (default \"app=cassandra\")\n```\n\n#### Examples\n\nBackup to AWS S3\n\n```\ncain backup \\\n    -n default \\\n    -l release=cassandra \\\n    -k keyspace \\\n    --dst s3://db-backup/cassandra\n```\n\nBackup to AWS S3 with Cassandra authentication enabled\n\n```\ncain backup \\\n    -n default \\\n    -l release=cassandra \\\n    -k keyspace \\\n    --dst s3://db-backup/cassandra\n    -a\n    -u cain\n    --nodetool-credentials-file /home/cassandra/.nodetool/credentials\n```\n\nBackup to Azure Blob Storage\n\n```\ncain backup \\\n    -n default \\\n    -l release=cassandra \\\n    -k keyspace \\\n    --dst abs://my-account/db-backup-container/cassandra\n```\n\n### Restore Cassandra backup from cloud storage\n\nCain performs a restore in the following way:\n1. Restore schema if `schema` is specified.\n2. Truncate all tables in `keyspace`.\n3. Copy files from the specified `src` (under `keyspace/\u003ckeyspaceSchemaHash\u003e/tag/`) - restore is only possible for the same keyspace schema.\n4. Load new data using `nodetool refresh`.\n\n#### Usage\n\n```\n$ cain restore --help\nrestore cassandra cluster from cloud storage\n\nUsage:\n  cain restore [flags]\n\nFlags:\n  -a, --authentication                     use authentication for nodetool and clqsh. Overrides $CAIN_AUTHENTICATION\n  -b, --buffer-size float                  in memory buffer size (MB) to use for files copy (buffer per file). Overrides $CAIN_BUFFER_SIZE (default 6.75)\n      --cassandra-data-dir string          cassandra data directory. Overrides $CAIN_CASSANDRA_DATA_DIR (default \"/var/lib/cassandra/data\")\n  -u, --cassandra-username string          cassandra username. Overrides $CAIN_CASSANDRA_USERNAME (default \"cain\")\n  -c, --container string                   container name to act on. Overrides $CAIN_CONTAINER (default \"cassandra\")\n  -h, --help                               help for restore\n  -k, --keyspace string                    keyspace to act on. Overrides $CAIN_KEYSPACE\n  -n, --namespace string                   namespace to find cassandra cluster. Overrides $CAIN_NAMESPACE (default \"default\")\n  -f, --nodetool-credentials-file string   path to nodetool credentials file. Overrides $CAIN_NODETOOL_CREDENTIALS_FILE (default \"/home/cassandra/.nodetool/credentials\")\n  -p, --parallel int                       number of files to copy in parallel. set this flag to 0 for full parallelism. Overrides $CAIN_PARALLEL (default 1)\n  -s, --schema string                      schema version to restore (optional). Overrides $CAIN_SCHEMA\n  -l, --selector string                    selector to filter on. Overrides $CAIN_SELECTOR (default \"app=cassandra\")\n      --src string                         source to restore from. Example: s3://bucket/cassandra/namespace/cluster-name. Overrides $CAIN_SRC\n  -t, --tag string                         tag to restore. Overrides $CAIN_TAG\n      --user-group string                  user and group who should own restored files. Overrides $CAIN_USER_GROUP (default \"cassandra:cassandra\")\n```\n\n#### Examples\n\nRestore from S3\n\n```\ncain restore \\\n    --src s3://db-backup/cassandra/default/ring01\n    -n default \\\n    -k keyspace \\\n    -l release=cassandra \\\n    -t 20180903091624\n```\n\nRestore from Azure Blob Storage\n\n```\ncain restore \\\n    --src s3://my-account/db-backup-container/cassandra/default/ring01\n    -n default \\\n    -k keyspace \\\n    -l release=cassandra \\\n    -t 20180903091624\n```\n\n### Describe keyspace schema\n\nCain describes the `keyspace` schema using `cqlsh`. It can return the schema itself, or a checksum of the schema file (used by `backup` and `restore`).\n\n#### Usage\n\n```\n$ cain schema --help\nget schema of cassandra cluster\n\nUsage:\n  cain schema [flags]\n\nFlags:\n  -c, --container string   container name to act on. Overrides $CAIN_CONTAINER (default \"cassandra\")\n  -k, --keyspace string    keyspace to act on. Overrides $CAIN_KEYSPACE\n  -n, --namespace string   namespace to find cassandra cluster. Overrides $CAIN_NAMESPACE (default \"default\")\n  -l, --selector string    selector to filter on. Overrides $CAIN_SELECTOR (default \"app=cassandra\")\n      --sum                print only checksum. Overrides $CAIN_SUM\n```\n\n#### Examples\n\n```\ncain schema \\\n    -n default \\\n    -l release=cassandra \\\n    -k keyspace\n```\n```\ncain schema \\\n    -n default \\\n    -l release=cassandra \\\n    -k keyspace \\\n    --sum\n```\n\n## Environment variables support\n\nCain commands support the usage of environment variables instead of flags. For example:\nThe `backup` command can be executed as mentioned in the example:\n\n```\ncain backup \\\n    -n default \\\n    -l release=cassandra \\\n    -k keyspace \\\n    --dst s3://db-backup/cassandra\n```\n\nYou can also set the appropriate envrionment variables (CAIN_FLAG, _ instead of -):\n\n```\nexport CAIN_NAMESPACE=default\nexport CAIN_SELECTOR=release=cassandra\nexport CAIN_KEYSPACE=keyspace\nexport CAIN_DST=s3://db-backup/cassandra\n\ncain backup\n```\n\n## Support for additional storage services\n\nSince Cain uses [Skbn](https://github.com/nuvo/skbn), adding support for additional storage services is simple. Read [this post](https://medium.com/nuvo-group-tech/copy-files-and-directories-between-kubernetes-and-s3-d290ded9a5e0) for more information.\n\n## Skbn compatibility matrix\n\n| Cain version | Skbn version |\n|--------------|--------------|\n| 0.5.3        | 0.5.1        |\n| 0.5.2        | 0.4.2        |\n| 0.5.1        | 0.4.2        |\n| 0.5.0        | 0.4.1        |\n| 0.4.2        | 0.4.1        |\n| 0.4.1        | 0.4.1        |\n| 0.4.0        | 0.4.0        |\n| 0.3.0        | 0.3.0        |\n| 0.2.0        | 0.2.0        |\n| 0.1.0        | 0.1.1        |\n\n## Credentials\n\n\n### Kubernetes\n\nCain tries to get credentials in the following order:\n1. if `KUBECONFIG` environment variable is set - skbn will use the current context from that config file\n2. if `~/.kube/config` exists - skbn will use the current context from that config file with an [out-of-cluster client configuration](https://github.com/kubernetes/client-go/tree/master/examples/out-of-cluster-client-configuration)\n3. if `~/.kube/config` does not exist - skbn will assume it is working from inside a pod and will use an [in-cluster client configuration](https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration)\n\n\n### AWS\n\nSkbn uses the default AWS [credentials chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html).\n\n### Azure Blob Storage\n\nSkbn uses `AZURE_STORAGE_ACCOUNT` and `AZURE_STORAGE_ACCESS_KEY` environment variables for authentication.\n\n### Cassandra Credentials\nWhen Authentication is enabled Cain will look for default credentials   \nfor `cqlsh` in `/home/cassandra/.cassandra/credentials`   \nif you use authentication please make sure the cassandra   \ncontainer has this file and the username and password are correct.   \n     \nFor `nodetool` authentications default credentials are in:   \n`/home/cassandra/.nodetool/credentials` can be overridden by    \nsetting the `--nodetool-credentials-file` flag.    \nWhen this flag is used, the username for the nodetool    \nauthentication must be provided as well .   \n\n## Examples\n\n1. [Helm example](/examples/helm)\n2. [Code example](/examples/code)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuvo%2Fcain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuvo%2Fcain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuvo%2Fcain/lists"}