{"id":3526,"date":"2018-12-04T00:22:13","date_gmt":"2018-12-04T06:22:13","guid":{"rendered":"https:\/\/www.supportpro.com\/blog\/?p=3526"},"modified":"2026-03-22T23:14:25","modified_gmt":"2026-03-23T05:14:25","slug":"backup-to-google-drive-from-centos-redhat","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/backup-to-google-drive-from-centos-redhat\/","title":{"rendered":"Backup Directories to Google Drive from CentOS\/RedHat"},"content":{"rendered":"\n<p><span style=\"font-weight: 400;\">Nowadays Google Drive is the most commonly used service to store our files as a cloud. Here in this article, it explains how to backup directories to Google Drive using bash script and API.<\/span><\/p>\n\n\n\n<p><em><strong>1. Install Google Drive on the server<\/strong><\/em><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Use the following link to download Google Drive:<\/span><\/p>\n\n\n\n<p><a href=\"https:\/\/drive.google.com\/open?id=1P2J2HObqDtIjB07yvotE4mzml4tjC4ot\">https:\/\/drive.google.com\/open?id=1P2J2HObqDtIjB07yvotE4mzml4tjC4ot<\/a><\/p>\n\n\n\n<p><em><strong>2. Then move this file to &#8220;\/usr\/sbin\/&#8221; folder.<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">&#91;root@redhat ~]# mv drive \/usr\/sbin\/drive<\/span><\/code><\/pre>\n\n\n\n<p><em><strong>3. Assign the correct permission to the file.<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">&#91;root@redhat ~]# chmod 755 \/usr\/sbin\/drive<\/span><\/code><\/pre>\n\n\n\n<p><em><strong>4. Now run the file &#8220;drive&#8221;.<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">&#91;root@redhat ~]# cd \/usr\/sbin\/<\/span>\n\n<span style=\"font-weight: 400;\">&#91;root@redhat ~]# .\/drive<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">You will get a link like this asking for a verification code.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Go to the following link in your browser:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">https:\/\/accounts.google.com\/o\/oauth2\/auth?client_id=367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com&amp;redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&amp;response_type=code&amp;scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&amp;state=state<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">Enter verification code.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Go to the above link&nbsp;on the browser (URL should vary while running the script each time).<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Sign in using a Google account and click on \u2018Allow\u2019, you will get the verification code as shown below.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a class=\"lightbox\" href=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_url.png\" data-rel=\"penci-gallery-image-content\" ><img fetchpriority=\"high\" decoding=\"async\" width=\"585\" height=\"134\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_url.png\" alt=\"\" class=\"wp-image-3530\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_url.png 585w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_url-300x69.png 300w\" sizes=\"(max-width: 585px) 100vw, 585px\" \/><\/a><\/figure>\n\n\n\n<p><span style=\"font-weight: 400;\">Type verification code and hit Enter.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a class=\"lightbox\" href=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_verification.png\" data-rel=\"penci-gallery-image-content\" ><img decoding=\"async\" width=\"1352\" height=\"79\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_verification.png\" alt=\"\" class=\"wp-image-3532\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_verification.png 1352w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_verification-300x18.png 300w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_verification-768x45.png 768w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_verification-1024x60.png 1024w\" sizes=\"(max-width: 1352px) 100vw, 1352px\" \/><\/a><\/figure>\n\n\n\n<p><em><strong>5. Create a backup script<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">&#91;root@redhat sbin]# vim bkupload.sh<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">The backup script is as follows:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">#!\/bin\/sh<\/span>\n\n<span style=\"font-weight: 400;\"># To take backup as tar for a directory<\/span>\n\n<span style=\"font-weight: 400;\">tar -zcf \"dir-backup-$(date '+%Y-%m-%d-%H-%M-%S').tar.gz\" \/root\/test<\/span>\n\n<span style=\"font-weight: 400;\"># To encrypt the backup tar file (if needed)<\/span>\n\n<span style=\"font-weight: 400;\">#openssl aes-256-cbc -a -salt -in \"dir-backup-$(date '+%Y-%m-%d-%H-%M-%S').tar.gz\" -out \"dir-backup-$(date '+%Y-%m-%d-%H-%M-%S').tar.gz.enc\" -pass 'pass:123456'<\/span>\n\n<span style=\"font-weight: 400;\"># To remove the original tar file (if needed)<\/span>\n\n<span style=\"font-weight: 400;\">#rm -rf \"dir-backup-$(date '+%Y-%m-%d-%H-%M-%S').tar.gz\"<\/span>\n\n<span style=\"font-weight: 400;\"># To upload to Google Drive<\/span>\n\n<span style=\"font-weight: 400;\">drive upload --file \"dir-backup-$(date '+%Y-%m-%d-%H-%M-%S').tar.gz\" -p 1XiaelkGjGkvC-FpM6HrKHFt7l7_zsADG<\/span><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a class=\"lightbox\" href=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_code.png\" data-rel=\"penci-gallery-image-content\" ><img decoding=\"async\" width=\"1291\" height=\"229\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_code.png\" alt=\"\" class=\"wp-image-3533\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_code.png 1291w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_code-300x53.png 300w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_code-768x136.png 768w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_code-1024x182.png 1024w\" sizes=\"(max-width: 1291px) 100vw, 1291px\" \/><\/a><\/figure>\n\n\n\n<p><span style=\"font-weight: 400;\">Here, \u201c<em>1XiaelkGjGkvC-FpM6HrKHFt7l7_zsADG<\/em>\u201d is the folder ID that we get from Google Drive URL.<\/span><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a class=\"lightbox\" href=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_web.png\" data-rel=\"penci-gallery-image-content\" ><img loading=\"lazy\" decoding=\"async\" width=\"950\" height=\"214\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_web.png\" alt=\"\" class=\"wp-image-3534\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_web.png 950w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_web-300x68.png 300w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_web-768x173.png 768w\" sizes=\"(max-width: 950px) 100vw, 950px\" \/><\/a><\/figure>\n\n\n\n<p class=\"has-text-align-left\"><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><em><strong>6. Set the correct permission to the script file.<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">[root@redhat sbin]# chmod 755 bkupload.sh<\/span><\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><em><strong>7. Now execute the script.<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400;\">[root@redhat sbin]# .\/bkupload.sh<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a class=\"lightbox\" href=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/script_run.png\" data-rel=\"penci-gallery-image-content\" ><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"199\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/script_run.png\" alt=\"\" class=\"wp-image-3536\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/script_run.png 618w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/script_run-300x97.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/figure>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Once the backup script is executed, you can see that the backup is correctly uploaded to Google Drive as follows:<\/span><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a class=\"lightbox\" href=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_backup.png\" data-rel=\"penci-gallery-image-content\" ><img loading=\"lazy\" decoding=\"async\" width=\"1344\" height=\"454\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_backup.png\" alt=\"\" class=\"wp-image-3559\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_backup.png 1344w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_backup-300x101.png 300w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_backup-768x259.png 768w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2018\/12\/drive_backup-1024x346.png 1024w\" sizes=\"(max-width: 1344px) 100vw, 1344px\" \/><\/a><\/figure>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">We can schedule this script on crontab for auto backup.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">FAQ<\/h3>\n\n\n\n<p>1. How can I back up files to Google Drive from CentOS?<br>You can use a bash script along with a Google Drive CLI tool and API authentication to upload backup files automatically.<\/p>\n\n\n\n<p>2. Can I automate Google Drive backups in Linux?<br>Yes, you can schedule the backup script using cron jobs to run at specific intervals.<\/p>\n\n\n\n<p>3. Is it possible to encrypt backup files before uploading?<br>Yes, you can use tools like OpenSSL to encrypt backup files before uploading them to Google Drive.<\/p>\n\n\n\n<p>4. What is the use of the folder ID in Google Drive backup?<br>The folder ID specifies the destination folder in Google Drive where the backup files will be uploaded.<\/p>\n\n\n\n<p>5. Does this method work for RedHat as well?<br>Yes, the same process works for both CentOS and RedHat systems.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.supportpro.com\/requestquote.php\" title=\"\">Automate your backups and keep your data safe in the cloud &#8211; get started today!<\/a><\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile is-vertically-aligned-center has-white-background-color has-background\"><div class=\"wp-block-media-text__content\">\n<p class=\"has-large-font-size\">Partner with <strong>SupportPRO<\/strong> for 24\/7 proactive cloud support that keeps your business secure, scalable, and ahead of the curve.<\/p>\n\n\n\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper\" id=\"hs-cta-wrapper-3350a795-db50-482f-9911-301930d1b1be\"><span class=\"hs-cta-node hs-cta-3350a795-db50-482f-9911-301930d1b1be\" id=\"hs-cta-3350a795-db50-482f-9911-301930d1b1be\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/3350a795-db50-482f-9911-301930d1b1be\" ><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-3350a795-db50-482f-9911-301930d1b1be\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/3350a795-db50-482f-9911-301930d1b1be.png\"  alt=\"Contact Us today!\"\/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '3350a795-db50-482f-9911-301930d1b1be', {\"useNewLoader\":\"true\",\"region\":\"na1\"}); <\/script><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"931\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup.png\" alt=\"guy server checkup\" class=\"wp-image-12943 size-full\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup.png 904w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-291x300.png 291w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-768x791.png 768w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-585x602.png 585w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Nowadays Google Drive is the most commonly used service to store our files as a cloud. Here in this article, it explains how to backup directories to Google Drive using&hellip;<\/p>\n","protected":false},"author":4,"featured_media":3527,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[5,1,3],"tags":[],"class_list":["post-3526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general-topics","category-miscellaneous","category-technical-articles"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/3526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=3526"}],"version-history":[{"count":56,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/3526\/revisions"}],"predecessor-version":[{"id":16445,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/3526\/revisions\/16445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media\/3527"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=3526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=3526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=3526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}