Clone Files to Cloud Storage: Difference between revisions

From WickyWiki
mNo edit summary
 
(25 intermediate revisions by the same user not shown)
Line 12: Line 12:
= Install =
= Install =


<syntaxhighlight lang=bash>
<source lang=bash>
sudo apt install rclone
</source>
 
Or from the source:
 
<source lang=bash>
wget https://rclone.org/install.sh
wget https://rclone.org/install.sh
chmod +x install.sh
chmod +x install.sh
sudo ./install.sh
sudo ./install.sh
</syntaxhighlight>
</source>
 
= Configure Google Drive Client Access =
 
Configure the account :
* Go to the Developer Console: https://console.developers.google.com/apis/dashboard
* Login if needed, make sure you have the correct account
* Create a project and select it
* Select "ENABLE API'S AND SERVICES" and enable the "Google Drive API"
 
Note:
* Token renewal seems to be managed by rclone.
 
= Configure rclone =
 
== Rclone config file ==
 
If you have a configuration file 'rclone.conf', you can restore a configuration by placing it in the correct location ~/.config/rclone/rclone.conf
 
<source lang=bash>
sudo cp -v rclone.conf ~/.config/rclone/rclone.conf
</source>
 
== Rclone config via SSH session ==
 
For automatic configuration you will need a regular browser in a desktop session, info on headless configuration:
* https://rclone.org/remote_setup/
 
For example, we are configuring the drive within a PuTTY ssh session from windows. The authentication proces requires a one-time login to your Google account with a regular browser. In order to make this possible we create a SSH tunnel to make the port available outside the PuTTY session. The port that is used by Rclone is '53682'.


= Configure =
What is our IP address?


== Google account and Google Drive API ==
<source lang=bash>
ifconfig
</source>


[[TODO: Google account and Google Drive API]]
Let's say it is '192.168.1.2'. Now create ssh tunnel (login) make http://localhost:53682 available via http://192.168.1.2:53682 :


== Google Drive Client Access ==
<source lang=bash>
ssh -fN -L 192.168.1.2:53682:localhost:53682 user1@192.168.1.2
</source>


This will grant access for a couple of hours.
You will have to login to the ssh session with 'user1'. This tunnel will remain running as a background proces. We can now configure the Google Drive access.


<syntaxhighlight lang=bash>
<source lang=bash>
rclone config
rclone config
n/s/q> n        # new
d                # delete earlier attempts
name> remote    # 'remote' is an example name, pick what you want
n                 # new
Storage> drive   # type=Google Drive
name> gdrive1
client_id>      
Storage> drive   # google drive
client_secret>  
client_id>
scope> 1        # Select your scope, 1 = full
client_secret>
root_folder_id>
scope> drive            # full access all files
svc acc file>  
service_account_file>
Auto config> y   #login with your gmail account and allow access
Edit advanced config> n
Team drives> n
Auto config> y         # copy url
</syntaxhighlight>
...
</source>
 
The configuration will give you an URL and starts waiting for a response.


From local to Google Drive, name 'remote', folder 'rclone'
# Copy the URL, for example: http://localhost:53682/auth?state=...
# In the URL replace 'localhost' with the IP address '192.168.1.2' and use it outside the PuTTY session with your browser.
# Logon to your Google account and allow access from Rclone.
# Google will forward to the location that was provided by Rclone you have to replace 'localhost' with the IP address again. Your browser should now reply with 'Succes!'.
# Now go back and continue in the PuTTY session, the configuration will have continued:


<syntaxhighlight lang=bash>
<source lang=bash>
rclone sync -v ~/test4.txt "[remote]:/rclone/"
...
</syntaxhighlight>
Team drives> n
Configuration complete.


From Google Drive to local
is this OK?> y
quit> q
</source>


<syntaxhighlight lang=bash>
We don't need the SSH tunnel anymore, stop it like this:
rclone sync -v  "remote:/rclone/test4.txt" ~/rclone/
<source lang=bash>
</syntaxhighlight>
#PID
ps aux | grep '192.168.1.2:53682' | grep -v 'grep'
#kill
kill -9 $( ps aux | grep '192.168.1.2:53682' | grep -v 'grep' |  awk '{ print $2 }' )
</source>


