# How to use cloud storage with Rclone

Rclone is a command line program written in Go language, used to sync files and directories from different cloud storage providers such as: Amazon Drive, Amazon S3, Box, Dropbox, Google Drive, OneDriver, etc.

As you see, it supports multiple platforms, which makes it a useful tool to sync your data between servers or to a private storage.

### How to Install rclone in Linux Systems

The installation of rclone can be completed in two different ways. The easier one is using their installation script, by issuing the following command.

curl https://rclone.org/install.sh | sudo bash


What this script does is to check the OS type on which it is ran and download the archive related to that OS. Then it extracts the archive and copies rclone binary to /usr/bin/rclone and gives 755 permissions on the file.

In the end, when the installation is complete, you should see the following line:

Rclone v1.48 has successfully installed.
Now run “rclone config” for setup, Check https://rclone.org/docs/ for  more details.


The second way to install rclone is by issuing the following commands.

curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64


Now copy the binary file and give it executable permissions.

cp rclone /usr/bin/
chown root:root /usr/bin/rclone
chmod 755 /usr/bin/rclone


Install rclone manpage.

mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb


## How to Configure rclone in Linux Systems

Next what you will need to do is run the rclone config to create your config file. It will be used for authentication for future usage of rclone. To run the configuration setup run the following command.

# rclone config


You will see the following prompt:

2019/08/09 15:33:52 NOTICE: Config file “/home/carlos/.config/rclone/rclone.conf” not found - using defaults
No remotes found - make a new one
n) New remote
q) Quit config
n/s/q>


The options are as follows:

• n) – Create new remote connection
• q) – exit the config

For the purpose of this tutorial lets press "n" and create new connection. You will be asked to give the new connection a name. After that you will be prompted to select the type of storage to be configured:

I have named by connection “Google” and selected “Google Drive”, which is under the number 12. The rest of the questions you can answer by simply leaving the default answer, which is an empty “”.

When asked to, you may select “autoconfig”, which will generate all the required info to connect to your Google Drive and give rclone permissions to use data from Google Drive.

The process looks something like this:

Google Application Client Secret - leave blank normally.
client_secret>
Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
\ "drive"
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ "drive.file"
4 | This is not visible in the drive website.
\ "drive.appfolder"
scope> 1
ID of the root folder - leave blank normally.  Fill in to access "Computers" folders. (see docs).
root_folder_id>
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file>
Remote config
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> y
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Waiting for code...
Got code
Configure this as a team drive?
y) Yes
n) No
y/n> n
--------------------
[remote]
client_id =
client_secret =
scope = drive
root_folder_id =
service_account_file =
token = {"access_token":"XXX","token_type":"Bearer","refresh_token":"XXX","expiry":"2019-08-09T15:33:12.153347576Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y


### How to Use rclone in Linux Systems

Rclone has quite a long list of available options and commands to be used with. We will try to cover some of the more important ones:

#### List Remote Directory

# rclone lsd <remote-dir-name>:


#### Copy Data with rclone

# rclone copy source:sourcepath dest:destpath


#### Sync data with rclone

If you want to sync some data between directories, you should use rclone with sync command.

The command should look like this:

# rclone sync source:path dest:path [flags]


In this case the source is synced to destination, changing the destination only! This method skips unchanged files. Since the command can cause data loss, you can use it with “–dry-run” to see what exactly will be copied and deleted.

#### Move Data with rclone

To move data, you can use rclone with move command. The command should look like this:

rclone move source:path dest:path [flags]


#### Other rclone Commands

To create a directory on destination.

rclone mkdir remote:path


To remove a directory.

rclone rmdir remote:path


Check if files on source and destination match:

rclone check source:path dest:path


Delete files:

rclone delete remote:pathHow to Use rclone in Linux Systems


Each of rclone commands can be used with different flags and includes its own help menu. For example, you can do a selective delete using the delete option. Lets say you want to delete files larger than 10M, the command would look like this.

rclone --min-size 10M delete remote:path


It is highly recommend to review the manual and help for each command to get the most of rclone. The full documentation of rclone is available at: https://rclone.org/

##### Carlos Dagorret
###### CTO Facultad de Ciencias Económicas

My research interests include distributed robotics, mobile computing and programmable matter.