|
| 1 | +# Take a backup |
| 2 | + |
| 3 | +The `backup.sh` script is designed to create a job for taking snapshot of `etcd` instance. The script generates Kubernetes Job manifests and applies them to the specified namespace. |
| 4 | + |
| 5 | +## Overview |
| 6 | +The script performs the following steps: |
| 7 | + |
| 8 | +1. Creates a Kubernetes Job manifests from one of the `etcd` members. |
| 9 | +2. The job takes a snapshot of the `etcd` member and uploads it to a s3-like storage. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- Ensure you have `kubectl` installed and configured to interact with the management cluster. |
| 14 | +- It is assumed that the snapshot files will be stored on an S3-like storage. |
| 15 | +- A kubernetes secret called `backup-storage-secret` containing the parameters and credentials to access the storage must be created in the same namespace where `kamaji-etcd` is running. |
| 16 | + |
| 17 | +### Creating the Secret |
| 18 | + |
| 19 | +To create the secret, use the following command: |
| 20 | + |
| 21 | +```bash |
| 22 | +kubectl create secret generic backup-storage-secret \ |
| 23 | + --from-literal=storage-url=<storage_url> \ |
| 24 | + --from-literal=storage-access-key=<access_key> \ |
| 25 | + --from-literal=storage-secret-key=<access_secret> \ |
| 26 | + --from-literal=storage-bucket-name=<bucket_name> \ |
| 27 | + --from-literal=storage-bucket-folder=<bucket_folder> \ |
| 28 | + -n <etcd_namespace> |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | +To run the script, use the following command: |
| 33 | + |
| 34 | +```bash |
| 35 | +./backup.sh [-e etcd_name] [-s etcd_client_service] [-n etcd_namespace] |
| 36 | +``` |
| 37 | + |
| 38 | +### Parameters |
| 39 | + |
| 40 | +- `-e etcd_name`: Name of the etcd StatefulSet (default: `kamaji-etcd`) |
| 41 | +- `-s etcd_client_service`: Name of the etcd client service (default: `kamaji-etcd-client`) |
| 42 | +- `-n etcd_namespace`: Namespace of the etcd StatefulSet (default: `kamaji-system`) |
| 43 | + |
| 44 | +### Example |
| 45 | + |
| 46 | +To run the script with custom parameters: |
| 47 | + |
| 48 | +```bash |
| 49 | +./backup.sh -e kamaji-etcd -s kamaji-etcd-client -n kamaji-system |
| 50 | +``` |
| 51 | + |
| 52 | +This will create a Kubernetes Job manifest with the specified parameters and apply it to the cluster. The job will take a snapshot of the `etcd` member and upload it to the specified S3-like storage. |
| 53 | + |
| 54 | +### Notes |
| 55 | + |
| 56 | +- Ensure you have access a s3-like storage and the necessary secret `backup-storage-secret` is configured in Kubernetes. |
| 57 | +- The script uses `kubectl` commands, so ensure you have the necessary permissions to perform these operations. |
| 58 | + |
| 59 | +### Debug mode |
| 60 | +To run the script in debug mode set the environment variable `DEBUG`: |
| 61 | + |
| 62 | +``` bash |
| 63 | +export DEBUG=1 |
| 64 | +``` |
| 65 | + |
| 66 | +## Schedule recurring backups |
| 67 | +To schedule recurring backups with CronJobs, use the `schedule.sh` script. The script generates Kubernetes CronJob manifests and applies them to the specified namespace. |
| 68 | + |
| 69 | +### Usage |
| 70 | +To run the script, use the following command: |
| 71 | + |
| 72 | +``` bash |
| 73 | +./schedule.sh [-e etcd_name] [-s etcd_client_service] [-n etcd_namespace] [-j schedule] |
| 74 | +``` |
| 75 | + |
| 76 | +### Parameters |
| 77 | + |
| 78 | +- `-e etcd_name`: Name of the etcd StatefulSet (default: `kamaji-etcd`) |
| 79 | +- `-s etcd_client_service`: Name of the etcd client service (default: `kamaji-etcd-client`) |
| 80 | +- `-n etcd_namespace`: Namespace of the etcd StatefulSet (default: `kamaji-system`) |
| 81 | +- `-j schedule`: Cron schedule for the backup job (default: `"0 0 * * *"`, which means daily at midnight) |
| 82 | + |
| 83 | +### Example |
| 84 | +To run the script with custom parameters: |
| 85 | + |
| 86 | +```bash |
| 87 | +./schedule.sh -e kamaji-etcd -s kamaji-etcd-client -n kamaji-system -j "14 9 * * 1-5" |
| 88 | +``` |
| 89 | +This will create a Kubernetes CronJob manifest with the specified parameters and apply it to the cluster. The CronJob will take a snapshot of the `etcd` member and upload it to the specified S3-like storage according to the defined schedule. |
| 90 | + |
| 91 | +### Debug mode |
| 92 | +To run the script in debug mode set the environment variable `DEBUG`: |
| 93 | + |
| 94 | +``` bash |
| 95 | +export DEBUG=1 |
| 96 | +``` |
0 commit comments