library(syncdr)
#devtools::load_all(".")
# Create .syncdrenv
.syncdrenv = toy_dirs()
#> ■■■■■■■■■■■■■■■ 47% | ETA: 5s
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 87% | ETA: 1s
# Get left and right directories' paths
left <- .syncdrenv$left
right <- .syncdrenv$rightThis article covers functions designed for asymmetric synchronization between two directories.
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 and by_content arguments as
desired (default: by_date = TRUE and
by_content = FALSE).
First, use the compare_directories() function to
generate a sync_status object. Then, provide this object as input to the
synchronization function. The by_date and
by_content arguments will be automatically determined based
on the sync_status.
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:
verbose = TRUEWhen 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)
#> ✔ synchronized2 - 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)
#> ✔ synchronized3 - 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)
#> ✔ synchronized4 - Partial asymmetric synchronization -non common files:
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 by backup_dir. If
backup_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 needed
Force 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.