Cara Akses Google Drive di Linux Server menggunakan rclone

rclone merupakan aplikasi berbasis command line yang berfungsi untuk melakukan sinkronisasi file dan direktori dari/ke berbagai layanan cloud storage atau protokol file server/storage.

Layanan cloud storage yang didukung oleh rclone yaitu Amazon Drive, Amazon S3, Box, Ceph, DigitalOcean Spaces, Dropbox, Google Cloud Storage, Google Drive, Nextcloud, ownCloud, FTP, SFTP, dan masih banyak lagi.

Install rclone

Download dan extract rclone yang sudah berberntuk file binari (sudah di compile).

Download menggunakan curl

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

Extract menggunakan unzip

unzip rclone-current-linux-amd64.zip

Masuk kedalam direktori rclone

cd rclone-*-linux-amd64

Copy file rclone ke direktori /usr/bin/ agar langsung bisa di eksekusi tanpa harus berpindah direktori

sudo cp rclone /usr/bin/

Ubah kepemilikan

sudo chown root:root /usr/bin/rclone

Ubah perizinan

sudo chmod 755 /usr/bin/rclone  

Install manual/(buku panduan) rclone

sudo mkdir -p /usr/local/share/man/man1

Copy file rclone.1 ke direktori /usr/local/share/man/man1

sudo cp rclone.1 /usr/local/share/man/man1/

Update/install mandb

sudo mandb  

Uji hasil install rclone dengan menampilkan nomor versi.

rclone version

Petunjuk pemakaian/manual

man rclone

atau bisa juga membaca dokumentasi resmi di website rclone.

Konfigurasi

Selanjutnya melakukan konfigurasi rclone, menambahkan cloud storage yang ingin dihubungkan ke Linux server.

Jalankan perintah rclone config

rclone config

Jika muncul pertanyaan

2021/05/20 04:29:26 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

Jawab n untuk membuat koneksi baru

Jika muncul pertanyaan

name> drive-saya

Berikan nama koneksinya, contoh: drive-saya

Jika muncul pertanyaan

Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Compress a remote
   \ "compress"
10 / Dropbox
   \ "dropbox"
11 / Encrypt/Decrypt a remote
   \ "crypt"
12 / Enterprise File Fabric
   \ "filefabric"
13 / FTP Connection
   \ "ftp"
14 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
15 / Google Drive
   \ "drive"
16 / Google Photos
   \ "google photos"
17 / Hadoop distributed file system
   \ "hdfs"
18 / Hubic
   \ "hubic"
19 / In memory object storage system.
   \ "memory"
20 / Jottacloud
   \ "jottacloud"
21 / Koofr
   \ "koofr"
22 / Local Disk
   \ "local"
23 / Mail.ru Cloud
   \ "mailru"
24 / Mega
   \ "mega"
25 / Microsoft Azure Blob Storage
   \ "azureblob"
26 / Microsoft OneDrive
   \ "onedrive"
27 / OpenDrive
   \ "opendrive"
28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
29 / Pcloud
   \ "pcloud"
30 / Put.io
   \ "putio"
31 / QingCloud Object Storage
   \ "qingstor"
32 / SSH/SFTP Connection
   \ "sftp"
33 / Sugarsync
   \ "sugarsync"
34 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
35 / Transparently chunk/split large files
   \ "chunker"
36 / Union merges the contents of several upstream fs
   \ "union"
37 / Webdav
   \ "webdav"
38 / Yandex Disk
   \ "yandex"
39 / Zoho
   \ "zoho"
40 / http Connection
   \ "http"
41 / premiumize.me
   \ "premiumizeme"
42 / seafile
   \ "seafile"
Storage> 15

Jawab 15 untuk google drive, contoh disini google drive dengan angka 15

Jika muncul pertanyaan

** See help for drive backend at: https://rclone.org/drive/ **

Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id>

Tidak perlu di isi, tekan enter

Jika muncul pertanyaan

OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>

Tidak perlu di isi, tekan enter

Jika muncul pertanyaan

Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 1

Masukkan angka 1 agar bisa mengakses Google Drive secara penuh (read, write, execute)

