Archive

Important

You must be using py42 to version 1.25.1 or higher to use the archive.stream_from_backup() or archive.stream_to_device() methods.

class py42.clients.archive.ArchiveClient(archive_accessor_factory, archive_service)

Bases: object

A module for getting information about backup archives on storage nodes along with functionality for streaming a file from backup.

get_all_by_device_guid(device_guid)

Gets archive information for a device.

Parameters

device_guid (str) – The GUID for the device.

Returns

An object that iterates over py42.response.Py42Response objects that each contain a page of archives.

Return type

generator

get_all_device_restore_history(days, device_id)

Gets all restore jobs from the past given days for the device with the given ID.

Parameters
  • days (int) – Number of days of restore history to retrieve.

  • device_id (int) – The identification number of the device to get restore history for.

Returns

An object that iterates over py42.response.Py42Response objects that each contain a page of restore history.

Return type

generator

get_all_org_cold_storage_archives(org_id, include_child_orgs=True, sort_key='archiveHoldExpireDate', sort_dir='asc')

Returns a detailed list of cold storage archive information for a given org ID.

Parameters
  • org_id (str) – The ID of a Code42 organization.

  • include_child_orgs (bool, optional) – Determines whether cold storage information from the Org’s children is also returned. Defaults to True.

  • sort_key (str, optional) – Sets the property by which the returned results will be sorted. Choose from archiveHoldExpireDate, orgName, mountPointName, archiveBytes, and archiveType. Defaults to archiveHoldExpireDate.

  • sort_dir (str, optional) – Sets the order by which sort_key should be sorted. Choose from asc or desc. Defaults to asc.

Returns

An object that iterates over py42.response.Py42Response objects that each contain a page of cold storage archive information.

Return type

generator

get_all_org_restore_history(days, org_id)

Gets all restore jobs from the past given days for the organization with the given ID.

Parameters
  • days (int) – Number of days of restore history to retrieve.

  • org_id (int) – The identification number of the organization to get restore history for.

Returns

An object that iterates over py42.response.Py42Response objects that each contain a page of restore history.

Return type

generator

get_all_user_restore_history(days, user_id)

Gets all restore jobs from the past given days for the user with the given ID.

Parameters
  • days (int) – Number of days of restore history to retrieve.

  • user_id (int) – The identification number of the user to get restore history for.

Returns

An object that iterates over py42.response.Py42Response objects that each contain a page of restore history.

Return type

generator

get_backup_sets(device_guid, destination_guid)

Gets all backup set names/identifiers referring to a single destination for a specific device. Learn more about backup sets.

Parameters
  • device_guid (str) – The GUID of the device to get backup sets for.

  • destination_guid (str) – The GUID of the destination containing the archive to get backup sets for.

Returns

A response containing the backup sets.

Return type

py42.response.Py42Response

get_by_archive_guid(archive_guid)

Gets single archive information by GUID.

Parameters

archive_guid (str) – The GUID for the archive.

Returns

A response containing archive information.

Return type

py42.response.Py42Response

stream_from_backup(file_paths, device_guid, destination_guid=None, archive_password=None, encryption_key=None, show_deleted=None, file_size_calc_timeout=10, backup_set_id=None)

Streams a file from a backup archive to memory. This method uses the same endpoint as restoring from Console and therefore has all the same considerations.

Support Documentation

Parameters
  • file_paths (str or list of str) – The path or list of paths to the files or directories in the archive.

  • device_guid (str) – The GUID of the device the file belongs to.

  • destination_guid (str, optional) – The GUID of the destination that stores the backup of the file. If None, it will use the first destination GUID it finds for your device. ‘destination_guid’ may be useful if the file is missing from one of your destinations or if you want to optimize performance. Defaults to None.

  • archive_password (str or None, optional) – The password for the archive, if password- protected. This is only relevant to users with archive key password security. Defaults to None.

  • encryption_key (str or None, optional) – A custom encryption key for decrypting an archive’s file contents, necessary for restoring files. This is only relevant to users with custom key archive security. Defaults to None.

  • show_deleted (bool, optional) – Set to True to include deleted files when restoring a directory. Defaults to None.

  • file_size_calc_timeout (int, optional) – Set to limit the amount of seconds spent calculating file sizes when crafting the request. Set to 0 or None to ignore file sizes altogether. Defaults to 10.

  • backup_set_id (str, optional) – The ID of the backup set restore from (only useful for V3 archives). If not supplied, the default backup set (id=1) will be used if it exists, otherwise the first in the list of existing backup sets will be used.

Returns

A response containing the streamed content.

Return type

py42.response.Py42Response

Usage example:

stream_response = sdk.archive.stream_from_backup("/full/path/to/file.txt", "1234567890")
with open("/path/to/save/file/to", "wb") as f:
    for chunk in stream_response.iter_content(chunk_size=128):
        if chunk:
            f.write(chunk)

In certain cases, you will have to unzip the results:

import zipfile
with zipfile.ZipFile("downloaded_directory.zip", "r") as zf:
    zf.extractall(".")
stream_to_device(file_paths, device_guid, accepting_device_guid, restore_path, destination_guid=None, archive_password=None, encryption_key=None, show_deleted=None, overwrite_existing_files=False, file_size_calc_timeout=10, backup_set_id=None)

Streams a file from a backup archive to a specified device.

Parameters
  • file_paths (str or list of str) – The path or list of paths to the files or directories in the archive.

  • device_guid (str) – The GUID of the device the file belongs to.

  • accepting_device_guid (str) – The GUID of the device accepting the restore.

  • restore_path (str, optional) – The path on the accepting device where the restore will be saved. Alternatively, pass in the value ORIGINAL_LOCATION to restore the file to the original location, which may be the case if you are replacing a device.

  • destination_guid (str, optional) – The GUID of the destination that stores the backup of the file. If None, it will use the first destination GUID it finds for your device. ‘destination_guid’ may be useful if the file is missing from one of your destinations or if you want to optimize performance. Defaults to None.

  • archive_password (str or None, optional) – The password for the archive, if password- protected. This is only relevant to users with archive key password security. Defaults to None.

  • encryption_key (str or None, optional) – A custom encryption key for decrypting an archive’s file contents, necessary for restoring files. This is only relevant to users with custom key archive security. Defaults to None.

  • show_deleted (bool, optional) – Set to True to include deleted files when restoring a directory. Defaults to None.

  • overwrite_existing_files (bool, optional) – to overwrite any existing files with the restored data. If False (the default), any existing files that match a path being restored will first get renamed.

  • file_size_calc_timeout (int, optional) – Set to limit the amount of seconds spent calculating file sizes when crafting the request. Set to 0 or None to ignore file sizes altogether. Defaults to 10.

  • backup_set_id (str, optional) – The ID of the backup set restore from (only useful for V3 archives). If not supplied, the default backup set (id=1) will be used if it exists, otherwise the first in the list of existing backup sets will be used.

Returns

py42.response.Py42Response.

update_cold_storage_purge_date(archive_guid, purge_date)

Updates the cold storage purge date for a specified archive.

Parameters
  • archive_guid (str) – The identification number of the archive that should be updated

  • purge_date (str) – The date on which the archive should be purged in yyyy-MM-dd format

Returns

the response from the ColdStorage API.

Return type

py42.response.Py42Response