How to sync Google Drive storage on Ubuntu with Rclone
There is no official Google Drive sync for Linux at the moment and we needed samba drive to backup files to Google Drive. To accomplish the goal, we decided to use Rsync.
Following installation instructions (https://rclone.org/install/), we execute the following commands.
Download:
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
Since its a new ubuntu installation, we need to install unzip package:
sudo apt install unzip
Unzip and navigate to new directory:
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64
Copy the binary file and change permissions:
sudo cp rclone /usr/bin/
sudo chown root:root /usr/bin/rclone
sudo chmod 755 /usr/bin/rclone
Install manpage
sudo mkdir -p /usr/local/share/man/man1
sudo cp rclone.1 /usr/local/share/man/man1/
sudo mandb
Configure rclone:
rclone config
Enter “n” for new remote since its a new remote and name it “remote” (following the guide at https://rclone.org/drive/).
“Google Drive” is under point 10, so we enter “10” and press Enter. It then asks for “client_id”, “client_secret” and “service_account_file”, which we leave empty and press Enter.
Then we enter “n” for auto config. It gives us a link to open which we open and get the auth code. Paste it in and continue. Press “n” for team drive, “y” to confirm configuration and press “q” to exit config.
Create a bash script:
cd ~
sudo mkdir cron
cd cron
sudo vi google_drive_push.sh
Add this script (change folder name as needed and make sure it exists in Google Drive):
#!/bin/bash
if pidof -o %PPID -x "google_drive_push.sh"; then
exit 1
fi
rclone sync /home/MyShareFolder/ remote:MyShareFolder/ -v -u --checkers 1 --transfers 1 --log-file=/home/user/cron/rclone-upload.log
exit
Make it executable
sudo chmod a+x google_drive_push.sh
run
sudo sh google_drive_push.sh