Skip to contents

Copies a specified file to a backup directory, optionally appending a timestamp.

Usage

rfp_fs_backup(
  path_dir_in,
  path_in_file,
  path_dir_out,
  stamp = format(Sys.time(), "%Y%m%d%H%M%S")
)

Arguments

path_dir_in

Character. Directory of the input file.

path_in_file

Character. Name of the input file, relative to path_dir_in.

path_dir_out

Character. Directory where the backup should be stored.

stamp

Character or NULL. Optional string to append to the filename. Defaults to the current time, to the second.

Value

Character. Full path to the newly created backup file.

Details

The backup is named <project>__<file>_<stamp>.<ext>, where <project> is the name of path_dir_in (resolved, so "." names the real directory) and the stamp is to the second. Two projects backing up a file of the same name in the same minute used to write the same name, and the second copy failed or, worse, was taken for the first (#377). A target that already exists is refused, never overwritten. A path_in_file in a subdirectory keeps that subdirectory under path_dir_out.

Examples

if (FALSE) { # \dontrun{
path_dir_in <- "~/Projects/gis/sern_peace_fwcp_2023"
path_in_file <- "background_layers.gpkg"
path_dir_out <- "~/Projects/gis/backups"
rfp_fs_backup(path_dir_in, path_in_file, path_dir_out)
# -> ~/Projects/gis/backups/sern_peace_fwcp_2023__background_layers_<stamp>.gpkg
} # }