Upload Backup/Files to Google Drive from Linux/CWP/HestiaCP/aaPanel

In this tutorial we’ll learn how easily you can upload backups to your google drive account.

Gdrive supports basic syncing. It only syncs one way at the time and works more like rsync than e.g. dropbox. Files that are synced to google drive are tagged with an appProperty so that the files on drive can be traversed faster. This means that you can’t upload files with gdrive upload into a sync directory as the files would be missing the sync tag, and would be ignored by the sync commands. The current implementation is slow and uses a lot of memory if you are syncing many files. Currently only one file is uploaded at the time, the speed can be improved in the future by uploading several files concurrently

First :

Download the Latest version of gdrive binary file from below and make it executable from command line :

cd /usr/local/bin
wget https://github.com/mysterydata/md-disk/raw/main/gdrive
chmod 755 gdrive
ln -s /usr/local/bin/gdrive /usr/bin/gdrive 

Second :

Install dependencies :

Centos 7/EL7 :

cd /usr/local/src
wget https://github.com/mysterydata/md-disk/raw/main/musl-devel-1.2.1-1.el7.x86_64.rpm
wget https://github.com/mysterydata/md-disk/raw/main/musl-libc-1.2.1-1.el7.x86_64.rpm
wget https://github.com/mysterydata/md-disk/raw/main/musl-libc-static-1.2.1-1.el7.x86_64.rpm
wget https://github.com/mysterydata/md-disk/raw/main/musl-filesystem-1.2.1-1.el7.x86_64.rpm
yum localinstall musl-devel-1.2.1-1.el7.x86_64.rpm musl-libc-static-1.2.1-1.el7.x86_64.rpm musl-libc-1.2.1-1.el7.x86_64.rpm musl-filesystem-1.2.1-1.el7.x86_64.rpm
yum groupinstall "Development Tools"

Centos 8 stream/almalinux/rockylinux/oraclelinux/EL8 :

cd /usr/local/src
wget https://github.com/mysterydata/md-disk/raw/main/musl-devel-1.2.1-1.el8.x86_64.rpm
wget https://github.com/mysterydata/md-disk/raw/main/musl-libc-1.2.1-1.el8.x86_64.rpm
wget https://github.com/mysterydata/md-disk/raw/main/musl-libc-static-1.2.1-1.el8.x86_64.rpm
wget https://github.com/mysterydata/md-disk/raw/main/musl-filesystem-1.2.1-1.el8.x86_64.rpm
yum localinstall musl-devel-1.2.1-1.el8.x86_64.rpm_64.rpm musl-libc-static-1.2.1-1.el8.x86_64.rpm musl-libc-1.2.1-1.el8.x86_64.rpm musl-filesystem-1.2.1-1.el8.x86_64.rpm
yum groupinstall "Development Tools"

for other linux for example for Debian and Ubuntu you need to install musl

apt install musl-dev musl musl-tools build-essential 

Third :

Execute gdrive list command to generate a verification code :

gdrive list

it will show like below image :

copy the url and open it in the browser and authorize it, after you’ll see an image like this :

copy the authorization code and paste in the terminal and hit enter

you’ll see the files are now listing.

Now create a Directory name cwp-backup1 in gdrive and it will be used to store backups/files in the folder :

gdrive mkdir cwp-backup1

you will see below message, eg :

[root@server ~]# gdrive mkdir cwp-backup1
Directory 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo created

save the directory ID here it is 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo

That’s it now we can sync the backup directory with gdrive :

Like if you store backups in /backup directory in your server then use below process :

gdrive sync upload /backup/ 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo

** here /backup/ is the directory in your server

** 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo is the directory ID in google drive which you’ve created before this step.


If you have different directory as backup dir in your server, for example /newbackup use below command to sync :

gdrive sync upload /newbackup/ 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo

If you want to upload a single file like a zip file or some other file extension :

gdrive upload --parent 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo filename.zip

**replace filename.zip with actual file name

if you want to delete the file after uploading to gdrive :

gdrive upload --parent 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo filename.zip --delete

**replace filename.zip with actual file name

If you want to upload the multiple files and folders in the directory use this command :

gdrive upload --parent --recursive  1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo /backup/

**please note syncing will take time, you can use Linux screen for background upload.

For More Usage Command information : GO HERE

Troubleshoot :

to update the new token you need to delete the current token config located in :

/home/user/.gdrive/token_v2.json

if you run gdrive as “root” user then the token config file location will be at example :

/root/.gdrive/token_v2.json
rm /root/.gdrive/token_v2.json

after deleting the file go back to Third step

Leave a Reply