How to Backup Directories to Google Drive Automatically on CentOS/Red Hat

This article explains how to backup directories to google drive.

1. Install google drive.

            Use the following link ti download google drive


2. Move this file to "/usr/sbin/" folder.

               [root@centos ~]# mv drive /usr/sbin/drive

3. Assign right permission to the file.

              [root@centos ~]# chmod 755 /usr/sbin/drive


4. Now run command "dive". It will ask authentication.

      You will get a link like this.


  Go  to the above link on browser, you will get verification code. Type verification code and hit Enter.

5. Create backup script.



# tar the bkp directory
tar -zcf "dir-backup-$(date '+%Y-%m-%d').tar.gz" /root/AAA/aby/

# encrypt the tar
#openssl aes-256-cbc -a -salt -in "dir-backup-$(date '+%Y-%m-%d').tar.gz" -out "dir-backup-$(date '+%Y-%m-%d').tar.gz.enc" -pass 'pass:123456'

# remove the original tar
#rm -rf "dir-backup-$(date '+%Y-%m-%d').tar.gz"

# upload to google drive
/usr/sbin/drive upload --file "dir-backup-$(date '+%Y-%m-%d').tar.gz" -p 0B2iJNfzwHersN3Yxa0N3U1lqeU0

rm -rf "dir-backup-$(date '+%Y-%m-%d').tar.gz"


"0B2iJNfzwHersN3Yxa0N3U1lqeU0"   This is your google drive directory name which can be copied from url.

6. Execute the script.

You can Schedule this script on crontab and schedule this autobackup.

How to scheduling Crontab for backup files and directories in linux

No comments:

Powered by Blogger.