Auto Backup Mysql Database From Ubuntu Server to Google Drive using Shell Script
Put the link in google and give permission (Note: Only 1 google drive account should be connected with Server, Make sure to give permission to the Mail id for which you want to backup sql file)

Step 7: Click Allow to give access

It will generate a random string

Step 8: Copy the verification Code & put it in Terminal

Now we successfully connected our Google drive account with our cloud server

2. Steps to Create Shell Script:

Step 1: In Terminal type sudo su

Sudo su

Step 2: Go to root directory, in this tutorial I done all things from root directory so I recommend you to do from root directory

cd /

Step 3: Create shell script file in root directory

nano backup.sh

Step 4: Go to the below github link, copy backup.sh code then paste it in your backup.sh file

Save it by pressing Ctrl+X and then type Y then press enter button

Step 5: Give permission to backup.sh file

chmod +x backup.sh

Step 6: Now create a folder in your google drive account (Which we connected to our cloud instance in previous steps)

Copy the URL of that google drive folder

Step 7: Now go to your terminal and test the script

To test the script, we have to pass 5 parameters to the script

5 parameters are,

Backup folder name — Folder we have in our cloud instance to store backup locally. test_db, (Database name which you are going to dump). Database username (Username you use to access your database, Ex: root) Database password. Google drive folder id, Which you noted down in

Step 6:

The final command will be like the following, Type it in terminal then click enter

./backup.sh mysqlbackup test_db root pass123 1OeUBK4T3AXiTl8Kc4bdFyv14uvC1qPv5

After executing the command type “ls” in Terminal you will find mysqlbackup folder which you passed as a parameter.

Now go to mysqlbackup folder by typing “cd mysqlbackup” then type “ls” you will find a dumped Database file.

Now go to Google drive Check your folder you will find a Backedup Database

Step 8: Now we are going to automate our script using crontab

nano /etc/crontab

Add the below line in your crontab file

0 11 * * * root /backup.sh mysqlbackup test_db root pass123 1OeUBK4T3AXiTl8Kc4bdFyv14uvC1qPv5

Save it by pressing Ctrl+X and then type Y then press the enter button

In the above command 0 11 * * * refers to the time when you want to backup sql file to the server….Here 0 11 * * * means everyday backup will be done at 11 AM.

Now you have done everything for auto backup

Check your google drive after 11.00 AM(Time which we provided in crontab. You need to check according to your time which you entered in crontab)

If you want to take backup at 11.00 PM, the command will be

0 23 * * * root /backup.sh mysqlbackup test_db root pass123 1OeUBK4T3AXiTl8Kc4bdFyv14uvC1qPv5

If you encounter any problem please let me know in comments.
['Sathish Kumar']
['MySQL', 'Google Drive', 'Ubuntu']