cdw1p icon

[BASH] Google Drive Auto Backup

cdw1p | PRO | 04/24/18 03:52:14 AM UTC | 0 ⭐ | 594 👁️ | Never ⏰ | []
Bash |

1.37 KB

|

None

|

0 👍

/

0 👎

#!/bin/sh
##-----------------------Database Access--------------------------##
DB_NAME="dbname"
DB_USER="dbuser"
DB_PASSWORD="dbpass"
 
##-----------------------Folder Web or Folder you want to backup--------------------------##
NameOfFolder=("seatide")
SourceOfFolder="/home/source"
BackupLocation="/backups"
date=$(date +"%Y-%m-%d")
Sitename="SEATIDE"
##That mean, you will Backup the folder /home/albennet and will save into Folder /backups
if [ ! -d $BackupLocation ]; then
mkdir -p $BackupLocation
fi
find $BackupLocation/*.zip -mtime +10 -exec rm {} \;
for fd in $NameOfFolder; do
# Name of the Backup File
file=$Sitename-$fd-$date.zip
 
 
# 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/$Sitename-$date-$DB_NAME.sql.tar
sleep 5s
##Process Upload Files to Google Drive
drive upload --file /backups/$file
sleep 5s
drive upload --file /backups/$Sitename-$date-$DB_NAME.sql.tar
if test $? = 0
then
echo $Sitename."Your Data Successfully Uploaded to the Google Drive!"
echo -e $Sitename."Your Data Successfully created and uploaded to the Google Drive!" | mail -s "Your VPS Backup from $date" cahyorizqullah@gmail.com
else
echo "Error in Your Data Upload to Google Drive" > $LOG_FILE
fi
done

Comments