Linux Tutorials

Shell Script backup multiple source code folders on Linux Server to Google Drive automatically

Pinterest LinkedIn Tumblr

To synchronize your backup data to Google Drive you’ll need install Rclone first. After that you need config authorize your Google Drive with Rclone. You can view setup guide backup vps data with Rclone and Google Drive before practice this tutorial.

Shell script backup multiple source code foder and synchronize data to Google Drive

#!/bin/bash

dest="/home/backup_source"

#The line below will store multiple folders in an array (files)
files=("/var/html/folder1" "/var/html/folder2" "var/html/folder3")

current_date="$( date +%F_%H-%M-%S )"

SERVER_NAME="remote_name:your_backup_folder_on_cloud"
REMOTE_NAME="remote_name:"

rclone -q --min-age 1w delete $SERVER_NAME #Remove all backups older than 1 week
rclone cleanup $REMOTE_NAME #Cleanup Trash

At first, you input list of backup folders in files variable then replace remote_name by your remote name you have configured with Rclone at previous setup guide. Next add this script to crontab.

chmod +x your_script.sh
crontab -e
#input this line to run script on 0:0 every day
0 0 * * * your_path_to_script

I'm a full stack developer. I have experiences with Java, Android, PHP, Python, C#, Web development...I hope website https://learncode24h.com will help everyone can learn code within 24h and apply it in working easily.

Comments are closed.