You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tobi 1e2abfd1e4 root user crontab 2 months ago
.gitignore init 3 months ago
README.md root user crontab 2 months ago
backup.py cephfs filter 2 months ago
config.template init 3 months ago
requirements.txt init 3 months 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

  1. The partion of your external harddrive. Get it using lsblk
  2. Folder where it should be mountet
  3. Detect the filesystem of the partion automatically
  4. Default => rw, suid, dev, exec, auto, nouser, async. nobootwait => don’t wait on mount while booting the system.
  5. Dump, don’t really undestand it => Documentation says “Dump is seldom used and if in doubt use 0.”
  6. “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