Creates a local backup of a Google Drive file.
Usage
backup_g_file(
g_id,
path,
type = NULL,
path_gcp_service_account_key = Sys.getenv("PATH_GCP_KEY_ZDA"),
overwrite = TRUE,
force = FALSE,
quiet = TRUE
)Arguments
- g_id
Google Drive file ID. A character scalar.
- path
Path to the local file backup destination. A character scalar.
- type
Desired type of the Google Drive file to be backed up. Only consulted if
g_ididentifies a native Google Apps file. Will be processed viagoogledrive::drive_mime_type(), so it can either be a file extension like"pdf", a full MIME type like"application/pdf", orNULLto determine the type based on the file extension ofpath(if none is specified, falls back on the default type determined by the Google Drive API). Note thattypetakes precedence over a possible file extension ofpath, but specifying only the latter should normally suffice.- path_gcp_service_account_key
Path to the GCP Service Account Key JSON file. See
auth_g_drive_gcp()for details.- overwrite
Whether or not to overwrite an already existing file under
path.- force
Whether or not to force overwriting the file regardless whether it has changed since the last backup or not.
- quiet
Whether or not to suppress printing status output from googledrive operations.
Value
An object of class dribble, a tibble with one row per file if local backup was (over)written, otherwise NULL, meaning
the remote file hasn't deviated from the local backup since the last run, invisibly.
Details
Essentially a convenience wrapper around googledrive::drive_download().
If a Google Sheet that includes multiple worksheets is backed up to a file type that doesn't support
worksheets like "csv", only the default (first) worksheet is written. In contrast, backup_g_sheet() allows to specify any worksheet to be backed up (but
always writes a single worksheet only regardless of the filetype).
See also
Other Google Apps functions:
auth_g_drive_gcp(),
auth_g_sheets_gcp(),
backup_g_sheet(),
g_file_mod_time(),
upload_to_g_drive()