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

  1. #!/bin/bash
  2.  
  3. BACKUP_ROOT=/home/ceph/backups
  4. TIME_START=$(date --rfc-3339=seconds)
  5. TODAY=$(date --rfc-3339=date)
  6. BACKUP_DIR=${BACKUP_ROOT}/${TODAY}
  7.  
  8. echo "Ceph Backup Started ${TIME_START}"
  9.  
  10. POOLS=( $(rados lspools) )
  11.  
  12. for POOL in "${POOLS[@]}"
  13. do
  14. POOL_BACKUP_DIR=${BACKUP_DIR}/${POOL}
  15. mkdir -p ${POOL_BACKUP_DIR}
  16. IMAGES=( $(rbd ls -p ${POOL}) )
  17. for IMAGE in "${IMAGES[@]}"
  18. do
  19. echo "$(date --rfc-3339=seconds) backup image:${POOL}/${IMAGE}"
  20. rbd export -p ${POOL} ${IMAGE} ${POOL_BACKUP_DIR}/${IMAGE}
  21. done
  22. done
  23.  
  24. TIME_END=$(date --rfc-3339=seconds)
  25. echo "Ceph Backup Completed ${TIME_END}"

Restore

Resultant backups can be imported using:

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

Docs

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