Automatically Backup Data to Google Drive

1. Install Gdrive

First step we need to install a third-party CLI tool which lets you simply transfer files to your Google Drive with scripts.
[root@www ~]# cd /usr/bin/
[root@www bin]# wget -O drive
[root@www bin]# chmod 755 drive
[root@www bin]# drive
In this step, after you type "drive" it will ask for verification code like this :

root@www bin]# drive
Go to the following link in your browser:

Enter verification code:

So, please access the link from your browser and will show the code :

Copy the code and paste into your VPS Console : (Enter verification code: )

2. Create Folder backups

Next step, we need to create a folder /backups to store the files backup
[root@www bin]# mkdir backups
[root@www bin]# cd /backups/
And create file
[root@www backups]# nano
And then paste this scripts :
##-----------------------Database Access--------------------------##

##-----------------------Folder Web or Folder you want to backup--------------------------##
date=$(date +"%Y-%m-%d")
##That mean, you will Backup the folder /home/albennet and will save into Folder /backups

if [ ! -d $BackupLocation ]; then
mkdir -p $BackupLocation
find $BackupLocation/*.zip -mtime +10 -exec rm {} \;
for fd in $NameOfFolder; do
# Name of the Backup File

# Zip the Folder you will want to Backup
echo "Starting to zip the folder and files"
cd $SourceOfFolder
zip -r $BackupLocation/$file $fd
sleep 5s
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $BackupLocation/$date-$DB_NAME.sql.tar
sleep 5s
##Process Upload Files to Google Drive
drive upload --file /backups/$file
sleep 5s
drive upload --file /backups/$date-$DB_NAME.sql.tar
if test $? = 0
echo "Your Data Successfully Uploaded to the Google Drive!"
echo -e "Your Data Successfully created and uploaded to the Google Drive!" | mail -s "Your VPS Backup from $date"
echo "Error in Your Data Upload to Google Drive" > $LOG_FILE
And then save the file

3. Change Permision

The next step is change the permision files
[root@www backups]# chmod +x

4. Crate Cheduler

The next step is create cronjob to run the script automatically
[root@www backups]# nano /etc/crontab
And insert this line:
0 2 * * * /backups/
Then save and restart crond.
[root@www ~]# /etc/init.d/crond restart
That mean, every 2:00 AM the script runs automatically to perform backup and store it in google drive.
And this is the result of data stored in Google Drive :

Backup is very important, Do Before It's Too Late