b2sdk._internal.sync.sync
- b2sdk._internal.sync.sync.count_files(local_folder, reporter, policies_manager)[source]
Count all of the files in a local folder.
- Parameters:
local_folder (b2sdk._internal.scan.folder.AbstractFolder) – a folder object.
reporter – reporter object
- class b2sdk._internal.sync.sync.KeepOrDeleteMode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
Mode of dealing with old versions of files on the destination
- DELETE = 301
delete the old version as soon as the new one has been uploaded
- KEEP_BEFORE_DELETE = 302
keep the old versions of the file for a configurable number of days before deleting them, always keeping the newest version
- NO_DELETE = 303
keep old versions of the file, do not delete anything
- class b2sdk._internal.sync.sync.Synchronizer(max_workers, policies_manager=<b2sdk._internal.scan.policies.ScanPoliciesManager object>, dry_run=False, allow_empty_source=False, newer_file_mode=NewerFileSyncMode.RAISE_ERROR, keep_days_or_delete=KeepOrDeleteMode.NO_DELETE, compare_version_mode=CompareVersionMode.MODTIME, compare_threshold=None, keep_days=None, sync_policy_manager=<b2sdk._internal.sync.policy_manager.SyncPolicyManager object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]
Bases:
object
Copies multiple “files” from source to destination. Optionally deletes or hides destination files that the source does not have.
The synchronizer can copy files:
From a B2 bucket to a local destination.
From a local source to a B2 bucket.
From one B2 bucket to another.
Between different folders in the same B2 bucket. It will sync only the latest versions of files.
By default, the synchronizer:
Fails when the specified source directory doesn’t exist or is empty. (see
allow_empty_source
argument)Fails when the source is newer. (see
newer_file_mode
argument)Doesn’t delete a file if it’s present on the destination but not on the source. (see
keep_days_or_delete
andkeep_days
arguments)Compares files based on modification time. (see
compare_version_mode
andcompare_threshold
arguments)
- Parameters:
sync_policy_manager (
SyncPolicyManager
) –upload_mode (
UploadMode
) –
- __init__(max_workers, policies_manager=<b2sdk._internal.scan.policies.ScanPoliciesManager object>, dry_run=False, allow_empty_source=False, newer_file_mode=NewerFileSyncMode.RAISE_ERROR, keep_days_or_delete=KeepOrDeleteMode.NO_DELETE, compare_version_mode=CompareVersionMode.MODTIME, compare_threshold=None, keep_days=None, sync_policy_manager=<b2sdk._internal.sync.policy_manager.SyncPolicyManager object>, upload_mode=UploadMode.FULL, absolute_minimum_part_size=None)[source]
Initialize synchronizer class and validate arguments
- Parameters:
max_workers (int) – max number of workers
policies_manager – object which decides which files to process
dry_run (bool) – test mode, does not actually transfer/delete when enabled
allow_empty_source (bool) – if True, do not check whether source folder is empty
newer_file_mode (b2sdk.v2.NewerFileSyncMode) – setting which determines handling for destination files newer than on the source
keep_days_or_delete (b2sdk.v2.KeepOrDeleteMode) – setting which determines if we should delete or not delete or keep for keep_days
compare_version_mode (b2sdk.v2.CompareVersionMode) – how to compare the source and destination files to find new ones
compare_threshold (int) – should be greater than 0, default is 0
keep_days (int) – if keep_days_or_delete is b2sdk.v2.KeepOrDeleteMode.KEEP_BEFORE_DELETE, then this should be greater than 0
sync_policy_manager (
SyncPolicyManager
) – object which decides what to do with each file (upload, download, delete, copy, hide etc)upload_mode (
UploadMode
) – determines how file uploads are handledabsolute_minimum_part_size (
Optional
[int
]) – minimum file part size for large filessync_policy_manager –
upload_mode –
absolute_minimum_part_size –
- sync_folders(source_folder, dest_folder, now_millis, reporter, encryption_settings_provider=<b2sdk._internal.sync.encryption_provider.ServerDefaultSyncEncryptionSettingsProvider object>)[source]
Syncs two folders. Always ensures that every file in the source is also in the destination. Deletes any file versions in the destination older than history_days.
- Parameters:
source_folder (
AbstractFolder
) – source folder objectdest_folder (
AbstractFolder
) – destination folder objectnow_millis (
int
) – current time in millisecondsreporter (
Optional
[SyncReport
]) – progress reporterencryption_settings_provider (
AbstractSyncEncryptionSettingsProvider
) – encryption setting provider