SHARE
TWEET

Untitled

a guest Mar 19th, 2017 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. #!/bin/bash
  89. #set web root location
  90. WR=/var/www/html/
  91. #set mysql settings
  92. MQLUSER=backup
  93. MQLPASS=xxxx
  94. MQLDB=mysql-db-name
  95. #set GPG password
  96. GPGPASS=your-gpg-pass
  97. #set BB bucket
  98. BBBUCKET=bb-bucket-name
  99. #set path to backup
  100. PATH1=/path/to/backups
  101. #set file name
  102. FILENAME1=mysql-`date +%s`.sql
  103. WEBROOT1=webroot-`date +%s`.tar.gz
  104. NGINX1=nginx-`date +%s`.tar.gz
  105. #set path+file name
  106. FILENAME=$PATH1/$FILENAME1
  107. WEBROOT=$PATH1/$WEBROOT1
  108. NGINX=$PATH1/$NGINX1
  109. #stop nginx
  110. systemctl stop nginx
  111. echo "nginx stopped"
  112. #compress webroot to .tar.gz
  113. tar -zcf $WEBROOT $WR
  114. echo "webroot compressed to .tar.gz"
  115. #take nginx config backup
  116. tar -zcf $NGINX /etc/nginx/
  117. echo "nginx configs compressed to .tar.gz"
  118. #take mariadb backup
  119. mysqldump --user=$MQLUSER --password=$MQLPASS > $FILENAME $MQLDB
  120. echo "mariadb database backup taken"
  121. #start nginx
  122. systemctl start nginx
  123. echo "nginx started back up"
  124. #compress mariadb backup to .tar.gz
  125. tar -zcf $FILENAME.tar.gz $FILENAME
  126. echo "database compressed to .tar.gz"
  127. #delete .sql file
  128. rm $FILENAME
  129. echo ".sql file deleted"
  130. #encrypt webroot compressed file symmetrically using gpg
  131. gpg --yes --batch --passphrase=$GPGPASS -c -o $WEBROOT.gpg $WEBROOT
  132. echo "webroot encrypted"
  133. #delete webroot compressed file
  134. rm $WEBROOT
  135. echo "webroot compressed file deleted"
  136. #encrypt db backup compressed file symmetrically using gpg
  137. gpg --yes --batch --passphrase=$GPGPASS -c -o $FILENAME.tar.gz.gpg $FILENAME.tar.gz
  138. echo "db backup encrypted"
  139. #delete db backup compressed file
  140. rm $FILENAME.tar.gz
  141. echo "db backup compressed file deleted"
  142. #encrypt nginx compressed file symmetrically using gpg
  143. gpg --yes --batch --passphrase=$GPGPASS -c -o $NGINX.gpg $NGINX
  144. echo "nginx encrypted"
  145. #delete nginx compressed file
  146. rm $NGINX
  147. echo "nginx compressed file deleted"
  148. #sha1sum calculation
  149. #calculate cheksum for nginx
  150. SHANGX=`sha1sum $NGINX.gpg | awk '{print $1}'`
  151. #calculate cheksum for webroot
  152. SHAWR=`sha1sum $WEBROOT.gpg | awk '{print $1}'`
  153. #calculate cheksum for mysqldb
  154. SHAMQL=`sha1sum $FILENAME.tar.gz.gpg | awk '{print $1}'`
  155. set -x #echo on
  156. cd $PATH1/ #change directory to path
  157. #things to upload to backblaze
  158. #upload db backup to BackBlaze B2
  159. b2 upload_file --sha1 $SHAMQL $BBBUCKET $FILENAME1.tar.gz.gpg mysql/$FILENAME1.tar.gz.gpg
  160. echo "encrypted db backup uploaded to BackBlaze B2 bucket:$BBBUCKET filename:$FILENAME1.tar.gz.gpg folder:mysql sha1sum:$SHAMQL"
  161. #upload webroot backupto BackBlaze B2
  162. b2 upload_file --sha1 $SHAWR $BBBUCKET $WEBROOT1.gpg webroot/$WEBROOT1.gpg
  163. echo "encrypted webroot backup uploaded to BackBlaze B2 bucket:$BBBUCKET filename:$WEBROOT1.gpg folder:webroot sha1sum:$SHAWR"
  164. #upload nginx backup to BackBlaze B2
  165. b2 upload_file --sha1 $SHANGX $BBBUCKET $NGINX1.gpg nginx/$NGINX1.gpg
  166. echo "encrypted nginx backup uploaded to BackBlaze B2 bucket:$BBBUCKET filename:$NGINX1.gpg folder:nginx sha1sum:$SHANGX"
  167. set +x #echo off
  168. #delete files
  169. rm $FILENAME.tar.gz.gpg
  170. echo "db encrypted backup $FILENAME1.tar.gz.gpg deleted from local machine"
  171. rm $WEBROOT.gpg
  172. echo "webroot encrypted backup $WEBROOT1.gpg deleted from local machine"
  173. rm $NGINX.gpg
  174. 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