Clone Files to Cloud Storage: Difference between revisions
mNo edit summary |
|||
| Line 31: | Line 31: | ||
* Create a project and select it | * Create a project and select it | ||
* Select "ENABLE API'S AND SERVICES" and enable the "Google Drive API" | * Select "ENABLE API'S AND SERVICES" and enable the "Google Drive API" | ||
Note: | Note: | ||
* Token renewal seems to be managed by rclone. | * Token renewal seems to be managed by rclone. | ||
= Configure rclone = | |||
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'. | |||
What is our IP address? | |||
= | <source lang=bash> | ||
ifconfig | |||
</source> | |||
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 : | |||
<source lang=bash> | |||
ssh -fN -L 192.168.1.2:53682:localhost:53682 user1@192.168.1.2 | |||
</source> | |||
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. | |||
< | <source lang=bash> | ||
rclone config | rclone config | ||
n | d # delete earlier attempts | ||
name> gdrive1 | n # new | ||
Storage | name> gdrive1 | ||
client_id> | Storage> drive # google drive | ||
client_secret> | client_id> | ||
scope> drive | client_secret> | ||
scope> drive # full access all files | |||
service_account_file> | |||
Edit advanced config> n | |||
Auto config> y # (1) copy url to a browser | |||
... | |||
</source> | |||
The configuration will give you an URL and starts waiting for a response. | |||
# 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: | |||
<source lang=bash> | |||
... | |||
Team drives> n | |||
Configuration complete. | |||
is this OK?> y | is this OK?> y | ||
</ | quit> q | ||
</source> | |||
We don't need the SSH tunnel anymore, stop it like this: | |||
<source lang=bash> | |||
#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> | |||
< | You should now be able to list files on your Google Drive with: | ||
rclone | <source lang=bash> | ||
</ | rclone lsl -v gdrive1:/ | ||
</source> | |||
To sync from local to Google Drive, name 'gdrive1', folder 'rclone': | |||
<source lang=bash> | |||
rclone sync -v ~/test4.txt "gdrive1:/rclone/" | |||
</source> | |||
< | To sync from Google Drive to local: | ||
rclone sync -v | <source lang=bash> | ||
</ | rclone sync -v "gdrive1:/rclone/test4.txt" ~/rclone/ | ||
</source> | |||
= 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: | ||
<source lang=bash> | |||
rclone config | rclone config | ||
n # new | |||
name> gdrive2 | name> gdrive2 | ||
Storage> crypt | Storage> crypt # encrypted | ||
remote> gdrive1: | remote> gdrive1:crypt | ||
filename_encryption> | filename_encryption> standard # encrypt the filenames | ||
directory_name_encryption> | directory_name_encryption> true # encrypt directory names | ||
type password | type password> y # enter encryption password | ||
salt | salt> n # without salt pass phrase | ||
advanced config | advanced config> n | ||
Configuration complete. | |||
OK?> y | |||
quit?> q | |||
</source> | |||
You can now decrypt and view files on your Google Drive with: | |||
<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: | |||
rclone | * 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 commands = | = Other Rclone commands = | ||
Note: | Note: | ||
| Line 168: | Line 166: | ||
Used space / free space / trashed: | Used space / free space / trashed: | ||
< | <source lang=bash> | ||
rclone about gdrive1: | rclone about gdrive1: | ||
</ | </source> | ||
Clean trash / bin. | Clean trash / bin. | ||
< | <source lang=bash> | ||
rclone cleanup gdrive1: | rclone cleanup gdrive1: | ||
</ | </source> | ||
Five most recently modified files with size and total number of files: | Five most recently modified files with size and total number of files: | ||
< | <source lang=bash> | ||
rclone tree --sort-modtime --human gdrive1:/ | tail -5 | rclone tree --sort-modtime --human gdrive1:/ | tail -5 | ||
</ | </source> | ||
[https://rclone.org/commands/ Complete list of Rclone commands] | |||
= Configure Google Drive Service Account = | |||
* https://rclone. | 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: | |||
<source lang=bash> | |||
rclone config | |||
... | |||
service_account_file> /home/user1/Scripts/rclone.json | |||
... | |||
</source> | |||
= See also = | = See also = | ||
* [https://rclone.org/commands/ List of Rclone commands] | |||
* [[Enlarge disk partition image]] | * [[Enlarge disk partition image]] | ||
* [https://github.com/kaczmarkiewiczp/rcloneExplorer rcloneExplorer (Android)] | * [https://github.com/kaczmarkiewiczp/rcloneExplorer rcloneExplorer (Android)] | ||
| Line 195: | Line 217: | ||
** Download RcloneBrowser : https://github.com/mmozeiko/RcloneBrowser/releases | ** Download RcloneBrowser : https://github.com/mmozeiko/RcloneBrowser/releases | ||
** Download Rclone: https://rclone.org/downloads/ | ** Download Rclone: https://rclone.org/downloads/ | ||
* [[Create and Test an SSH Tunnel]] | |||
Revision as of 10:05, 15 August 2024
Links
- http://wiki.linuxquestions.org/wiki/Rsync_with_Google_Drive
- https://rclone.org/drive/
- https://developers.google.com/identity/protocols/OAuth2ServiceAccount
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 :
- 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
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 # (1) copy url to a browser ...
The configuration will give you an URL and starts waiting for a response.
- 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:
... 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 ...