Jika muncul pertanyaan

ID of the root folder
Leave blank normally.

Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.

Enter a string value. Press Enter for the default ("").
root_folder_id>

Direktori atau sub-direktori di Google Drive yang ingin dijadikan root folder. Tidak perlu diisi jika ingin menjadikan root folder di Google Drive sebagai root folder, tekan enter.

Jika muncul pertanyaan

Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.

Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.

Enter a string value. Press Enter for the default ("").
service_account_file>

Tidak perlu diisi, tekan enter.

Jika muncul peertanyaan

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

Edit advanced config, jawab n

Jika muncul pertanyaan

Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> n

Use auto config? Jawab n

Lalu akan diberikan sebuah link

Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=dfd25.22..apps.dfvvdnt.com&ddfbdkfndknfdlaiode&scope=https%3A%2F%2Fwww.googleapis.com%2Fautfdfdg&stagdfdyEhT-OUPq56fY02QNoOaRA
Log in and authorize rclone for access

Copy dan kunjungi link tersebut, Pastikan login terlebih dahulu kedalam akun google yang akan diakses google drive nya.

izinkan akses

Lalu akan muncul kode verifikasi, salin kode verifikasi tersebut

Jika muncul pertanyaan

Enter verification code> 4/iAdf0e-g7oYyfdgdfmvcfcgbvBHGEfJoV223vF13enhQeDcx2B4qh2uAQ

Tempel/isikan kode verifikasi yang sebelumnya kita dapatkan

JIka muncul pertanyaan

Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> n

Konfigurasikan sebagai team drive? jawab n

Setelah itu akan ditampilkan overview dari konfigurasi

--------------------
[drive-saya]
type = drive
scope = drive
token = {"access_token":"ya29.GltIBxdJ9BWv9wsbbdckTxXZIRZ7I0WuxJTEqpBhvMx1d-gyvN6aSOxQS2xqs3jU21ws_eayXF_DkRvqHXgF-yZOo6k6YgUl_1O8KHOp9_kIDU5Az0tHFUvDTqgG","token_type":"Bearer","refresh_token":"1/ZkUB4McwvVSG9lOv8iWmt7I3yp9EK6TcwWvO8-HHbtg","expiry":"2019-07-17T14:42:40.738880079Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

Jika sudah yakin benar jawab y

Setelah itu akan ditampilkan koneksi cloud storage yang sudah dibuat

Name                 Type
====                 ====
drive-saya           drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

Jawab q untuk keluar dari konfigurasi rclone

Perintah dasar rclone

Selanjutnya mengakses Google Drive melalui rclone dengan menggunakan perintah-perintah yang tersedia.

Menampilkan file

rclone ls drive-saya:

Menampilkan direktori

rclone lsd drive-saya:

Menampilkan file dan direktori

rclone lsf drive-saya:

Membuat direktori

rclone mkdir drive-saya:Nama-direktori

Copy file

rclone copy hello.txt drive-saya:Nama-direktori

Menghapus file, tidak menghapus direktori

rclone delete drive-saya:Nama-direktori

Menghapus direktori yang kosong

rclone rmdir drive-saya:Nama-direktori

Menghapus file dan direktori

rclone purge drive-saya:Nama-direktori

Mount Google Drive di Linux

rclone dapat melakukan mount Google Drive di Linux.

Membuat direktori di home Linux

mkdir ~/google-drive

Jalankan perintah mount dan buat berjalan di latar belakang

rclone mount drive-saya: ~/google-drive &

Maka akan ditampilkan ID proses nya, contoh ID

[1] 2952   

Salin atau simpan kode tersebut. Bilamana kita akan menghentikan/unmount lakukan perintah kill dengan di ikuti nomer ID proses.

Cek isi dari direktori mount ~/google-drive, apakah isinya sama dengan yang ada di Google Drive.

ls -l ~/google-drive

Menghentikan proses rclone mount degan perintah kill ID-proses, contoh ID proses nya adalah 2952

kill 2952

Keterangan artikel

Tested on : Ubuntu 20.04
Sumber & refrensi :
https://musaamin.web.id/cara-akses-google-drive-di-linux-server/