SHARE
TWEET

Untitled

a guest Mar 19th, 2017 26 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #set web root location
  3. WR=/var/www/html/
  4. #set mysql settings
  5. MQLUSER=backup
  6. MQLPASS=xxxx
  7. MQLDB=mysql-db-name
  8. #set GPG password
  9. GPGPASS=your-gpg-pass
  10. #set BB bucket
  11. BBBUCKET=bb-bucket-name
  12. #set path to backup
  13. PATH1=/path/to/backups
  14. #set file name
  15. FILENAME1=mysql-`date +%s`.sql
  16. WEBROOT1=webroot-`date +%s`.tar.gz
  17. NGINX1=nginx-`date +%s`.tar.gz
  18. #set path+file name
  19. FILENAME=$PATH1/$FILENAME1
  20. WEBROOT=$PATH1/$WEBROOT1
  21. NGINX=$PATH1/$NGINX1
  22. #stop nginx
  23. systemctl stop nginx
  24. echo "nginx stopped"
  25. #compress webroot to .tar.gz
  26. tar -zcf $WEBROOT $WR
  27. echo "webroot compressed to .tar.gz"
  28. #take nginx config backup
  29. tar -zcf $NGINX /etc/nginx/
  30. echo "nginx configs compressed to .tar.gz"
  31. #take mariadb backup
  32. mysqldump --user=$MQLUSER --password=$MQLPASS > $FILENAME $MQLDB
  33. echo "mariadb database backup taken"
  34. #start nginx
  35. systemctl start nginx
  36. echo "nginx started back up"
  37. #compress mariadb backup to .tar.gz
  38. tar -zcf $FILENAME.tar.gz $FILENAME
  39. echo "database compressed to .tar.gz"
  40. #delete .sql file
  41. rm $FILENAME
  42. echo ".sql file deleted"
  43. #encrypt webroot compressed file symmetrically using gpg
  44. gpg --yes --batch --passphrase=$GPGPASS -c -o $WEBROOT.gpg $WEBROOT
  45. echo "webroot encrypted"
  46. #delete webroot compressed file
  47. rm $WEBROOT
  48. echo "webroot compressed file deleted"
  49. #encrypt db backup compressed file symmetrically using gpg
  50. gpg --yes --batch --passphrase=$GPGPASS -c -o $FILENAME.tar.gz.gpg $FILENAME.tar.gz
  51. echo "db backup encrypted"
  52. #delete db backup compressed file
  53. rm $FILENAME.tar.gz
  54. echo "db backup compressed file deleted"
  55. #encrypt nginx compressed file symmetrically using gpg
  56. gpg --yes --batch --passphrase=$GPGPASS -c -o $NGINX.gpg $NGINX
  57. echo "nginx encrypted"
  58. #delete nginx compressed file
  59. rm $NGINX
  60. echo "nginx compressed file deleted"
  61. #sha1sum calculation
  62. #calculate cheksum for nginx
  63. SHANGX=`sha1sum $NGINX.gpg | awk '{print $1}'`
  64. #calculate cheksum for webroot
  65. SHAWR=`sha1sum $WEBROOT.gpg | awk '{print $1}'`
  66. #calculate cheksum for mysqldb
  67. SHAMQL=`sha1sum $FILENAME.tar.gz.gpg | awk '{print $1}'`
  68. set -x #echo on
  69. cd $PATH1/ #change directory to path
  70. #things to upload to backblaze
  71. #upload db backup to BackBlaze B2
  72. b2 upload_file --sha1 $SHAMQL $BBBUCKET $FILENAME1.tar.gz.gpg mysql/$FILENAME1.tar.gz.gpg
  73. echo "encrypted db backup uploaded to BackBlaze B2 bucket:$BBBUCKET filename:$FILENAME1.tar.gz.gpg folder:mysql sha1sum:$SHAMQL"
  74. #upload webroot backupto BackBlaze B2
  75. b2 upload_file --sha1 $SHAWR $BBBUCKET $WEBROOT1.gpg webroot/$WEBROOT1.gpg
  76. echo "encrypted webroot backup uploaded to BackBlaze B2 bucket:$BBBUCKET filename:$WEBROOT1.gpg folder:webroot sha1sum:$SHAWR"
  77. #upload nginx backup to BackBlaze B2
  78. b2 upload_file --sha1 $SHANGX $BBBUCKET $NGINX1.gpg nginx/$NGINX1.gpg
  79. echo "encrypted nginx backup uploaded to BackBlaze B2 bucket:$BBBUCKET filename:$NGINX1.gpg folder:nginx sha1sum:$SHANGX"
  80. set +x #echo off
  81. #delete files
  82. rm $FILENAME.tar.gz.gpg
  83. echo "db encrypted backup $FILENAME1.tar.gz.gpg deleted from local machine"
  84. rm $WEBROOT.gpg
  85. echo "webroot encrypted backup $WEBROOT1.gpg deleted from local machine"
  86. rm $NGINX.gpg
  87. echo "nginx encrypted backup $NGINX1.gpg deleted from local machine"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top