b2sdk._internal.sync.policy

class b2sdk._internal.sync.policy.NewerFileSyncMode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mode of handling files newer on destination than on source

SKIP = 101

skip syncing such file

REPLACE = 102

replace the file on the destination with the (older) file on source

RAISE_ERROR = 103

raise a non-transient error, failing the sync operation

class b2sdk._internal.sync.policy.CompareVersionMode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mode of comparing versions of files to determine what should be synced and what shouldn’t

MODTIME = 201

use file modification time on source filesystem

SIZE = 202

compare using file size

NONE = 203

compare using file name only

class b2sdk._internal.sync.policy.AbstractFileSyncPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: object

Abstract policy class.

Parameters:
DESTINATION_PREFIX = NotImplemented
SOURCE_PREFIX = NotImplemented
__init__(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]
Parameters:
  • source_path (Optional[AbstractPath]) – source file object

  • source_folder (AbstractFolder) – source folder object

  • dest_path (Optional[AbstractPath]) – destination file object

  • dest_folder (AbstractFolder) – destination folder object

  • now_millis (int) – current time in milliseconds

  • keep_days (int) – days to keep before delete

  • newer_file_mode (NewerFileSyncMode) – setting which determines handling for destination files newer than on the source

  • compare_threshold (int) – when comparing with size or time for sync

  • compare_version_mode (CompareVersionMode) – how to compare source and destination files

  • encryption_settings_provider (AbstractSyncEncryptionSettingsProvider) – encryption setting provider

  • upload_mode (UploadMode) – file upload mode

  • absolute_minimum_part_size (Optional[int]) – minimum file part size that can be uploaded to the server

classmethod files_are_different(source_path, dest_path, compare_threshold=None, compare_version_mode=CompareVersionMode.MODTIME, newer_file_mode=NewerFileSyncMode.RAISE_ERROR)[source]

Compare two files and determine if the the destination file should be replaced by the source file.

Parameters:
  • source_path (AbstractPath) – source file object

  • dest_path (AbstractPath) – destination file object

  • compare_threshold (Optional[int]) – compare threshold when comparing by time or size

  • compare_version_mode (CompareVersionMode) – source file version comparator method

  • newer_file_mode (NewerFileSyncMode) – newer destination handling method

  • source_path

  • dest_path

  • compare_threshold

  • compare_version_mode

  • newer_file_mode

get_all_actions()[source]

Yield file actions.

class b2sdk._internal.sync.policy.DownPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: AbstractFileSyncPolicy

File is synced down (from the cloud to disk).

Parameters:
DESTINATION_PREFIX = 'local://'
SOURCE_PREFIX = 'b2://'
class b2sdk._internal.sync.policy.UpPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: AbstractFileSyncPolicy

File is synced up (from disk the cloud).

Parameters:
DESTINATION_PREFIX = 'b2://'
SOURCE_PREFIX = 'local://'
class b2sdk._internal.sync.policy.UpAndDeletePolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: UpPolicy

File is synced up (from disk to the cloud) and the delete flag is SET.

Parameters:
class b2sdk._internal.sync.policy.UpAndKeepDaysPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: UpPolicy

File is synced up (from disk to the cloud) and the keepDays flag is SET.

Parameters:
class b2sdk._internal.sync.policy.DownAndDeletePolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: DownPolicy

File is synced down (from the cloud to disk) and the delete flag is SET.

Parameters:
class b2sdk._internal.sync.policy.DownAndKeepDaysPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: DownPolicy

File is synced down (from the cloud to disk) and the keepDays flag is SET.

Parameters:
class b2sdk._internal.sync.policy.CopyPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: AbstractFileSyncPolicy

File is copied (server-side).

Parameters:
DESTINATION_PREFIX = 'b2://'
SOURCE_PREFIX = 'b2://'
class b2sdk._internal.sync.policy.CopyAndDeletePolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: CopyPolicy

File is copied (server-side) and the delete flag is SET.

Parameters:
class b2sdk._internal.sync.policy.CopyAndKeepDaysPolicy(source_path, source_folder, dest_path, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=CompareVersionMode.MODTIME, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]

Bases: CopyPolicy

File is copied (server-side) and the keepDays flag is SET.

Parameters:
b2sdk._internal.sync.policy.make_b2_delete_note(version, index, transferred)[source]

Create a note message for delete action.

Parameters:
  • version (b2sdk.v2.FileVersion) – an object which contains file version info

  • index (int) – file version index

  • transferred (bool) – if True, file has been transferred, False otherwise

b2sdk._internal.sync.policy.make_b2_delete_actions(source_path, dest_path, dest_folder, transferred)[source]

Create the actions to delete files stored on B2, which are not present locally.

Parameters:
b2sdk._internal.sync.policy.make_b2_keep_days_actions(source_path, dest_path, dest_folder, transferred, keep_days, now_millis)[source]

Create the actions to hide or delete existing versions of a file stored in b2.

When keepDays is set, all files that were visible any time from keepDays ago until now must be kept. If versions were uploaded 5 days ago, 15 days ago, and 25 days ago, and the keepDays is 10, only the 25 day-old version can be deleted. The 15 day-old version was visible 10 days ago.

Parameters:
  • source_path (Optional[AbstractPath]) – source file object

  • dest_path (Optional[B2Path]) – destination file object

  • dest_folder (AbstractFolder) – destination folder object

  • transferred (bool) – if True, file has been transferred, False otherwise

  • keep_days (int) – how many days to keep a file

  • now_millis (int) – current time in milliseconds