-
Notifications
You must be signed in to change notification settings - Fork 88
Todrive
- Introduction
- Definitions
- Config file options
- Command line options
- Option details
- Redirect CSV
- Limited Service Account Access
- No Service Account Access
Gam print commands allow the results to be uploaded to Google Drive instead of being saved locally.
By default, Gam titles the uploaded file: "Domain Name - Data Type"; Data Type describes the data being uploaded, e.g. Groups, Orgs, Users. It is uploaded to the root folder of the admin user named in oauth2.txt
.
You can modify the default todrive behavior with options in gam.cfg
or on the command line.
<DriveFileID> ::= <String>
<DriveFolderID> ::= <String>
<TimeZone> ::= <String>
See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
<Locale> ::=
''| #Not defined
ar_eg| #Arabic, Egypt
az_az| #Azerbaijani, Azerbaijan
be_by| #Belarusian, Belarus
bg_bg| #Bulgarian, Bulgaria
bn_in| #Bengali, India
ca_es| #Catalan, Spain
cs_cz| #Czech, Czech Republic
cy_gb| #Welsh, United Kingdom
da_dk| #Danish, Denmark
de_ch| #German, Switzerland
de_de| #German, Germany
el_gr| #Greek, Greece
en_au| #English, Australia
en_ca| #English, Canada
en_gb| #English, United Kingdom
en_ie| #English, Ireland
en_us| #English, U.S.A.
es_ar| #Spanish, Argentina
es_bo| #Spanish, Bolivia
es_cl| #Spanish, Chile
es_co| #Spanish, Colombia
es_ec| #Spanish, Ecuador
es_es| #Spanish, Spain
es_mx| #Spanish, Mexico
es_py| #Spanish, Paraguay
es_uy| #Spanish, Uruguay
es_ve| #Spanish, Venezuela
fi_fi| #Finnish, Finland
fil_ph| #Filipino, Philippines
fr_ca| #French, Canada
fr_fr| #French, France
gu_in| #Gujarati, India
hi_in| #Hindi, India
hr_hr| #Croatian, Croatia
hu_hu| #Hungarian, Hungary
hy_am| #Armenian, Armenia
in_id| #Indonesian, Indonesia
it_it| #Italian, Italy
iw_il| #Hebrew, Israel
ja_jp| #Japanese, Japan
ka_ge| #Georgian, Georgia
kk_kz| #Kazakh, Kazakhstan
kn_in| #Kannada, India
ko_kr| #Korean, Korea
lt_lt| #Lithuanian, Lithuania
lv_lv| #Latvian, Latvia
ml_in| #Malayalam, India
mn_mn| #Mongolian, Mongolia
mr_in| #Marathi, India
my_mn| #Burmese, Myanmar
nl_nl| #Dutch, Netherlands
nn_no| #Nynorsk, Norway
no_no| #Bokmal, Norway
pa_in| #Punjabi, India
pl_pl| #Polish, Poland
pt_br| #Portuguese, Brazil
pt_pt| #Portuguese, Portugal
ro_ro| #Romanian, Romania
ru_ru| #Russian, Russia
sk_sk| #Slovak, Slovakia
sl_si| #Slovenian, Slovenia
sr_rs| #Serbian, Serbia
sv_se| #Swedish, Sweden
ta_in| #Tamil, India
te_in| #Telugu, India
th_th| #Thai, Thailand
tr_tr| #Turkish, Turkey
uk_ua| #Ukrainian, Ukraine
vi_vn| #Vietnamese, Vietnam
zh_cn| #Simplified Chinese, China
zh_hk| #Traditional Chinese, Hong Kong SAR China
zh_tw #Traditional Chinese, Taiwan
You can specify many todrive
options in gam.cfg
.
todrive_clearfilter
Enable/disable clearing the spreadsheet basic filter when uploading data to an existing sheet in an existing file.
Default: False
todrive_clientaccess
Enable/disable use of client access rather than service account access when uploading files with todrive
Default: False
todrive_conversion
Enable/disable conversion of CSV files to Google Sheets when todrive is specified
Default: True
todrive_localcopy
Enable/disable saving a local copy of CSV files when todrive is specified
Default: False
todrive_locale
The Spreadsheet settings Locale value.
See <Locale>
Default: ''
todrive_nobrowser
Enable/disable opening a browser when todrive is specified
Default: False
todrive_noemail
Enable/disable sending an email when todrive is specified
Default: True
todrive_parent
Parent folder for CSV files when todrive is specified;
can be id:<DriveFolderID> or <DriveFolderName>
Default: root
todrive_sheet_timestamp
Enable/disable adding a timestamp to the sheet (tab) title of CSV files when todrive is specified
Default: False
todrive_sheet_timeformat
Format of the timestamp added to the sheet (tab) title of CSV files
See: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
Default: '' which selects an ISO format timestamp
Example: %Y-%m-%dT%H:%M:%S will display as 2020-07-06T17:48:54
todrive_timestamp
Enable/disable adding a timestamp to the title of CSV files when todrive is specified
Default: False
todrive_timeformat
Format of the timestamp added to the title of CSV files
See: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
Default: '' which selects an ISO format timestamp
Example: %Y-%m-%dT%H:%M:%S will display as 2020-07-06T17:48:54
todrive_timezone
The Spreadsheet settings Timezone value.
See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Default: ''
todrive_upload_nodata
Enable/disable uploading CSV files with no data rows
Default: True
todrive_user
Email address of user to receive CSV files when todrive is specified
Default: '' which becomes admin user in admin_email or address from oauth2.txt
Anywhere you can specify todrive
, there are additional subarguments following the todrive
argument that let you title the file, add a description, specify the sheet name,
direct the uploaded file to a particular user and location and add a timestamp to the file title.
<ToDriveAttribute> ::=
(tdaddsheet [<Boolean>])|
(tdbackupsheet (id:<Number>)|<String>)|
(tdclearfilter [<Boolean>])|
(tdcopysheet (id:<Number>)|<String>)|
(tddescription <String>)|
(tdfileid <DriveFileID>)|
(tdlocalcopy [<Boolean>])|
(tdlocale <Locale>)|
(tdnobrowser [<Boolean>])|
(tdnoemail [<Boolean>])|
(tdparent (id:<DriveFolderID>)|<DriveFolderName>)|
(tdsheet (id:<Number>)|<String>)|
(tdsheettimestamp [<Boolean>] [tdsheettimeformat <String>])
(tdsheettitle <String>)|
([tdsheetdaysoffset <Number>] [tdsheethoursoffset <Number])|
(tdtimestamp [<Boolean>] [tdtimeformat <String>])|
([tddaysoffset <Number>] [tdhoursoffset <Number])|
(tdtimezone <TimeZone>)|
(tdtitle <String>)|
(tdcellwrap clip|overflow|wrap)|
(tdupdatesheet [<Boolean>])|
(tduploadnodata [<Boolean>])|
(tduser <EmailAddress>)
By default, a new Google spreadsheet will be created.
Gam titles the uploaded file: "Domain Name - Data Type"; Data Type describes the data being uploaded, e.g. Groups, Orgs, Users.
It is uploaded to the root folder of the admin user named in oauth2.txt
.
-
tduser
- The user to receive the uploaded file; if not specified, thetodrive_user
value from gam.cfg is used; that value defaults to the user named in oauth2.txt.
If tdfileid <DriveFileID>
is not specified, a new file is created.
-
tdparent
- An existing/writable parent folder for the uploaded file; if not specified, thetodrive_parent
value from gam.cfg is used; that value defaults to the root folder.
-
tdtitle
- The title for the uploaded file, if not specified, the Gam default title is used. -
tddescription
- The description for the uploaded file, if not specified, the command line that created the file is used. -
tdsheet <String>
- The sheet name in the uploaded file if it is uploaded as a Google Sheet, if not specified, thetdtitle
is used. -
tdsheettimestamp
- Should a timestamp (of the time the file is uploaded to Google) be added to the sheet (tab) title of the uploaded file; if not specified, thetodrive_sheet_timestamp
value from gam.cfg is used, that value defaults to False. -
tdsheettimeformat
- Format of the timestamp added to the sheet (tab) title of the uploaded file; if not specified, thetodrive_sheet_timeformat
value from gam.cfg is used, that value defaults to '' which selects an ISO format timestamp. -
tdsheetdaysoffset
andtdsheethoursoffset
- Values that subtract time from the sheet (tab) timestamp. If neither value is specified, thetddaysoffset
andtdhoursoffset
values are used. To use a file timestamp offset, but not a sheet (tab) timestamp offset, specifytdsheetdaysoffset 0
. A possible use for these values is as documentation to reflect the end of the time period that the uploaded report covers. -
tdtimestamp
- Should a timestamp (of the time the file is uploaded to Google) be added to the title of the uploaded file; if not specified, thetodrive_timestamp
value from gam.cfg is used, that value defaults to False. -
tdtimeformat
- Format of the timestamp added to the title of the uploaded file; if not specified, thetodrive_timeformat
value from gam.cfg is used, that value defaults to '' which selects an ISO format timestamp. -
tddaysoffset
andtdhoursoffset
- Values that subtract time from the timestamp, they default to 0. A possible use for these values is as documentation to reflect the end of the time period that the uploaded report covers.
-
tdlocale <Locale>
- The Spreadsheet settings Locale value. -
tdtimezone <TimeZone>
- The Spreadsheet settings Timezone value. -
tdcellwrap clip|overflow|wrap
- The Spreadsheet cell wrapping strategy.
-
tdnobrowser
- If False, a browser is opened to view the file uploaded to Google Drive; if not specified, thetodrive_nobrowser
value from gam.cfg is used. -
tdnoemail
- If False, an email is sent totduser
informing them of name and URL of the uploaded file; if not specified, thetodrive_noemail
value from gam.cfg is used.
-
tdlocalcopy
- Should a local copy of the CSV file be saved in addition to the file uploaded to Google Drive; if not specified, thetodrive_localcopy
value from gam.cfg is used.
-
tdfileid <DriveFileID>
- An existing/writable file for the uploaded file. -
tdsheet <String>
- A new sheet with name<String>
will be created and assigned a new sheet ID. All other sheets will be deleted.
-
tdfileid <DriveFileID>
- An existing/writable file for the uploaded file. -
tdsheet <String>
- The title of the new sheet; if not specified, this will be the same value astdtitle
. -
tdaddsheet
- In conjunction withtdfileid <DriveFileID>
andtdsheet <String>
, a new sheet will be added to an existing/writeable file. All other sheets are unaffected.
-
tdfileid <DriveFileID>
- An existing/writable file for the uploaded file. -
tdsheet (id:<Number>)|<String>
- An existing sheet with ID<Number>
or name<String>
will be updated. All other sheets are unaffected. -
tdupdatesheet
- In conjunction withtdfileid <DriveFileID>
andtdsheet id:<Number>
, an existing sheet in an existing/writeable file is updated. -
tdsheettitle
- In conjunction withtdfileid <DriveFileID>
andtdsheet id:<Number>
andtdupdatesheet
, an existing sheet in an existing/writeable file is updated and renamed. -
tdupdatesheet
- In conjunction withtdfileid <DriveFileID>
andtdsheet <String>
, an existing sheet in an existing/writeable file is updated; it will be created if necessary. -
tdbackupsheet (id:<Number>)|<String>
- An existing sheet will be updated with the contents oftdsheet (id:<Number>)|<String>)
before that sheet is updated. -
tdcopysheet (id:<Number>|<String>
- An existing sheet will be updated with the contents oftdsheet (id:<Number>)|<String>)
after that sheet is updated. -
tdclearfilter [<Boolean>]
- Should the spreadsheet basic filter be cleared; if not specified, thetodrive_clearfilter
value from gam.cfg is used, that value defaults to False. When False, the current/default behavior, the data suppressed by an existing filter is not replaced by the uploaded data. This might be desirable if you wanted to compare the previous and current data, but in general you probably want a value of True so that the uploaded data completely replaces the existing data.
-
tduploadnodata
- Enable/disable uploading CSV files with no data rows; if not specified, thetodrive_upload_nodata
value from gam.cfg is used; that value defaults to true
You can specify todrive
options in conjunction with redirect csv
.
redirect csv <FileName> [multiprocess] [append] [noheader] [charset <Charset>]
[columndelimiter <Character>] [quotechar <Character>]
[todrive <ToDriveAttribute>*]
If you are doing redirect csv <FileName> multiprocess
, it is more efficient to specify todrive <ToDriveAttribute>*
as part of
the redirect as verification of the todrive
settings, which can invole several API calls, is done once rather than in each of the subprocesses.
columndelimiter <Character>
and quotechar <Character>
will not generally be used with todrive
as
Google Sheets only recognizes ,
as the column delimiter and "
as the quote character.
Generate a list of user IDs and names, title the file "User IDs and Names", upload it to the "GAM Reports" folder of usermgr@domain.com, add a timestamp to the title.
gam print users fields id,name todrive tdtitle "User IDs and Names" tdtimestamp true tduser usermgr@domain.com tdparent "GAM Reports"
Generate a list of CrOS devices and update an existing sheet in a Google spreadsheet. The sheet ID is preserved so other appplications can access the data using the file ID and sheet ID. By setting 'tdtimestamp true`, the file name will the updated to reflect the time of execution, but the file ID will not change.
gam redirect csv - todrive tdtitle "CrOS" tdtimestamp true tdfileid 12345-mizZ6Q2vP1rcHQH3tAZQt_NVB2EOxmS2SU3yM tdsheet id:0 tdupdatesheet true print cros fields deviceId,notes,orgUnitPath,serialNumber,osversion
For a collection of users, generate a list of files shared with anyone; combine the output for all users into a single file.
gam redirect csv - multiprocess todrive tdtitle AnyoneShares-All csv Users.csv gam user ~primaryEmail print filelist fields id,name,permissions pm type anyone em
For a collection of users, generate a list of files shared with anyone; generate a separate file for each user. The two forms of the command are equivalent.
gam csv Users.csv gam redirect csv - todrive tdtitle "AnyoneShares-~~primaryEmail~~" user ~primaryEmail print filelist fields id,name,permissions pm type anyone em
gam csv Users.csv gam user ~primaryEmail print filelist fields id,name,permissions pm type anyone em todrive tdtitle "AnyoneShares-~~primaryEmail~~"
Suppose you have a spreadsheet with sheets Monday
... Friday
, Backup Monday
... Backup Friday
and Latest
.
Each day you run a report to update the current day sheet (Tuesday
), you want to backup the data first (Backup Tuesday
) and
you want the updated data copied to Latest
so you don't have to remember what the day of the week is.
gam redirect csv - todrive tdfileid <DriveFileID> tdupdatesheet tdsheet Tuesday tdbackupsheet "Backup Tuesday" tdcopysheet "Latest" ...
If you want to limit a user's service account access but still allow `todrive', issue the following command and authorize the additional service account APIs:
gam user user@domain.com update serviceaccount`
Authorize these APIs:
Drive API - todrive
Gmail API - Send Messages - including todrive
Sheets API - todrive
By default, todrive
uses service account access to upload files, set sheet names and send email notifications.
If it is not possible to allow the user any service account access (this is not common),
perform the following command so that the user can upload files with todrive
using client access.
gam config todrive_clientaccess true save
Issue the following command and authorize the additional client access APIs:
gam oauth create
Authorize these APIs:
Drive API - todrive_clientaccess
Gmail API - todrive_clientaccess
Sheets API - todrive_clientaccess
When todrive_clientaccess
is true, todrive_user\tduser
is ignored, all actions are performed as the user specified in oauth2.txt
.
Need more help? Ask on the GAM Discussion Group
Update History
Installation
- How to Install GAM7
- How to Uograde GAMADV-XTD3 to GAM7
- How to Upgrade Legacy GAM to GAM7
- How to Update GAM7
- Install GAM as Python Library
- GAM7 on Chrome OS Devices
- GAM7 on Android Devices
- Google Network Addresses
- HTTPS Proxy
- SSL Root CA Certificates
- How to Uninstall GAM7
Configuration
- Authorization
- GAM Configuration
- Running GAM7 securely on a Google Compute Engine
- Using GAM7 with a delegated admin service account
- Using GAM7 with a YubiKey
Notes and Information
- Upgrade Benefits
- Questions? Visit the GAM Discussion Forum
- GAM Public Chat Room
- Scripts
- Other Resources
- Drive REST API v3
- BNF Syntax
- GAM Return Codes
- Python Regular Expressions
- Rclone
Definitions
Command Processing
- Bulk Processing
- Command Line Parsing
- Command Logging and Progress
- Command data from Google Docs/Sheets/Storage
- CSV Special Characters
- CSV Input Filtering
- CSV Output Filtering
- Meta Commands and File Redirection
- Permission matches
- Tag Replace
- Todrive
Collections
Client Access
- Addresses
- Administrators
- Alert Center
- Aliases
- Calendars
- Calendars - Access
- Calendars - Events
- Chrome Auto Update Expiration Counts
- Chrome Browser Cloud Management
- Chrome Device Needs Attention Counts
- Chrome Installed Apps
- Chrome Policies
- Chrome Printers
- Chrome Profile Management
- Chrome Version Counts
- Chrome Version History
- ChromeOS Devices
- Classroom - Courses
- Classroom - Guardians
- Classroom - Invitations
- Classroom - Membership
- Cloud Channel
- Cloud Identity Devices
- Cloud Identity Groups
- Cloud Identity Groups - Membership
- Cloud Identity Policies
- Cloud Storage
- Context Aware Access Levels
- Customer
- Domains
- Domains - Verification
- Domain People - Contacts & Profiles
- Domain Shared Contacts - Global Address List
- Email Audit Monitor
- Find File Owner
- Google Data Transfers
- Groups
- Groups - Membership
- Inbound SSO
- Licenses
- Mobile Devices
- Organizational Units
- Reports
- Reseller
- Resources
- Send Email
- Schemas
- Shared Drives
- Sites
- Users
- Unmanaged Accounts
- Users - Signout and Turn off 2-Step Verification
- Vault - Takeout
- Version and Help
Special Service Account Access
Service Account Access
- Users - Analytics Admin
- Users - Application Specific Passwords
- Users - Backup Verification Codes
- Users - Calendars
- Users - Calendars - Access
- Users - Calendars - Events
- Users - Chat
- Users - Classification Labels
- Users - Classroom - Profile
- Users - Deprovision
- Users - Contacts
- Users - Contacts - Delegates
- Users - Drive - File Selection
- Users - Drive - Activity/Settings
- Users - Drive - Cleanup
- Users - Drive - Comments
- Users - Drive - Copy/Move
- Users - Drive - Files-Display
- Users - Drive - Files-Manage
- Users - Drive - Orphans
- Users - Drive - Ownership
- Users - Drive - Permissions
- Users - Drive - Query
- Users - Drive - Revisions
- Users - Drive - Shortcuts
- Users - Drive - Transfer
- Users - Forms
- Users - Gmail - Client Side Encryption
- Users - Gmail - Delegates
- Users - Gmail - Filters
- Users - Gmail - Forwarding
- Users - Gmail - Labels
- Users - Gmail - Messages/Threads
- Users - Gmail - Profile
- Users - Gmail - S/MIME
- Users - Gmail - SendAs/Signature/Vacation
- Users - Gmail - Settings
- Users - Group Membership
- Users - Keep
- Users - Looker Studio
- Users - Meet
- Users - Classroom - Profile
- Users - People - Contacts & Profiles
- Users - Photo
- Users - Profile Sharing
- Users - Shared Drives
- Users - Spreadsheets
- Users - Tasks
- Users - Tokens
- Users - YouTube