|
1 year ago | |
---|---|---|
.gitignore | 2 years ago | |
README.md | 1 year ago | |
backup.py | 1 year ago | |
config.template | 2 years ago | |
requirements.txt | 2 years ago |
README.md
K8S RBD Backup
(Kubernetes Rados Block Device Backup)
Backups any persistent kubernetes volumes, static and dynamically created ones. Using the rbd
tool in cephadm install ceph-common
. It will leave you with fully functional images, that can be either
manually mounted to recover data, or directly inserted in an existing ceph cluster.
Setup
Copy the config template and fill in your own values (name it just config
after and place it next to the backup.py script)
- cluster_admin_token - this needs to be a token of a kubernetes service account that has the rolebinding cluster-admin. You create one using the commands from here
- backup_path - somewhere the script should place the backups
- kube_api_endpoint - central floating ip specified in kubeadm.yaml
- delete_old ("true"/"false") - will delete backups older than X days
- older_than_days - X days
Auto mount external drive
Edit /etc/fstab
# Ext Harddrive for backups
/dev/sda1 /restore/ auto defaults,nofail 0 2
Parameters
- The partion of your external harddrive. Get it using
lsblk
- Folder where it should be mountet
- Detect the filesystem of the partion automatically
- Default => rw, suid, dev, exec, auto, nouser, async. nobootwait => don't wait on mount while booting the system.
- Dump, don't really undestand it => Documentation says "Dump is seldom used and if in doubt use 0."
- "In practice, use "1" for your root partition, / and 2 for the rest."
Crontab
You will want the script to run automatically. Do that by creating a simple root user crontab using sudo crontab -e
and append the file something like this
# every day at 1 am
0 1 * * * cd /home/tobi/backup && python3 backup.py
Crontabs are stored under /var/spool/cron/crontabs
incase you want to modify that.
Mounting a backup manully
sudo mount /path/to/backup.img /path/to/empty/folder
Importing it into ceph
rbd import --image-feature layering backup.img pool/new-image-name
The image feature is especially important. Images that you want to mount into kubernetes pods have to have the layering
feature and only that.
Running the script manually
The running user needs to have access to backup_path
specified in the config file
python3 backup.py