== Google Drive Service Account ==
You should now  be able to list files on your Google Drive with:
<source lang=bash>
rclone lsl -v gdrive1:/
</source>


* https://developers.google.com/drive/api/v2/reference/permissions/insert
To sync from local to Google Drive, name 'gdrive1', folder 'rclone':
<source lang=bash>
rclone sync -v ~/test4.txt "gdrive1:/rclone/"
</source>


We will need a json file
To sync from Google Drive to local:
<source lang=bash>
rclone sync -v  "gdrive1:/rclone/test4.txt" ~/rclone/
</source>


[[TODO Accesibility of files - can't see the files of the other account in Google Drive]]
= Configure Rclone encryption drive =


Create a service account :
In this configuration we will create an encryption accesspoint 'gdrive2' that accesses files in a folder 'crypt' on a previously configured accesspoint 'gdrive1'. This makes sure only YOU can see the contents of the files, don't loose your encryption password, there is no way to recover it.
* To create a service account and obtain its credentials, go to the Google Developer Console. [https://console.developers.google.com/apis/dashboard
* You must have a project - create one if you don’t.
* Use the “Create Credentials” button. Fill in “Service account name” with something that identifies your client. “Role” can be empty.
* select “Key type JSON”.
* If you ever need to remove access, press the “Delete service account key” button.
* save the json file for use with rclone config


Encryption access via Google Drive access:
<source lang=bash>
rclone config
rclone config
  ...
n                      # new
  service_account_file> ~/Uploader-75551fa3f8b6.json
name> gdrive2
  ...
Storage> crypt          # encrypted
remote> gdrive1:crypt
filename_encryption> standard  # encrypt the filenames
directory_name_encryption> true # encrypt directory names
type password> y   # enter encryption password
salt> n       # without salt pass phrase
advanced config> n
Configuration complete.
 
OK?> y
quit?> q
</source>


== Encrypted ==
You can now decrypt and view files on your Google Drive with:


* https://rclone.org/crypt/
<source lang=bash>
rclone lsl -v gdrive2:
</source>
 
To sync from local to Google Drive, name 'gdrive2':
 
<source lang=bash>
rclone sync -v ~/Documents "gdrive2:/"
</source>
 
Note:
* more info on https://rclone.org/crypt/
* the pass-phrase / salt in this case is more like another password, pick a strong password and you don't need the pass-phrase
 
= Other Rclone commands =
 
Note:
* Commands seem to be instantly applied, however, server-side it may take some time to complete. For example, when you 'cleanup' and then check the used space with 'about' repeatedly, you may see 'Trashed' going down to 0 in steps.
 
Used space / free space / trashed:
 
<source lang=bash>
rclone about gdrive1:
</source>
 
Clean trash / bin.
 
<source lang=bash>
rclone cleanup gdrive1:
</source>
 
Five most recently modified files with size and total number of files:
 
<source lang=bash>
rclone tree --sort-modtime --human gdrive1:/ | tail -5
</source>
 
[https://rclone.org/commands/ Complete list of Rclone commands]
 
= Configure Google Drive Service Account =
 
Note:
* I didn't test this
* 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


Define an encrypted target, the configured remote in the previous paragraph will be used as storage.
Configure rclone:


<syntaxhighlight lang=bash>
<source lang=bash>
rclone config
rclone config
Current remotes:
...
Name                Type
service_account_file> /home/user1/Scripts/rclone.json
====                ====
...
remote              drive
</source>


e/n/d/r/c/s/q> n
= See also =
name> cryptremote
Storage> crypt
remote> remote:/rclone/encrypted
filename_encryption> 2
directory_name_encryption> 1
type password y/g/n> y
seed y/g/n> n
advanced config y/n> n
</syntaxhighlight>


From local to Google Drive, name 'cryptremote'
* [https://rclone.org/commands/ List of Rclone commands]
* [[Enlarge disk partition image]]
<syntaxhighlight lang=bash>
* [https://github.com/kaczmarkiewiczp/rcloneExplorer rcloneExplorer (Android)]
rclone sync -v ~/test4.txt "cryptremote:/"
* [https://martins.ninja/RcloneBrowser/ RcloneBrowser (Windows, Linux)]
</syntaxhighlight>
** Download RcloneBrowser : https://github.com/mmozeiko/RcloneBrowser/releases
** Download Rclone: https://rclone.org/downloads/
* [[Create and Test an SSH Tunnel]]

Latest revision as of 10:05, 15 August 2024


Links

Install

sudo apt install rclone

Or from the source:

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

Configure Google Drive Client Access

Configure the account :

Note:

  • Token renewal seems to be managed by rclone.

Configure rclone

Rclone config file

If you have a configuration file 'rclone.conf', you can restore a configuration by placing it in the correct location ~/.config/rclone/rclone.conf

sudo cp -v rclone.conf ~/.config/rclone/rclone.conf

Rclone config via SSH session

For automatic configuration you will need a regular browser in a desktop session, info on headless configuration:

For example, we are configuring the drive within a PuTTY ssh session from windows. The authentication proces requires a one-time login to your Google account with a regular browser. In order to make this possible we create a SSH tunnel to make the port available outside the PuTTY session. The port that is used by Rclone is '53682'.

What is our IP address?

ifconfig

Let's say it is '192.168.1.2'. Now create ssh tunnel (login) make http://localhost:53682 available via http://192.168.1.2:53682 :

ssh -fN -L 192.168.1.2:53682:localhost:53682 user1@192.168.1.2

You will have to login to the ssh session with 'user1'. This tunnel will remain running as a background proces. We can now configure the Google Drive access.

rclone config
	d                 # delete earlier attempts
	n                 # new
	name> gdrive1
	Storage> drive    # google drive
	client_id>
	client_secret>
	scope> drive            # full access all files
	service_account_file>
	Edit advanced config> n
	Auto config> y          # copy url
	...

The configuration will give you an URL and starts waiting for a response.

  1. Copy the URL, for example: http://localhost:53682/auth?state=...
  2. In the URL replace 'localhost' with the IP address '192.168.1.2' and use it outside the PuTTY session with your browser.
  3. Logon to your Google account and allow access from Rclone.
  4. Google will forward to the location that was provided by Rclone you have to replace 'localhost' with the IP address again. Your browser should now reply with 'Succes!'.
  5. Now go back and continue in the PuTTY session, the configuration will have continued:
	...
	Team drives> n
	Configuration complete.

	is this OK?> y
	quit> q

We don't need the SSH tunnel anymore, stop it like this:

#PID
ps aux | grep '192.168.1.2:53682' | grep -v 'grep'
#kill
kill -9  $( ps aux | grep '192.168.1.2:53682' | grep -v 'grep' |  awk '{ print $2 }' )

You should now be able to list files on your Google Drive with:

rclone lsl -v gdrive1:/

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

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

To sync from Google Drive to local:

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

Configure Rclone encryption drive

In this configuration we will create an encryption accesspoint 'gdrive2' that accesses files in a folder 'crypt' on a previously configured accesspoint 'gdrive1'. This makes sure only YOU can see the contents of the files, don't loose your encryption password, there is no way to recover it.

Encryption access via Google Drive access:

rclone config
	n                       # new
	name> gdrive2
	Storage> crypt          # encrypted
	remote> gdrive1:crypt
	filename_encryption> standard   # encrypt the filenames
	directory_name_encryption> true # encrypt directory names
	type password> y 	  # enter encryption password
	salt> n 		      # without salt pass phrase
	advanced config> n
	Configuration complete.

	OK?> y
	quit?> q

You can now decrypt and view files on your Google Drive with:

rclone lsl -v gdrive2:

To sync from local to Google Drive, name 'gdrive2':

rclone sync -v ~/Documents "gdrive2:/"

Note:

  • more info on https://rclone.org/crypt/
  • the pass-phrase / salt in this case is more like another password, pick a strong password and you don't need the pass-phrase

Other Rclone commands

Note:

  • Commands seem to be instantly applied, however, server-side it may take some time to complete. For example, when you 'cleanup' and then check the used space with 'about' repeatedly, you may see 'Trashed' going down to 0 in steps.

Used space / free space / trashed:

rclone about gdrive1:

Clean trash / bin.

rclone cleanup gdrive1:

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

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

Complete list of Rclone commands

Configure Google Drive Service Account

Note:

  • I didn't test this
  • 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
	...
	service_account_file> /home/user1/Scripts/rclone.json
	...

See also