How to Backup Ceph Block Storage

I have a customer who is running a reduced redundancy ceph cluster as backend to her openstack cluster. Since it’s development, she’s not as concerned about availability, but still wants to provide assurance against data loss. Here’s a backup script to export the images from Ceph so she can nightly dump her data to a remote location.

As always, the backup and recovery techniques used in this script should be thoroughly tested before considered reliable.

Backup

#!/bin/bash

BACKUP_ROOT=/home/ceph/backups
TIME_START=$(date --rfc-3339=seconds)
TODAY=$(date --rfc-3339=date)
BACKUP_DIR=${BACKUP_ROOT}/${TODAY}

echo "Ceph Backup Started ${TIME_START}"

POOLS=( $(rados lspools) )

for POOL in "${POOLS[@]}"
do
  POOL_BACKUP_DIR=${BACKUP_DIR}/${POOL}
  mkdir -p ${POOL_BACKUP_DIR}
  IMAGES=( $(rbd ls -p ${POOL}) )
  for IMAGE in "${IMAGES[@]}"
  do
    echo "$(date --rfc-3339=seconds) backup image:${POOL}/${IMAGE}"
    rbd export -p ${POOL} ${IMAGE} ${POOL_BACKUP_DIR}/${IMAGE}
  done
done

TIME_END=$(date --rfc-3339=seconds)
echo "Ceph Backup Completed ${TIME_END}"

Restore

Resultant backups can be imported using:

rbd import -p ${POOL} ${POOL_BACKUP_DIR}/${IMAGE} ${IMAGE}

Docs

Read more about rbd at http://ceph.com/docs/master/man/8/rbd/


comments powered by Disqus