Skip to content

Instantly share code, notes, and snippets.

@zhanghui9700
Last active December 30, 2016 03:35
Show Gist options
  • Save zhanghui9700/53fb8ea12d707d0d5166e327c658cd11 to your computer and use it in GitHub Desktop.
Save zhanghui9700/53fb8ea12d707d0d5166e327c658cd11 to your computer and use it in GitHub Desktop.

cinder backup

root@node-2:~# cat /etc/cinder/cinder.conf | grep -v "^#|^$" | grep "backup"

backup_ceph_conf = /etc/ceph/ceph.conf
backup_ceph_user = backups
backup_ceph_chunk_size = 134217728
backup_ceph_pool = backups
backup_ceph_stripe_unit = 0
backup_ceph_stripe_count = 0
backup_driver = cinder.backup.drivers.ceph

root@node-2:~# ps -ef | grep backup

cinder    5367     1  0 Oct08 ?        00:10:26 /usr/bin/python2.7 /usr/bin/cinder-backup --log-file=/var/log/cinder/cinder-backup.log --config-file=/etc/cinder/cinder.conf

self.backup_api = backupAPI.API() backupAPI = importutils.import_class(CONF.backup_api_class) CONF.backup_api_class.default='cinder.backup.api.API'

@zhanghui9700
Copy link
Author

def _run_backup(self, context, backup, volume):
    # cinder.backup.drivers.ceph.CephBackupDriver
    backup_service = self.service.get_backup_driver(context)

    # {'initiator': 'iqn.1993-08.org.debian:01:b8dbe1a7fb8', 'ip': '192.168.32.5', 'platform': 'x86_64', 'host': 'node-6.suninfo.com', 'os_type': 'linux2', 'multipath': False}
    properties = utils.brick_get_connector_properties()
    #  {u'secure_enabled': False, u'is_snapshot': False, u'backup_device': Volume(_name_id=None,admin_metadata={},attach_status='detached',availability_zone='nova',bootable=False,consistencygroup=<?>,consistencygroup_id=None,created_at=2016-12-28T10:21:09Z,deleted=False,deleted_at=None,display_description='',display_name='1GB-second',ec2_id=None,encryption_key_id=None,glance_metadata=<?>,host='rbd:volumes@RBD-backend#RBD-backend',id=0c956ff6-db44-4679-8188-6db207095545,launched_at=2016-12-28T10:21:09Z,metadata={},migration_status=None,multiattach=False,previous_status='available',project_id=0fcb881dcc5e4394bbc38bd03202b718,provider_auth=None,provider_geometry=None,provider_id=None,provider_location=None,replication_driver_data=None,replication_extended_status=None,replication_status='disabled',scheduled_at=2016-12-28T10:21:09Z,size=1,snapshot_id=None,snapshots=<?>,source_volid=None,status='backing-up',terminated_at=None,updated_at=2016-12-30T02:56:03Z,user_id=5709b1c89ee943aab5722f8cdcc00967,volume_attachment=<?>,volume_type=VolumeType(98c2a93c-6dc6-41b5-9b09-edcfefc62210),volume_type_id=98c2a93c-6dc6-41b5-9b09-edcfefc62210)}
    backup_dic = self.volume_rpcapi.get_backup_device(context,
                                                      backup, volume)
    try:
        backup_device = backup_dic.get('backup_device')
        is_snapshot = backup_dic.get('is_snapshot')
        # {'device': {'path': <os_brick.initiator.linuxrbd.RBDVolumeIOWrapper object at 0x7f73985ea190>}, 'connector': <os_brick.initiator.connector.RBDConnector object at 0x7f739859eb10>, 'conn': {u'driver_volume_type': u'rbd', u'data': {u'secret_type': u'ceph', u'name': u'volumes/volume-0c956ff6-db44-4679-8188-6db207095545', u'encrypted': False, u'secret_uuid': u'a5d0dd94-57c4-ae55-ffe0-7e3732a24455', u'qos_specs': None, u'hosts': [u'192.168.34.3'], u'volume_id': u'0c956ff6-db44-4679-8188-6db207095545', u'auth_enabled': True, u'access_mode': u'rw', u'auth_username': u'volumes', u'ports': [u'6789']}}}
        attach_info = self._attach_device(context, backup_device,
                                          properties, is_snapshot)
        try:
            device_path = attach_info['device']['path']
            if isinstance(device_path, six.string_types):
                if backup_dic.get('secure_enabled', False):
                    with open(device_path) as device_file:
                        backup_service.backup(backup, device_file)
                else:
                    with utils.temporary_chown(device_path):
                        with open(device_path) as device_file:
                            backup_service.backup(backup, device_file)
            else:
                backup_service.backup(backup, device_path)

        finally:
            self._detach_device(context, attach_info,
                                backup_device, properties,
                                is_snapshot)
    finally:
        backup = objects.Backup.get_by_id(context, backup.id)
        self._cleanup_temp_volumes_snapshots_when_backup_created(
            context, backup)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment