Title: | An R package to backup folders to Google Drive with limited permissions |
---|---|
Description: | Backup files and folders to Google Drive without giving access to all of your drive. |
Authors: | Giorgio Comai [aut, cre] |
Maintainer: | Giorgio Comai <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9001 |
Built: | 2024-11-17 04:10:08 UTC |
Source: | https://github.com/giocomai/rbackupr |
Add file to cache
rb_add_file_to_cache(dribble, parent_id, project = NULL)
rb_add_file_to_cache(dribble, parent_id, project = NULL)
dribble |
A dribble. |
parent_id |
Identifier of the parent folder |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
Add folder to cache
rb_add_folder_to_cache( dribble, parent_id, relative_path, project = NULL, cache = TRUE )
rb_add_folder_to_cache( dribble, parent_id, relative_path, project = NULL, cache = TRUE )
dribble |
A dribble. |
parent_id |
Identifier of the parent folder. |
relative_path |
Path relative to base folder. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
Backup files
rb_backup( path, project = NULL, first_level_folders = NULL, first_level_files = TRUE, max_level = 100, recurse = TRUE, glob = NULL, create = TRUE, update = FALSE, cache = TRUE, base_folder = "rbackupr" )
rb_backup( path, project = NULL, first_level_folders = NULL, first_level_files = TRUE, max_level = 100, recurse = TRUE, glob = NULL, create = TRUE, update = FALSE, cache = TRUE, base_folder = "rbackupr" )
path |
Local path where files to backup are stored. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
first_level_folders |
Defaults to NULL. If given, clarifies which folders within the path should be uploaded, keeping the folder structure. |
first_level_files |
Logical, defaults to TRUE. If FALSE, first level files (files that are directly under the project folder, rather than a subfolder) are not included in the backup. |
max_level |
Defaults to 100. Maximum level of sub-folders to backup. Default means it will go 100 times deep into sub-folders. Used also to prevent infinite loops. |
recurse |
Defaults to TRUE. Recurse up to one level. |
glob |
Defaults to NULL. Can be used to filter type of files to upload, e.g. "*.jpg" |
create |
Logical, defaults to TRUE. Create folders if missing. Set to FALSE if you are sure there are no new folders to raise an error if something unexpected happens. |
update |
Logical, defaults to FALSE. If TRUE, checks on Google Drive for newly updated files or folders, otherwise it assumes that only files and folders listed in cache exist online. |
cache |
Logical, defaults to TRUE. Stores locally cached information about base and project folder. |
base_folder |
Name of base folder, defaults to 'rbackupr' |
## Not run: if (interactive()) { rb_backup(path = "folder_to_backup", project = "test_project") } ## End(Not run)
## Not run: if (interactive()) { rb_backup(path = "folder_to_backup", project = "test_project") } ## End(Not run)
Mostly used internally in functions, exported for reference.
rb_check_cache(cache = NULL)
rb_check_cache(cache = NULL)
cache |
Defaults to NULL. If NULL, checks current cache settings. If given, returns given value, ignoring cache. |
Either TRUE or FALSE, depending on current cache settings.
if (interactive()) { rb_check_cache() }
if (interactive()) { rb_check_cache() }
Checks if cache folder exists, if not returns an informative message
rb_check_cache_folder()
rb_check_cache_folder()
If the cache folder exists, returns TRUE. Otherwise throws an error.
# If cache folder does not exist, it throws an error tryCatch(rb_check_cache_folder(), error = function(e) { return(e) } ) # Create cache folder rb_set_cache_folder(path = fs::path( tempdir(), "rb_cache_folder" )) rb_create_cache_folder(ask = FALSE) rb_check_cache_folder()
# If cache folder does not exist, it throws an error tryCatch(rb_check_cache_folder(), error = function(e) { return(e) } ) # Create cache folder rb_set_cache_folder(path = fs::path( tempdir(), "rb_cache_folder" )) rb_create_cache_folder(ask = FALSE) rb_check_cache_folder()
Creates the base cache folder where 'rbackupr' caches data.
rb_create_cache_folder(ask = TRUE)
rb_create_cache_folder(ask = TRUE)
ask |
Logical, defaults to TRUE. If FALSE, and cache folder does not exist, it just creates it without asking (useful for non-interactive sessions). |
Nothing, used for its side effects.
if (interactive()) { rb_create_cache_folder() }
if (interactive()) { rb_create_cache_folder() }
Disable caching for the current session
rb_disable_cache()
rb_disable_cache()
Nothing, used for its side effects.
rb_disable_cache()
rb_disable_cache()
Set up app and scope for the current session
rb_drive_auth( client = NULL, scopes = "https://www.googleapis.com/auth/drive.file", email = gargle::gargle_oauth_email(), cache = gargle::gargle_oauth_cache(), use_oob = gargle::gargle_oob_default(), path = NULL, token = NULL )
rb_drive_auth( client = NULL, scopes = "https://www.googleapis.com/auth/drive.file", email = gargle::gargle_oauth_email(), cache = gargle::gargle_oauth_cache(), use_oob = gargle::gargle_oob_default(), path = NULL, token = NULL )
client |
A Google client. See example, and dedicated gargle documentation. |
scopes |
Defaults to 'https://www.googleapis.com/auth/drive.file'. See Google api documentation for details |
email |
Optional. If specified,
Defaults to the option named |
cache |
Specifies the OAuth token cache. Defaults to the option named
|
use_oob |
Whether to use out-of-band authentication (or, perhaps, a
variant implemented by gargle and known as "pseudo-OOB") when first
acquiring the token. Defaults to the value returned by
If the OAuth client is provided implicitly by a wrapper package, its type
probably defaults to the value returned by
|
path |
JSON identifying the service account, in one of the forms
supported for the |
token |
A token with class Token2.0 or an object of
httr's class |
Nothing, used for its side effects, i.e. logging in your Google account.
if (interactive()) { google_client <- httr::oauth_app( "my-very-own-google-app", key = "123456789.apps.googleusercontent.com", secret = "abcdefghijklmnopqrstuvwxyz" ) rb_drive_auth(google_client) }
if (interactive()) { google_client <- httr::oauth_app( "my-very-own-google-app", key = "123456789.apps.googleusercontent.com", secret = "abcdefghijklmnopqrstuvwxyz" ) rb_drive_auth(google_client) }
Create missing folders and get data frame with identifiers of all given folders
rb_drive_create_folders( folders, parent_id, relative_path = NULL, project = NULL, update = FALSE, base_folder = "rbackupr", cache = TRUE )
rb_drive_create_folders( folders, parent_id, relative_path = NULL, project = NULL, update = FALSE, base_folder = "rbackupr", cache = TRUE )
folders |
A character vector of folder names. |
parent_id |
Identifier of parent folder, where the new folders are to be created. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
update |
Logical, defaults to FALSE. If TRUE, checks on Google Drive for newly updated files or folders, otherwise it assumes that only files and folders listed in cache exist online. |
if (interactive()) { rb_drive_create_folders( folders = c("folder_a", "folder_b"), parent_id = rb_get_project() ) }
if (interactive()) { rb_drive_create_folders( folders = c("folder_a", "folder_b"), parent_id = rb_get_project() ) }
Create or get base folder
rb_drive_find_base_folder( base_folder = "rbackupr", create = FALSE, cache = TRUE )
rb_drive_find_base_folder( base_folder = "rbackupr", create = FALSE, cache = TRUE )
base_folder |
Name of base folder, defaults to "rbackupr". |
create |
Defaults to FALSE. If set to TRUE, the folder is create if not found. |
cache |
Logical, defaults to TRUE. Can be se to NULL, and managed with 'rb_enable_cache()' / 'rb_disable_cache()' |
## Not run: if (interactive()) { rb_drive_find_base_folder() } ## End(Not run)
## Not run: if (interactive()) { rb_drive_find_base_folder() } ## End(Not run)
Create rbackupr project
rb_drive_find_project( project = NULL, base_folder = "rbackupr", create = TRUE, cache = TRUE ) rb_drive_create_project( project = NULL, base_folder = "rbackupr", create = TRUE, cache = TRUE ) rb_get_project( project = NULL, base_folder = "rbackupr", create = TRUE, cache = TRUE )
rb_drive_find_project( project = NULL, base_folder = "rbackupr", create = TRUE, cache = TRUE ) rb_drive_create_project( project = NULL, base_folder = "rbackupr", create = TRUE, cache = TRUE ) rb_get_project( project = NULL, base_folder = "rbackupr", create = TRUE, cache = TRUE )
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
create |
Logical, defaults to TRUE. Creates folder if not existing. |
A dribble corresponding to the project folder.
## Not run: if (interactive()) { rb_drive_find_project(project = "example") } ## End(Not run) ## Not run: if (interactive()) { rb_drive_create_project(project = "example") } ## End(Not run) rb_get_project(project = "example")
## Not run: if (interactive()) { rb_drive_find_project(project = "example") } ## End(Not run) ## Not run: if (interactive()) { rb_drive_create_project(project = "example") } ## End(Not run) rb_get_project(project = "example")
Enable caching for the current session
rb_enable_cache()
rb_enable_cache()
Nothing, used for its side effects.
rb_enable_cache()
rb_enable_cache()
Gets location of cache file
rb_get_cache_file( filename = "rbackupr_cache.sqlite", cache_folder = rbackupr::rb_get_cache_folder() )
rb_get_cache_file( filename = "rbackupr_cache.sqlite", cache_folder = rbackupr::rb_get_cache_folder() )
filename |
Defaults to "rbackupr_cache.sqlite". |
cache_folder |
Defaults to folder set with 'rb_set_cache_folder()' |
A character vector of length one with location of item cache file.
rb_set_cache_folder(path = tempdir()) sqlite_cache_file_location <- rb_get_cache_file() # outputs location of cache file sqlite_cache_file_location
rb_set_cache_folder(path = tempdir()) sqlite_cache_file_location <- rb_get_cache_file() # outputs location of cache file sqlite_cache_file_location
Gets name of table inside the database
rb_get_cache_table_name( type = "project", project = rbackupr::rb_get_project_name() )
rb_get_cache_table_name( type = "project", project = rbackupr::rb_get_project_name() )
type |
Defaults to "project". Type of cache file to output. Values typically used by 'rbackupr' include "base_folder", "projects", and "project". |
project |
Defaults to project name set with 'rbackupr::rb_get_project_name()'. Ignored if the parameter type is not set to "project" |
A character vector of length one with the name of the relevant table in the cache file.
# outputs name of table used in the cache database rb_get_cache_table_name(type = "project", language = "testing_project")
# outputs name of table used in the cache database rb_get_cache_table_name(type = "project", language = "testing_project")
Check if new files appeared inside an online folder
rb_get_files(dribble_id, update = FALSE, project = NULL, cache = TRUE)
rb_get_files(dribble_id, update = FALSE, project = NULL, cache = TRUE)
dribble_id |
The dribble identifier of a folder on Google Drive. |
update |
Logical, defaults to FALSE. If TRUE, checks on Google Drive for newly updated folders. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
cache |
Logical, defaults to TRUE. Stores locally cached information about base and project folder. |
A data frame with three columns: name (of the folder), id (of the dribble of the folder), parent_id (dribble id of the parent folder)
if (interactive()) { rb_get_files(rb_drive_find_project()) }
if (interactive()) { rb_get_files(rb_drive_find_project()) }
Gets folder name based on id
rb_get_folder_name(dribble_id, project = NULL, base_folder = "rbackupr")
rb_get_folder_name(dribble_id, project = NULL, base_folder = "rbackupr")
dribble_id |
The dribble identifier of a folder on Google Drive. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
base_folder |
Name of base folder, defaults to 'rbackupr' |
cache |
Logical, defaults to TRUE. Stores locally cached information about base and project folder. |
A data frame with three columns: name (of the folder), id (of the dribble of the folder), parent_id (dribble id of the parent folder)
if (interactive()) { rb_get_folder_name(rb_drive_find_project()) }
if (interactive()) { rb_get_folder_name(rb_drive_find_project()) }
Gets cached folder with given parent, or update them from Google Drive upon request
rb_get_folders( dribble_id, update = FALSE, project = NULL, base_folder = "rbackupr", cache = TRUE )
rb_get_folders( dribble_id, update = FALSE, project = NULL, base_folder = "rbackupr", cache = TRUE )
dribble_id |
The dribble identifier of a folder on Google Drive. |
update |
Logical, defaults to FALSE. If TRUE, checks on Google Drive for newly updated folders. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
cache |
Logical, defaults to TRUE. Stores locally cached information about base and project folder. |
A data frame with three columns: name (of the folder), id (of the dribble of the folder), parent_id (dribble id of the parent folder)
if (interactive()) { rb_get_folders(rb_drive_find_project()) }
if (interactive()) { rb_get_folders(rb_drive_find_project()) }
Gets parent id of a given folder
rb_get_parent_folder(dribble_id, project = NULL, base_folder = "rbackupr")
rb_get_parent_folder(dribble_id, project = NULL, base_folder = "rbackupr")
dribble_id |
The dribble identifier of a folder on Google Drive. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
cache |
Logical, defaults to TRUE. Stores locally cached information about base and project folder. |
A data frame with three columns: name (of the folder), id (of the dribble of the folder), parent_id (dribble id of the parent folder)
if (interactive()) { rb_get_parent_folder(rb_drive_find_project()) }
if (interactive()) { rb_get_parent_folder(rb_drive_find_project()) }
Based only on cached data-
rb_get_relative_path( dribble_id, project = NULL, max_level = 100, base_folder = "rbackupr" )
rb_get_relative_path( dribble_id, project = NULL, max_level = 100, base_folder = "rbackupr" )
dribble_id |
The dribble identifier of a folder on Google Drive. |
project |
Defaults to NULL. Can be set once per session with 'rb_get_project_name()'. If given, must be a character vector of length one: name of the project. |
max_level |
Defaults to 100. Maximum level of sub-folders to backup. Default means it will go 100 times deep into sub-folders. Used also to prevent infinite loops. |
base_folder |
Name of base folder, defaults to 'rbackupr' |
Consider using a folder out of your current project directory, e.g. 'rb_set_cache_folder("~/R/rbackupr_data/")': you will be able to use the same cache in different projects, and prevent cached files from being sync-ed if you use services such as Nextcloud or Dropbox.
rb_set_cache_folder(path = NULL) rb_get_cache_folder(path = NULL)
rb_set_cache_folder(path = NULL) rb_get_cache_folder(path = NULL)
path |
A path to a location used for caching data. If the folder does not exist, it will be created. |
The path to the caching folder, if previously set; the same path as given to the function; or the default, 'rbackupr_data' is none is given.
if (interactive()) { rb_set_cache_folder(fs::path(fs::path_home_r(), "R", "rbackupr_data")) } rb_get_cache_folder()
if (interactive()) { rb_set_cache_folder(fs::path(fs::path_home_r(), "R", "rbackupr_data")) } rb_get_cache_folder()
Set (or get) name of project for the current session.
rb_set_project(project = NULL) rb_get_project_name(project = NULL)
rb_set_project(project = NULL) rb_get_project_name(project = NULL)
project |
Defaults to NULL. If given, it must be a character vector of length one. Name of a project. It will be used as the root folder for your current project, and located under the 'base_folder' on your Google Drive. |
The project name, if previously set; the same as input if not NULL; or the default, 'rbackupr_data' is none is given.
rb_set_project(project = "weather_csv_files") rb_get_project_name()
rb_set_project(project = "weather_csv_files") rb_get_project_name()