示例#1
0
def update_backup_schedule(resource_group_name, webapp_name, storage_account_url=None,
                           frequency=None, keep_at_least_one_backup=None,
                           retention_period_in_days=None, db_name=None,
                           db_connection_string=None, db_type=None, slot=None):
    client = web_client_factory()
    location = _get_location_from_webapp(client, resource_group_name, webapp_name)
    configuration = None

    try:
        configuration = _generic_site_operation(resource_group_name, webapp_name,
                                                'get_backup_configuration', slot)
    except CloudError:
        # No configuration set yet
        if not all([storage_account_url, frequency, retention_period_in_days,
                    keep_at_least_one_backup]):
            raise CLIError('No backup configuration found. A configuration must be created. ' +
                           'Usage: --container-url URL --frequency TIME --retention DAYS ' +
                           '--retain-one TRUE/FALSE')

    # If arguments were not specified, use the values in the current backup schedule
    if storage_account_url is None:
        storage_account_url = configuration.storage_account_url

    if retention_period_in_days is None:
        retention_period_in_days = configuration.backup_schedule.retention_period_in_days

    if keep_at_least_one_backup is None:
        keep_at_least_one_backup = configuration.backup_schedule.keep_at_least_one_backup
    else:
        keep_at_least_one_backup = keep_at_least_one_backup.lower() == 'true'

    if frequency:
        # Parse schedule frequency
        frequency_num, frequency_unit = _parse_frequency(frequency)
    else:
        frequency_num = configuration.backup_schedule.frequency_interval
        frequency_unit = configuration.backup_schedule.frequency_unit

    if configuration and configuration.databases:
        db = configuration.databases[0]
        db_type = db_type or db.database_type
        db_name = db_name or db.name
        db_connection_string = db_connection_string or db.connection_string

    db_setting = _create_db_setting(db_name, db_type, db_connection_string)

    backup_schedule = BackupSchedule(frequency_num, frequency_unit.name,
                                     keep_at_least_one_backup, retention_period_in_days)
    backup_request = BackupRequest(location, backup_schedule=backup_schedule, enabled=True,
                                   storage_account_url=storage_account_url, databases=db_setting)
    if slot:
        return client.web_apps.update_backup_configuration_slot(resource_group_name, webapp_name,
                                                                backup_request, slot)
    else:
        return client.web_apps.update_backup_configuration(resource_group_name, webapp_name,
                                                           backup_request)
示例#2
0
def create_backup(resource_group_name, webapp_name, storage_account_url,
                  db_name=None, db_type=None,
                  db_connection_string=None, backup_name=None, slot=None):
    client = web_client_factory()
    if backup_name and backup_name.lower().endswith('.zip'):
        backup_name = backup_name[:-4]
    location = _get_location_from_webapp(client, resource_group_name, webapp_name)
    db_setting = _create_db_setting(db_name, db_type, db_connection_string)
    backup_request = BackupRequest(location, backup_request_name=backup_name,
                                   storage_account_url=storage_account_url, databases=db_setting)
    if slot:
        return client.web_apps.backup_slot(resource_group_name, webapp_name, backup_request, slot)
    else:
        return client.web_apps.backup(resource_group_name, webapp_name, backup_request)