Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.77 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This machine's name, to keep things apart if you have multiple
  4. MACHINE=""
  5.  
  6. # The password used for encryption
  7. #CRYPTPW="my-supersecret-encryption-password-goes-here"
  8. #we use gpg instead
  9.  
  10. # Username and password for MySQL (root preferred to backup all tables)
  11. MYSQLUSER=""
  12. MYSQLPASS=""
  13.  
  14. # Email address where backup files are sent to
  15. RCPT="________@googlemail.com"
  16.  
  17. # Current date/time in YYYY-MM-DD format
  18. DT=$(date +%F)
  19.  
  20. # This is the heart of the backup script. It expects 3 parameters:
  21. #   1 - file name prefix, i.e. 'mysql'
  22. #   2 - Description, i.e. "MySQL dump"
  23. #   3 - File- or directory name(s) to backup, i.e. '/tmp/mysqldump.sql'
  24. dobackup(){
  25.   PREFIX=$1
  26.   DESCRIPTION=$2
  27.   shift 2
  28.   DIRS=$@
  29.  
  30.   # Change to root directory
  31.   cd /
  32.  
  33.   # Remove temp files we may be using.
  34.   rm -f /tmp/$PREFIX-*
  35.  
  36.   # Create the archive, and encrypt it
  37.   tar -czf /tmp/$PREFIX-$DT.tgz $DIRS
  38.   #openssl des3 -salt -k $CRYPTPW -in /tmp/$PREFIX-$DT.tgz -out /tmp/$PREFIX-$DT.tgz.des3
  39.   gpg -r "sebnapi" --batch -e /tmp/$PREFIX-$DT.tgz
  40.  
  41.   # Split this file into 8MB chunks, so we can email it
  42.   split -d --bytes=8M /tmp/$PREFIX-$DT.tgz.gpg /tmp/$PREFIX-$DT.tgz.gpg.
  43.  
  44.   # Finally email out each chunk separately
  45.   for f in /tmp/$PREFIX-$DT.tgz.gpg.*
  46.   do
  47.     SUBJ="Backup $MACHINE $DT $DESCRIPTION"
  48.     MSG=""
  49.     echo $MSG | mutt "$RCPT" -s "$SUBJ" -a $f
  50.   done
  51.  
  52.   # Clean up the mess we made
  53.   rm -f /tmp/$PREFIX-*
  54. }
  55.  
  56. # Dump the MySQL databases
  57. mysqldump -u $MYSQLUSER -p$MYSQLPASS --all-databases -Q > /tmp/mysqldump.sql
  58.  
  59. # Do the backups
  60. dobackup mysql "1/4 MySQL dump" tmp/mysqldump.sql
  61. dobackup etc "2/4 ETC" etc
  62. dobackup usr "3/4 USR" usr/local
  63. dobackup www "4/4 WWW" var/www
  64.  
  65. # Remove the database dump
  66. rm -f /tmp/mysqldump.sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement