How to use the freezer.utils.utils.DateTime.now function in freezer

To help you get started, we’ve selected a few freezer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / freezer / freezer / openstack / backup.py View on Github external
"""
        client_manager = self.client_manager
        cinder = client_manager.get_cinder()

        volume = cinder.volumes.get(volume_id)
        LOG.debug("Creation temporary snapshot")
        snapshot = client_manager.provide_snapshot(
            volume, "backup_snapshot_for_volume_%s" % volume_id)
        LOG.debug("Creation temporary volume")
        copied_volume = client_manager.do_copy_volume(snapshot)
        LOG.debug("Creation temporary glance image")
        image = client_manager.make_glance_image(copied_volume.id,
                                                 copied_volume)
        LOG.debug("Download temporary glance image {0}".format(image.id))
        stream = client_manager.download_image(image)
        package = "{0}/{1}".format(volume_id, utils.DateTime.now().timestamp)
        LOG.debug("Saving image to {0}".format(self.storage.type))
        if volume.name is None:
            name = volume_id
        else:
            name = volume.name
        headers = {'x-object-meta-length': str(len(stream)),
                   'volume_name': name,
                   'availability_zone': volume.availability_zone
                   }
        attachments = volume._info['attachments']
        if attachments:
            headers['server'] = attachments[0]['server_id']
        self.storage.add_stream(stream, package, headers=headers)
        LOG.debug("Deleting temporary snapshot")
        client_manager.clean_snapshot(snapshot)
        LOG.debug("Deleting temporary volume")
github openstack / freezer / freezer / job.py View on Github external
def backup(self, app_mode):
        """

        :type app_mode: freezer.mode.mode.Mode
        :return:
        """
        backup_media = self.conf.backup_media

        time_stamp = utils.DateTime.now().timestamp
        self.conf.time_stamp = time_stamp

        if backup_media == 'fs':
            LOG.info('Path to backup: {0}'.format(self.conf.path_to_backup))
            app_mode.prepare()
            snapshot_taken = snapshot.snapshot_create(self.conf)
            if snapshot_taken:
                app_mode.release()
            try:
                filepath = '.'
                chdir_path = os.path.expanduser(
                    os.path.normpath(self.conf.path_to_backup.strip()))
                if not os.path.exists(chdir_path):
                    msg = 'Path to backup does not exist {0}'.format(
                        chdir_path)
                    LOG.critical(msg)
github openstack / freezer / freezer / main.py View on Github external
def run_job(conf, storage):
    freezer_job = {
        'backup': job.BackupJob,
        'restore': job.RestoreJob,
        'info': job.InfoJob,
        'admin': job.AdminJob,
        'exec': job.ExecJob}[conf.action](conf, storage)

    start_time = utils.DateTime.now()
    LOG.info('Job execution Started at: {0}'.format(start_time))
    response = freezer_job.execute()
    end_time = utils.DateTime.now()
    LOG.info('Job execution Finished, at: {0}'.format(end_time))
    LOG.info('Job time Elapsed: {0}'.format(end_time - start_time))
    LOG.info('Backup metadata received: {0}'.format(json.dumps(response)))
    if not conf.quiet:
        LOG.info("Run freezer agent process successfully")

    if conf.metadata_out and response:
        if conf.metadata_out == '-':
            sys.stdout.write(json.dumps(response))
            sys.stdout.flush()
        else:
            with open(conf.metadata_out, 'w') as outfile:
                outfile.write(json.dumps(response))
    elif response and isinstance(response, dict):
        pp = prettytable.PrettyTable(["Property", "Value"])
        for k, v in response.items():
github openstack / freezer / freezer / storage / base.py View on Github external
"""
        if no_incremental:
            return None
        try:
            increments = self.get_latest_level_zero_increments(
                engine=engine,
                hostname_backup_name=hostname_backup_name)
            highest_level = max(increments.keys())
            highest_level_backup = increments[highest_level]
            if max_level and max_level <= highest_level:
                return None
            if always_level and highest_level > always_level:
                return None
            expire_time = (highest_level_backup.timestamp +
                           restart_always_level * 86400)
            if restart_always_level and utils.DateTime.now().timestamp > \
                    expire_time:
                return None
            if always_level and highest_level == always_level:
                return increments[highest_level - 1]
            return highest_level_backup
        except IndexError:
            return None
github openstack / freezer / freezer / openstack / backup.py View on Github external
def backup_cinder(self, volume_id, name=None, description=None,
                      incremental=False):
        client_manager = self.client_manager
        cinder = client_manager.get_cinder()
        container = "{0}/{1}/{2}".format(self.container, volume_id,
                                         utils.DateTime.now().timestamp)
        if incremental:
            search_opts = {
                'volume_id': volume_id,
                'status': 'available'
            }
            backups = cinder.backups.list(search_opts=search_opts)
            if len(backups) <= 0:
                msg = ("Backup volume %s is failed."
                       "Do a full backup before incremental backup"
                       % volume_id)
                raise Exception(msg)
            else:
                cinder.backups.create(volume_id, container, name, description,
                                      incremental=incremental, force=True)
        else:
            cinder.backups.create(volume_id, container, name, description,
github openstack / freezer / freezer / main.py View on Github external
def run_job(conf, storage):
    freezer_job = {
        'backup': job.BackupJob,
        'restore': job.RestoreJob,
        'info': job.InfoJob,
        'admin': job.AdminJob,
        'exec': job.ExecJob}[conf.action](conf, storage)

    start_time = utils.DateTime.now()
    LOG.info('Job execution Started at: {0}'.format(start_time))
    response = freezer_job.execute()
    end_time = utils.DateTime.now()
    LOG.info('Job execution Finished, at: {0}'.format(end_time))
    LOG.info('Job time Elapsed: {0}'.format(end_time - start_time))
    LOG.info('Backup metadata received: {0}'.format(json.dumps(response)))
    if not conf.quiet:
        LOG.info("Run freezer agent process successfully")

    if conf.metadata_out and response:
        if conf.metadata_out == '-':
            sys.stdout.write(json.dumps(response))
            sys.stdout.flush()
        else:
            with open(conf.metadata_out, 'w') as outfile:
                outfile.write(json.dumps(response))