Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
481
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.  
  16. # Current date/time in YYYY-MM-DD format
  17. DT=$(date +%F)
  18.  
  19. # This is the heart of the backup script. It expects 3 parameters:
  20. #   1 - file name prefix, i.e. 'mysql'
  21. #   2 - Description, i.e. "MySQL dump"
  22. #   3 - File- or directory name(s) to backup, i.e. '/tmp/mysqldump.sql'
  23. dobackup(){
  24.   PREFIX=$1
  25.   DESCRIPTION=$2
  26.   shift 2
  27.   DIRS=$@
  28.  
  29.   # Change to root directory
  30.   cd /
  31.  
  32.   # Remove temp files we may be using.
  33.   rm -f /tmp/$PREFIX-*
  34.  
  35.   # Create the archive, and encrypt it
  36.   tar -czf /tmp/$PREFIX-$DT.tgz $DIRS
  37.   #openssl des3 -salt -k $CRYPTPW -in /tmp/$PREFIX-$DT.tgz -out /tmp/$PREFIX-$DT.tgz.des3
  38.   gpg -r "sebnapi" --batch -e /tmp/$PREFIX-$DT.tgz
  39.  
  40.   # Split this file into 8MB chunks, so we can email it
  41.   split -d --bytes=8M /tmp/$PREFIX-$DT.tgz.gpg /tmp/$PREFIX-$DT.tgz.gpg.
  42.  
  43.   # Finally email out each chunk separately
  44.   for f in /tmp/$PREFIX-$DT.tgz.gpg.*
  45.   do
  46.     SUBJ="Backup $MACHINE $DT $DESCRIPTION"
  47.     MSG=""
  48.     echo $MSG | mutt "$RCPT" -s "$SUBJ" -a $f
  49.   done
  50.  
  51.   # Clean up the mess we made
  52.   rm -f /tmp/$PREFIX-*
  53. }
  54.  
  55. # Dump the MySQL databases
  56. mysqldump -u $MYSQLUSER -p$MYSQLPASS --all-databases -Q > /tmp/mysqldump.sql
  57.  
  58. # Do the backups
  59. dobackup mysql "1/4 MySQL dump" tmp/mysqldump.sql
  60. dobackup etc "2/4 ETC" etc
  61. dobackup usr "3/4 USR" usr/local
  62. dobackup www "4/4 WWW" var/www
  63.  
  64. # Remove the database dump
  65. rm -f /tmp/mysqldump.sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement