Creating a protection plan

  1. Authenticate to the cloud platform via the Python shell.

    The following variables should be available now:

    >>> base_url  # the base URL of the API
    'https://eu2-cloud.acronis.com/api'
    >>> auth  # the 'Authorization' header value with the access token
    {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImMwMD...'}
    
  2. Import the uuid4 function from the uuid python module:

    >>> from uuid import uuid4
    
  3. Define a variable named protection_plan_id, and then assign the UUID generated with the uuid4() function and converted to string to this variable:

    >>> protection_plan_id = str(uuid4())
    '5b15f6e1-88ec-4dce-b523-0e8394c0bc19'
    
  4. Define a variable named plan_data, and then assign an object with the subject key with an object containing the policy key with an array containing a total protection policy to this variable:

    >>> plan_data = {
    ...     'subject': {
    ...         'policy': [
    ...             {
    ...                 'id': protection_plan_id,
    ...                 'type': 'policy.protection.total',
    ...                 'origin': 'upstream',
    ...                 'enabled': True,
    ...                 'name': 'My Protection Plan'
    ...             }
    ...         ]
    ...     }
    ... }
    
  5. Define the variable named policies and assign it with the list of protection policy objects. As an example, a machine backup policy with default settings will be included:

    Full code

      1policies = [
      2    {
      3        "id": str(uuid4()),
      4        # Machine backup policy type is 'policy.backup.machine'
      5        'type': 'policy.backup.machine',
      6        'parent_ids': [
      7            protection_plan_id
      8        ],
      9        'origin': 'upstream',
     10        'enabled': True,
     11        'settings_schema': '2.0',
     12        'settings': {
     13            # Archive compression level. Available values: ``normal``, ``high``, ``max``. When value is not specified - no compression is applied.
     14            'compression': 'normal',
     15            # Format of the Acronis backup archive. Available values: ``11``, ``12``, ``auto``.
     16            'format': 'auto',
     17            # If true, snapshots of multiple volumes will be taken simultaneously. Equals to false if value is not specified.
     18            'multi_volume_snapshotting_enabled': True,
     19            # If true, the file security settings will be preserved. Equals to false if value is not specified.
     20            'preserve_file_security_settings': True,
     21            # Configuration of retries on recoverable errors during the backup operations like reconnection to destination. No attempts to fix recoverable errors will be made if retry configuration is not set.
     22            'reattempts': {
     23                # If true, enables retry on recoverable errors.
     24                'enabled': True,
     25                # An interval between retry attempts.
     26                'interval': {
     27                    # A type of the interval. Available values are: ``seconds``, ``minutes``, ``hours``, ``days``.
     28                    'type': 'seconds',
     29                    # The amount of value specified in ``interval.type``.
     30                    'count': 30
     31                },
     32                # Max number of retry attempts. Operation will be considered as failed when max number of retry attempts is reached.
     33                'max_attempts': 30
     34            },
     35            # If true, a user interaction will be avoided when possible. Equals to false if value is not specified.
     36            'silent_mode_enabled': True,
     37            # Determines the size to split backups on. Splitting is not performed if value is not specified.
     38            'splitting': {
     39                # The size of split backup file in bytes.
     40                'size': 9223372036854775807
     41            },
     42            # Configuration of retries on errors during the creation of the virtual machine snapshot. No attempts to fix recoverable errors will be made if retry configuration is not set.
     43            'vm_snapshot_reattempts': {
     44                # If true, enables retry on errors.
     45                'enabled': True,
     46                # Configuration of the interval between retry attempts.
     47                'interval': {
     48                    # A type of the interval. Available values are: ``seconds``, ``minutes``, ``hours``, ``days``.
     49                    'type': 'minutes',
     50                    # The amount of value specified in ``interval.type``.
     51                    'count': 5
     52                },
     53                # Max number of retry attempts. Operation will be considered as failed when max number of retry attempts is reached.
     54                'max_attempts': 3
     55            },
     56            # Settings for the Volume Shadow Copy Service (VSS) provider. If not set, no VSS provider is used.
     57            'vss': {
     58                # If true, the VSS will be enabled.
     59                'enabled': True,
     60                # A type of VSS provider to use in backup. Only ``native`` and ``target_system_defined`` options are available.
     61                'provider': 'target_system_defined'
     62            },
     63            # The archive properties.
     64            'archive': {
     65                # The name of the generated archive. The name may use the following variables: ``[Machine Name]``, ``[Plan ID]``, ``[Plan Name]``, ``[Unique ID]``, ``[Virtualization Server Type]``.
     66                'name': '[Machine Name]-[Plan ID]-[Unique ID]A'
     67            },
     68            # Time windows for performance limitations of backup and storage maintenance operations.
     69            'performance_window': {
     70                'enabled': False  # If true, the time windows will be enabled.
     71            },
     72            # Configuration of backup retention rules.
     73            'retention': {
     74                # A list of retention rules.
     75                'rules': [
     76                    {
     77                        # A list of backup sets where rules are effective.
     78                        'backup_set': [
     79                            'daily'
     80                        ],
     81                        # Configuration of the duration to keep backups in archive created by the policy.
     82                        'max_age': {
     83                            # A type of the duration. Available values are: ``seconds``, ``minutes``, ``hours``, ``days``.
     84                            'type': 'days',
     85                            # The amount of value specified in ``max_age.type``.
     86                            'count': 7
     87                        }
     88                    },
     89                    {
     90                        'backup_set': [
     91                            'weekly'
     92                        ],
     93                        'max_age': {
     94                            'type': 'weeks',
     95                            'count': 4
     96                        }
     97                    },
     98                    {
     99                        'backup_set': [
    100                            'monthly'
    101                        ],
    102                        'max_age': {
    103                            'type': 'months',
    104                            'count': 6
    105                        }
    106                    }
    107                ],
    108                # If true, retention rules will be applied after backup is finished.
    109                'after_backup': True
    110            },
    111            # Storage location of the archives.
    112            'vault': {
    113                # Type of storage location. Available values: ``local_folder``, ``network_share``, ``ftp``, ``sftp``, ``cd``, ``tape``, ``storage_node``, ``asz``, ``removable``, ``cloud``, ``nfs_share``, ``esx``, ``astorage2``, ``script``.
    114                'type': 'cloud',
    115                # If true, the vault will be accessed using the policy credentials.
    116                'use_policy_credentials': True
    117            },
    118            # Configuration of policy-related alerts.
    119            'alerts': {
    120                # If true, the alerts will be enabled.
    121                'enabled': False,
    122                # Number of days that will trigger the alert about the passed number of days without a backup.
    123                'max_days_without_backup': 5
    124            },
    125            # Configuration of the backup schedule.
    126            'scheduling': {
    127                # A list of schedules with backup sets that compose the whole scheme.
    128                'backup_sets': [
    129                    {
    130                        'type': 'auto',
    131                        'schedule': {
    132                            'alarms': {
    133                                'time': {
    134                                    'weekdays': [
    135                                        'mon',
    136                                        'tue',
    137                                        'wed',
    138                                        'thu',
    139                                        'fri'
    140                                    ],
    141                                    'repeat_at': [
    142                                        {
    143                                            'hour': 21,
    144                                            'minute': 0
    145                                        }
    146                                    ]
    147                                }
    148                            },
    149                            'conditions': {},
    150                            'prevent_sleep': True,
    151                            'type': 'weekly'
    152                        }
    153                    }
    154                ],
    155                # If true, the backup schedule will be enabled.
    156                'enabled': True,
    157                # Max number of backup processes allowed to run in parallel. Unlimited if not set.
    158                'max_parallel_backups': 2,
    159                'rand_max_delay': {  # Configuration of the random delay between the execution of parallel tasks.
    160                    # A type of the duration. Available values are: ``seconds``, ``minutes``, ``hours``, ``days``.
    161                    'type': 'minutes',
    162                    # The amount of value specified in ``rand_max_delay.type``.
    163                    'count': 30
    164                },
    165                # A backup scheme. Available values: ``simple``, ``always_full``, ``always_incremental``, ``weekly_incremental``, ``weekly_full_daily_incremental``, ``custom``, ``cdp``.
    166                'scheme': 'always_incremental',
    167                # A day of week to start weekly backups in 3-letter abbreviation format.
    168                'weekly_backup_day': 'mon'
    169            },
    170            # A configuration of Changed Block Tracking (CBT). Available values: ``use_if_enabled``, ``enable_and_use``, ``do_not_use``.
    171            'cbt': 'enable_and_use',
    172            # If true, determines whether a file has changed by the file size and timestamp. Otherwise, the entire file contents are compared to those stored in the backup.
    173            'fast_backup_enabled': True,
    174            # If true, a quiesced snapshot of the virtual machine will be taken.
    175            'quiesce_snapshotting_enabled': True
    176        }
    177    },
    178    # Put other policy objects here.
    179]
    

    For more policy settings, refer to Protection policy settings.

  6. Merge the list of protection policy objects into the policy key of the plan_data object:

    >>> plan_data['subject']['policy'] += policies
    
  7. Convert the plan_data object to a JSON text:

    >>> plan_data = json.dumps(plan_data, indent=4)
    
  8. Send a POST request with the JSON text to the /policy_management/v4/policies endpoint:

    >>> response = requests.post(
    ...     f'{base_url}/policy_management/v4/policies',
    ...     headers={'Content-Type': 'application/json', **auth},
    ...     data=plan_data,
    ... )
    
  9. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the protection plan has been created.

    A different status code means that an error has occurred. For the details, refer to “Status and error codes”.

    Also, the response body contains an object with the result key containing an array of policy IDs formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'result': ['5b15f6e1-88ec-4dce-b523-0e8394c0bc19@policy.protection.total',
                '256f2ee5-c9fd-4aad-8607-97a977deeaae@policy.backup.machine',
                '260a95af-366f-4331-ad88-6f188f034870@policy.security.vulnerability_assessment',
                'fce55bf0-efb2-4220-b9bf-6fdebc5af660@policy.security.backups_scanning',
                'a1d5efa0-f9d7-4493-9bc9-c159879c7724@policy.security.windows_defender',
                '23f0fc3c-1b52-4da5-a765-fd856255b023@policy.security.patch_management',
                '9502bbc1-b37c-4617-8a8e-c174a945e98d@policy.security.microsoft_security_essentials',
                'f354c80f-5b7a-4466-97f1-df670cccb673@policy.security.antimalware_protection',
                '4f3c7359-2a83-40cf-9733-172253d85484@policy.security.data_protection_map',
                '3c496736-8fdf-48b7-bd4d-66c770448e83@policy.security.active_protection',
                '6c120d91-7ce3-463e-abae-b6c43ab27c87@policy.security.url_filtering']}