Clone Files to Cloud Storage: Difference between revisions

From WickyWiki
m service account maybe not necessary
Line 18: Line 18:
</syntaxhighlight>
</syntaxhighlight>


= Configure =
= Configure Google Drive Client Access =
 
== Google Drive Client Access ==


Configure the account :
Configure the account :
Line 28: Line 26:
* Select "ENABLE APIS AND SERVICES" and enable the "Google Drive API"
* Select "ENABLE APIS AND SERVICES" and enable the "Google Drive API"


=== Configure rclone ===
== Configure rclone ==


Note:
Note:
* This will partly be repeated after the access token has expired.
* Token renewal seems to be done by rclone automatically. Still
* For automatic configuration you will need a browser in a desktop session, for info on headless configuration go here:
** https://rclone.org/remote_setup/


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 60: Line 60:
</syntaxhighlight>
</syntaxhighlight>


== Google Drive Service Account ==
= Configure Google Drive Service Account =


Note:  
Note:  
* The service account and the main account do not share access to Google Drive files.  
* The service account and the main account do not share access to Google Drive files.  
* You can not use the Webinterface to access the service account Google Drive files. However, a service account is still the preferred method if you want to machine-to-machine interaction.
* You can not use the Webinterface to access the service account Google Drive files. However, a service account is the preferred method for machine-to-machine interaction.
* To be able to use 'drive-impersonate' you need a "G Suite domain", for this you will need to use a domain that you 'own'. There are various ways to prove you 'own' a domain.
* To be able to use 'drive-impersonate' you need a "G Suite domain", for this you will need to use a domain that you 'own'. There are various ways to prove you 'own' a domain.


Create a service account :
Create a service account :
* Go to the Developer Console: https://console.developers.google.com/apis/dashboard
* Go to the Developer Console: https://console.developers.google.com/apis/dashboard
* Login if needed, makes sure you have the corrrect account
* Login if needed, makes sure you have the correct account
* Create a project and select it
* Create a project and select it
* Select "ENABLE APIS AND SERVICES" and enable the "Google Drive API"
* Select "ENABLE APIS AND SERVICES" and enable the "Google Drive API"
Line 75: Line 75:
* Select "Key type JSON" and save the file (rclone.json) for use with rclone config
* Select "Key type JSON" and save the file (rclone.json) for use with rclone config


=== Configure rclone ===
== Configure rclone ==


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
rclone config
rclone config
n                  # New remote
n                  # New remote
name> gdrive        # Any short name
name> gdrive1      # Any short name
Storage Type> drive # Google Drive
Storage Type> drive # Google Drive
client_id>  
client_id>  
Line 95: Line 95:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
rclone lsf -v "gdrive:"
rclone lsf -v "gdrive1:"
</syntaxhighlight>
</syntaxhighlight>


Line 101: Line 101:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
rclone sync -v /home/pi/Documents "gdrive:/rclone/"
rclone sync -v /home/pi/Documents "gdrive1:/rclone/"
</syntaxhighlight>
</syntaxhighlight>


Line 111: Line 111:
* https://rclone.org/crypt/
* https://rclone.org/crypt/


Define an encrypted target, in this example the configured remote 'gdrive' is used as storage in subfolder 'crypt'.
Define an encrypted target, in this example the configured remote 'gdrive1' is used as storage in subfolder 'crypt'.


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 118: Line 118:
name> gdrive2
name> gdrive2
Storage> crypt
Storage> crypt
remote> gdrive:/crypt
remote> gdrive1:/crypt
filename_encryption> 2
filename_encryption> 2
directory_name_encryption> 1
directory_name_encryption> 1
Line 149: Line 149:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
rclone about gdrive:
rclone about gdrive1:
</syntaxhighlight>
</syntaxhighlight>


Clean trash / bin:
Clean trash / bin. Note that this is done in background, it may take some time to finish:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
rclone cleanup gdrive:
rclone cleanup gdrive1:
</syntaxhighlight>
</syntaxhighlight>


Line 161: Line 161:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
rclone tree --sort-modtime --human gdrive:/ | tail -5
rclone tree --sort-modtime --human gdrive1:/ | tail -5
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:10, 16 October 2018


Links

Install

wget https://rclone.org/install.sh
chmod +x install.sh
sudo ./install.sh

Configure Google Drive Client Access

Configure the account :

Configure rclone

Note:

  • Token renewal seems to be done by rclone automatically. Still
  • For automatic configuration you will need a browser in a desktop session, for info on headless configuration go here:
rclone config
	n                   # New remote
	name> gdrive1       # Any short name
	Storage Type> drive # Google Drive
	client_id> 
	client_secret> 
	scope> drive        # Full access all files, excluding Application Data Folder
	root_folder_id> 
	service_account_file>
	Auto config> y      #your browser will open, login with your gmail account and allow access
	Team drives> n	
	is this OK?> y

Sync from local to Google Drive, name 'gdrive1', folder 'rclone':

rclone sync -v ~/test4.txt "gdrive1:/rclone/"

Sync from Google Drive to local:

rclone sync -v  "gdrive1:/rclone/test4.txt" ~/rclone/

Configure Google Drive Service Account

Note:

  • The service account and the main account do not share access to Google Drive files.
  • You can not use the Webinterface to access the service account Google Drive files. However, a service account is the preferred method for machine-to-machine interaction.
  • To be able to use 'drive-impersonate' you need a "G Suite domain", for this you will need to use a domain that you 'own'. There are various ways to prove you 'own' a domain.

Create a service account :

  • Go to the Developer Console: https://console.developers.google.com/apis/dashboard
  • Login if needed, makes sure you have the correct account
  • Create a project and select it
  • Select "ENABLE APIS AND SERVICES" and enable the "Google Drive API"
  • Use the " Create Credentials" button to create a "Service account key". Pick a "Service account name". "Role" can be empty.
  • Select "Key type JSON" and save the file (rclone.json) for use with rclone config

Configure rclone

rclone config
	n                   # New remote
	name> gdrive1       # Any short name
	Storage Type> drive # Google Drive
	client_id> 
	client_secret> 
	scope> drive        # Full access all files, excluding Application Data Folder
	root_folder_id> 
	service_account_file> /home/pi/Scripts/rclone.json
	Edit advanced config?> n
	Configure this as a team drive?> n
	is this OK?> y

List contents:

rclone lsf -v "gdrive1:"

Sync:

rclone sync -v /home/pi/Documents "gdrive1:/rclone/"

List of rclone commands:

Encryption

Define an encrypted target, in this example the configured remote 'gdrive1' is used as storage in subfolder 'crypt'.

rclone config
	e/n/d/r/c/s/q> n
	name> gdrive2
	Storage> crypt
	remote> gdrive1:/crypt
	filename_encryption> 2
	directory_name_encryption> 1
	type password y/g/n> y
	seed y/g/n> n
	advanced config y/n> n

Sync from local to Google Drive, name 'gdrive2':

rclone sync -v /home/pi/Documents "gdrive2:/"

List contents (encrypted):

rclone lsf -v "gdrive:/crypt"

List contents (decrypted):

rclone lsf -v "gdrive2:"

Other commands

Used space / free space / trashed:

rclone about gdrive1:

Clean trash / bin. Note that this is done in background, it may take some time to finish:

rclone cleanup gdrive1:

Five most recently modified files with size and total number of files:

rclone tree --sort-modtime --human gdrive1:/ | tail -5