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 gdrive3 binary file from below and make it executable from command line :
cd /usr/local/bin rm -rf /usr/local/bin/gdrive /usr/bin/gdrive 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 add command to add google drive :
gdrive add account
Use this instructions to connect gdrive : https://github.com/glotlabs/gdrive/blob/main/docs/create_google_api_credentials.md
Now create a Directory name cwp-backup1 in gdrive and it will be used to store backups/files in the folder :
gdrive files mkdir cwp-backup1
you will see below message, eg :
[root@server ~]# gdrive files mkdir cwp-backup1 Directory 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo created
save the directory ID here it is 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo
you can also print the id :
gdrive files mkdir cwp-backup1 --print-only-id # or you can list files : gdrive files list
That’s it now we can sync the backup directory with gdrive :
(SYNC is Not working in gdrive3 probably author will add this support later)
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 files 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 :
Delete is not working in gdrive3
gdrive files 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 files upload --recursive --parent 1ncJzhW6xK-pdTVhrZupwERZ-o2fg3UHo /backup/
you can print id via this command :
gdrive files upload cwp-backup1 --print-only-id
Troubleshoot :
to update the new token you need to delete the current token config located in :
/home/user/.config/gdrive3/
if you run gdrive as “root” user then the token config file location will be at example :
/root/.config/gdrive3/rm /root/.config/gdrive3/
after deleting the file go back to Third step