b2sdk.sync.policy

class b2sdk.sync.policy.NewerFileSyncMode[source]

Bases: enum.Enum

An enumeration.

SKIP = 101
REPLACE = 102
RAISE_ERROR = 103
class b2sdk.sync.policy.CompareVersionMode[source]

Bases: enum.Enum

An enumeration.

MODTIME = 201
SIZE = 202
NONE = 203
class b2sdk.sync.policy.AbstractFileSyncPolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: object

Abstract policy class.

DESTINATION_PREFIX = NotImplemented
SOURCE_PREFIX = NotImplemented
__init__(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]
Parameters
  • source_file (b2sdk.v1.File) – source file object

  • source_folder (b2sdk.v1.AbstractFolder) – source folder object

  • dest_file (b2sdk.v1.File) – destination file object

  • dest_folder (b2sdk.v1.AbstractFolder) – destination folder object

  • now_millis (int) – current time in milliseconds

  • keep_days (int) – days to keep before delete

  • newer_file_mode (b2sdk.v1.NEWER_FILE_MODES) – 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 (b2sdk.v1.COMPARE_VERSION_MODES) – how to compare source and destination files

classmethod files_are_different(source_file, dest_file, compare_threshold=None, compare_version_mode=<CompareVersionMode.MODTIME: 201>, newer_file_mode=<NewerFileSyncMode.RAISE_ERROR: 103>)[source]

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

Parameters
  • source_file (b2sdk.v1.File) – source file object

  • dest_file (b2sdk.v1.File) – destination file object

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

  • compare_version_mode (b2sdk.v1.CompareVersionMode) – source file version comparator method

  • newer_file_mode (b2sdk.v1.NewerFileSyncMode) – newer destination handling method

get_all_actions()[source]

Yield file actions.

class b2sdk.sync.policy.DownPolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: b2sdk.sync.policy.AbstractFileSyncPolicy

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

DESTINATION_PREFIX = 'local://'
SOURCE_PREFIX = 'b2://'
class b2sdk.sync.policy.UpPolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: b2sdk.sync.policy.AbstractFileSyncPolicy

File is synced up (from disk the cloud).

DESTINATION_PREFIX = 'b2://'
SOURCE_PREFIX = 'local://'
class b2sdk.sync.policy.UpAndDeletePolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: b2sdk.sync.policy.UpPolicy

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

class b2sdk.sync.policy.UpAndKeepDaysPolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: b2sdk.sync.policy.UpPolicy

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

class b2sdk.sync.policy.DownAndDeletePolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: b2sdk.sync.policy.DownPolicy

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

class b2sdk.sync.policy.DownAndKeepDaysPolicy(source_file, source_folder, dest_file, dest_folder, now_millis, keep_days, newer_file_mode, compare_threshold, compare_version_mode=<CompareVersionMode.MODTIME: 201>)[source]

Bases: b2sdk.sync.policy.DownPolicy

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

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

Create a note message for delete action.

Parameters
  • version (b2sdk.v1.FileVersionInfo) – an object which contains file version info

  • index (int) – file version index

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

b2sdk.sync.policy.make_b2_delete_actions(source_file, dest_file, dest_folder, transferred)[source]

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

Parameters
  • source_file (b2sdk.v1.File) – source file object

  • dest_file (b2sdk.v1.File) – destination file object

  • dest_folder (b2sdk.v1.AbstractFolder) – destination folder

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

b2sdk.sync.policy.make_b2_keep_days_actions(source_file, dest_file, 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_file (b2sdk.v1.File) – source file object

  • dest_file (b2sdk.v1.File) – destination file object

  • dest_folder (b2sdk.v1.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