Assalamualaikum Warrahmatullahi Wabarakatuh

Halo gan, pada kesempatan kali ini saya ingin membahas mengenai Bagaimana cara Backup Data di Server kita ke Google Drive secara otomatis. Disini kita akan membutuhkan beberapa requirement:
– Google Account
– Linux Server
– Rclone

Rclone adalah salah satu project buatan seseorang bernama Nick Craig-Wood (https://twitter.com/njcw). Website resmi Rclone bisa dikunjungi di https://rclone.org. Rclone ini sendiri merupakan sebuah tools yang berguna untuk melakukan Komunikasi antara Server dan Remote Storage. Ada banyak Remote Storage yang di support oleh si Rclone ini diantaranya Google Drive, Dropbox, Onedrive, Yandex Disk, Amazon Cloud Drive, dan masih banyak lagi yang lainnya.

Langsung Saja kita ke tahan instalasi dan konfigurasinya.

1) Install Rclone di Server
# curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
# unzip rclone-current-linux-amd64.zip
# cd rclone-*-linux-amd64
# cp rclone /usr/bin/
# chown root:root /usr/bin/rclone
# chmod 755 /usr/bin/rclone

2) Konfigurasi Rclone nya supaya bisa terhubung dengan Google Drive kita. Isiannya saya tandai dengan warna hijau.
# rclone config

No remotes found - make a new one
n) New remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
n/r/c/s/q> n
name> remote
Type of storage to configure.
Choose a number from below, or type in your own value
[snip]
XX / Google Drive
   \ "drive"
[snip]
Storage> drive
Google Application Client Id - leave blank normally.
client_id>
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"
 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
ID of the root folder - leave blank normally.  Fill in to access "Computers" folders. (see docs).
root_folder_id> (Leave it blank)
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file> (Leave it blank)
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

Pada Tahap ini kita akan di minta untuk membuka link berikut dengan catatan kita sudah login ke account google kita di browser. Jadi bisa langsung copy-paste saja link nya.

If your browser doesn't open automatically go to the following link: http://ip-server-nya:53682/auth
Log in and authorize rclone for access
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":"2014-03-16T13:57:58.955387075Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

3) Sampai sini Server kita sudah mendapatkan full access ke Google Drive. Sekarang tinggal membuat bagaimana caranya server melakukan Backup Data ke Google Drive secara otomatis. Pertama saya akan membuat Folder terlebih dahulu melalui Google Drive. Folder ini tidak boleh di rename kedepannya, karena kalau di rename, kita harus merubah lagi settingan di server nya. Di sini saya membuat folder bernama “Backup-Websites”. Saya sarankan untuk membuat nama folder nya tanpa spasi.

4) Misalnya data yang ingin kita Backup berada di /var/www/html/ dan kita akan lakukan backup data nya setiap hari pada jam 02:00 dini hari.  Maka berikut adalah langkah membuat script nya
# touch /root/backup-data-ke-gdrive.sh
# chmod +x /root/backup-data-ke-gdrive.sh
# nano /root/backup-data-ke-gdrive.sh

#!/bin/bash
## Ini adalah script untuk Backup dan Upload data ke Google Drive ##
## Zip folder /var/www/html/ nya ##
date=$(date +%y-%m-%d)
zip -r /root/data-website-$date.zip /var/www/html/*
## Upload file zip nya ke Google Drive ##
rclone copy /root/data-website-$date.zip remote:Backup-Websites/
## Clean Up Data nya ##
rm -rf /root/data-website-$date.zip 

5) Setelah script diatas siap. Maka langkah terkahir kita akan masukan script tersebut ke Cron supaya bisa di eksekusi otomatis pada jam 02:00 setiap harinya
# nano /etc/crontab
0 2 * * * root /root/backup-data-ke-gdrive.sh

Sampai sini maka data server anda akan otomatis terbackup ke Google Drive setiap harinya. Sekian pembahasan mengenai Backup Data Server Ke Google Drive Menggunakan Rclone dan semoga bermanfaat untuk pembaca. Jangan lupa untuk share ke teman-teman yang membutuhkan supaya bisa bermanfaat untuk banyak orang.

Wassalamualaikum Warrahmatullahi Wabarakatuh

Reference: https://rclone.org/drive/

4 thoughts on “Backup Data Server Ke Google Drive Menggunakan Rclone”

Leave a Reply

Your email address will not be published. Required fields are marked *