cdw1p

[BASH] Google Drive Auto Backup

Apr 23rd, 2018
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.37 KB | None | 0 0
  1. #!/bin/sh
  2. ##-----------------------Database Access--------------------------##
  3. DB_NAME="dbname"
  4. DB_USER="dbuser"
  5. DB_PASSWORD="dbpass"
  6.  
  7. ##-----------------------Folder Web or Folder you want to backup--------------------------##
  8. NameOfFolder=("seatide")
  9. SourceOfFolder="/home/source"
  10. BackupLocation="/backups"
  11. date=$(date +"%Y-%m-%d")
  12. Sitename="SEATIDE"
  13. ##That mean, you will Backup the folder /home/albennet and will save into Folder /backups
  14. if [ ! -d $BackupLocation ]; then
  15. mkdir -p $BackupLocation
  16. fi
  17. find $BackupLocation/*.zip -mtime +10 -exec rm {} \;
  18. for fd in $NameOfFolder; do
  19. # Name of the Backup File
  20. file=$Sitename-$fd-$date.zip
  21.  
  22.  
  23. # Zip the Folder you will want to Backup
  24. echo "Starting to zip the folder and files"
  25. cd $SourceOfFolder
  26. zip -r $BackupLocation/$file $fd
  27. sleep 5s
  28. mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $BackupLocation/$Sitename-$date-$DB_NAME.sql.tar
  29. sleep 5s
  30. ##Process Upload Files to Google Drive
  31. drive upload --file /backups/$file
  32. sleep 5s
  33. drive upload --file /backups/$Sitename-$date-$DB_NAME.sql.tar
  34. if test $? = 0
  35. then
  36. echo $Sitename."Your Data Successfully Uploaded to the Google Drive!"
  37. echo -e $Sitename."Your Data Successfully created and uploaded to the Google Drive!" | mail -s "Your VPS Backup from $date" cahyorizqullah@gmail.com
  38. else
  39. echo "Error in Your Data Upload to Google Drive" > $LOG_FILE
  40. fi
  41. done
Add Comment
Please, Sign In to add comment