Asymmetric Synchronization Functions
asymmetric-synchronization.Rmd
library(syncdr)
#devtools::load_all(".")
# Create .syncdrenv
.syncdrenv = toy_dirs()
#> ■■■■■■■■■ 27% | ETA: 8s
#> ■■■■■■■■■■■■■■■■■■■ 60% | ETA: 5s
# Get left and right directories' paths
left <- .syncdrenv$left
right <- .syncdrenv$right
This article covers functions designed for asymmetric synchronization between two directories.
What is asymmetric synchronization?
This is a one-way synchronization: you have a master/leader directory, and you want changes made there to be reflected in a secondary/follower directory.
⏭️ For all synchronization functions below, note that synchronization occurs from left to right. This mean that the right directory will mirror the contents of the left directory.
Key Points:
When using these synchronization functions, you have two options for providing inputs:
Specify the paths for both the left and right directories, and set the
by_date
andby_content
arguments as desired (default:by_date = TRUE
andby_content = FALSE
).First, use the
compare_directories()
function to generate a sync_status object. Then, provide this object as input to the synchronization function. Theby_date
andby_content
arguments will be automatically determined based on thesync_status
.
Types of asymmetric synchronization
syncdr
allows to perform a specific set of
asymmetric synchronization actions, so that you can choose
which one to execute depending on your needs
Type of synchronization |
Actions on common files |
Actions on non-common files |
---|---|---|
Full asymmetric synchronization: |
|
|
Partial asymmetric synchronization -common files: |
|
no actions |
Full asymmetric synchronization of non common files |
no actions |
|
Partial asymmetric asymmetric synchronization of non common files: |
no actions |
|
Let’s see them in actions through the examples below:
*️⃣ Note: verbose = TRUE
When executing any synchronization, you have the option to enable
verbose mode by setting verbose = TRUE
. This will display
the tree structure of both directories BEFORE and AFTER the
synchronization
1 - Full asymmetric synchronization:
# With leader/master directory being the left directory
# Option 1
full_asym_sync_to_right(left_path = left,
right_path = right,
by_content = TRUE)
#> ✔ synchronized
#>
# Option 2
sync_status <- compare_directories(left_path = left,
right_path = right,
by_content = TRUE)
full_asym_sync_to_right(sync_status = sync_status)
#> ✔ synchronized
#>
# With leader/master directory being the right directory
sync_status <- compare_directories(left_path = right, #notice args changing here
right_path = left,
by_content = TRUE)
full_asym_sync_to_right(sync_status = sync_status)
#> ✔ synchronized
#>
2 - Partial asymmetric synchronization -common files:
sync_status <- compare_directories(left_path = left,
right_path = right)
common_files_asym_sync_to_right(sync_status = sync_status)
#> ✔ synchronized
#>
3 - Full asymmetric synchronization -non common files:
sync_status <- compare_directories(left_path = left,
right_path = right)
update_missing_files_asym_to_right(sync_status = sync_status)
#> ✔ synchronized
#>
4 - Partial asymmetric synchronization -non common files:
sync_status <- compare_directories(left_path = left,
right_path = right)
partial_update_missing_files_asym_to_right(sync_status = sync_status)
#> ✔ synchronized
#>
Synchronizing Using Additional Options
To retain more control over the synchronization process, you can utilize two additional options available for all synchronization functions: backup and force.
Backup Option: Setting
backup = TRUE
will create a backup (copy) of the right directory before performing the synchronization. This backup is stored in the location specified bybackup_dir
. Ifbackup_dir
is not provided, the backup will be saved in a temporary directory (tempdir
). This ensures that you can revert to the previous state if neededForce Option: By default, force = TRUE, which means the function will proceed directly with the synchronization without any interruptions. If you set force = FALSE, the function will first display a preview of the proposed actions, including which files will be copied and which will be deleted. You will be prompted to confirm whether you wish to proceed with these actions. Synchronization will only continue if you agree; otherwise, it will be aborted, and no changes will be made to the directories.