Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ceph-backup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ window unit = days
destination directory = /tmp/
images = deleteme,test
compress = yes
convert to qcow2 = no
ceph config = /etc/ceph/ceph.conf
backup mode = incremental
check mode = no
9 changes: 7 additions & 2 deletions cephbackup/ceph_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CephFullBackup(object):
DIFF_BACKUP_SUFFIX = '.diff_from'
COMPRESSED_BACKUP_SUFFIX = '.tar.gz'

def __init__(self, pool, images, backup_dest, conf_file, check_mode=False, compress_mode=False, window_size=7, window_unit='days'):
def __init__(self, pool, images, backup_dest, conf_file, check_mode=False, compress_mode=False, convert_to_qcow2=False, window_size=7, window_unit='days'):
'''
images: list of images to backup
backup_dest: path where to write the backups
Expand All @@ -37,6 +37,7 @@ def __init__(self, pool, images, backup_dest, conf_file, check_mode=False, compr
self._backup_dest = backup_dest
self._check_mode = check_mode
self._compress_mode = compress_mode
self._convert_to_qcow2 = convert_to_qcow2
# TODO: support also cardinal backup window instead of temporal one, snapshots unit
self._window_size = window_size
self._window_unit = window_unit
Expand Down Expand Up @@ -188,6 +189,9 @@ def _export_image_or_snapshot(self, name, root_name, base=None):
# This is a full (non diff) export of the image or snapshot
print "Exporting image {image} to {dest}".format(image=name, dest=dest)
cmdlist.append('rbd export {pool}/{image} {dest}'.format(pool=self._pool, image=name, dest=dest))
if self._convert_to_qcow2:
cmdlist.append('qemu-img convert -O qcow2 {dest} {dest}.qcow2'.format(dest=dest))
cmdlist.append('mv {dest}.qcow2 {dest} -f'.format(dest=dest))
else:
# Exporting diffs from a base image or snapshot
# Validate also the base
Expand Down Expand Up @@ -349,10 +353,11 @@ def main():
parser.add_argument('-d', '--dest', help="Destination directory", required=True)
parser.add_argument('-n', '--check', help="Check mode, show the commands, do not write a backup", action="store_true")
parser.add_argument('-z', '--compress', help="Compress mode, it will compress each exported file and delete the original one", action="store_true")
parser.add_argument('-q', '--convert_to_qcow2', help="Convert the disk to qcow2 format", action="store_true")
parser.add_argument('-c', '--ceph-conf', help="Path to ceph configuration file", type=str, default='/etc/ceph/ceph.conf')
args = parser.parse_args()

cb = CephFullBackup(args.pool, args.images, args.dest, args.ceph_conf, args.check, args.compress)
cb = CephFullBackup(args.pool, args.images, args.dest, args.ceph_conf, args.check, args.compress, args.convert_to_qcow2)
cb.full_backup()

if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion cephbackup/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def start_backup(self):
conf_file = self.getsetting(section, 'ceph config')
check_mode = bool(strtobool(self.getsetting(section, 'check mode')))
compress_mode = bool(strtobool(self.getsetting(section, 'compress')))
convert_to_qcow2 = bool(strtobool(self.getsetting(section, 'convert to qcow2')))
window_size = int(self.getsetting(section, 'window size'))
window_unit = self.getsetting(section, 'window unit')
backup_mode = self.getsetting(section, 'backup mode')
cb = CephFullBackup(section, images, backup_dest, conf_file, check_mode, compress_mode, window_size, window_unit)
cb = CephFullBackup(section, images, backup_dest, conf_file, check_mode, compress_mode, convert_to_qcow2, window_size, window_unit)
if backup_mode == 'full':
print "Full ceph backup"
cb.print_overview()
Expand Down