Additional Sync Controls: Backup and Force
additional-options.Rmd
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
, make all functions proceed directly with the synchronization without user’s confirmation. However, to avoid unintended changes to your directories, you can setforce = FALSE
. This way 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.
For example, suppose you are performing a full asymmetric synchronization of your, say, left and right directories. This type of synchronization entails that certain files will be copied over to the right directory, as well as that certain files will be deleted from it.
To maintain greater control over the process, you can allow the function to perform the synchronization while simultaneously storing a copy of the original directory before any changes occur. This way, you can revert to the original if needed.
# generate toy directories
e <- toy_dirs()
#> ■■■■■■■■■ 27% | ETA: 8s
#> ■■■■■■■■■■■■■■■■■■■ 60% | ETA: 5s
.syncdrenv.1 <- syncdr:::copy_temp_environment()
# Get left and right directories' paths
left <- .syncdrenv.1$left
right <- .syncdrenv.1$right
sync_status <- compare_directories(left, right)
# call sync function
full_asym_sync_to_right(sync_status = sync_status,
backup = TRUE)
#> ✔ synchronized
#>
Another option is to visualize a preliminary check, before the synchronization takes place. This can be done taking advantage of the force option. Note that prompt for user confirmation will work when you run the function interactively in your R session. However, this interactive prompt will not be functional within this article.
full_asym_sync_to_right(sync_status = sync_status,
force = FALSE)
#> These files will be DELETED in right
#>
#> |Files |Action |
#> |:-------------------|:-------------|
#> |/C/C1_duplicate.Rds |To be deleted |
#> |/D/D3.Rds |To be deleted |
#> |/E/E1.Rds |To be deleted |
#> |/E/E2.Rds |To be deleted |
#> |/E/E3.Rds |To be deleted |
#> These files will be COPIED (overwriting if present) to right
#>
#>
#> |Files |Action |
#> |:---------|:------------|
#> |/A/A1.Rds |To be copied |
#> |/A/A2.Rds |To be copied |
#> |/A/A3.Rds |To be copied |
#> |/B/B3.Rds |To be copied |
#> Do you want to proceed? Type your answer (Yes/no/cancel)
#> ✔ synchronized
#>
#You will need to type `no` or 'cancel' to stop the synchronization