Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This machine's name, to keep things apart if you have multiple
- MACHINE=""
- # The password used for encryption
- #CRYPTPW="my-supersecret-encryption-password-goes-here"
- #we use gpg instead
- # Username and password for MySQL (root preferred to backup all tables)
- MYSQLUSER=""
- MYSQLPASS=""
- # Email address where backup files are sent to
- RCPT="________@googlemail.com"
- # Current date/time in YYYY-MM-DD format
- DT=$(date +%F)
- # This is the heart of the backup script. It expects 3 parameters:
- # 1 - file name prefix, i.e. 'mysql'
- # 2 - Description, i.e. "MySQL dump"
- # 3 - File- or directory name(s) to backup, i.e. '/tmp/mysqldump.sql'
- dobackup(){
- PREFIX=$1
- DESCRIPTION=$2
- shift 2
- DIRS=$@
- # Change to root directory
- cd /
- # Remove temp files we may be using.
- rm -f /tmp/$PREFIX-*
- # Create the archive, and encrypt it
- tar -czf /tmp/$PREFIX-$DT.tgz $DIRS
- #openssl des3 -salt -k $CRYPTPW -in /tmp/$PREFIX-$DT.tgz -out /tmp/$PREFIX-$DT.tgz.des3
- gpg -r "sebnapi" --batch -e /tmp/$PREFIX-$DT.tgz
- # Split this file into 8MB chunks, so we can email it
- split -d --bytes=8M /tmp/$PREFIX-$DT.tgz.gpg /tmp/$PREFIX-$DT.tgz.gpg.
- # Finally email out each chunk separately
- for f in /tmp/$PREFIX-$DT.tgz.gpg.*
- do
- SUBJ="Backup $MACHINE $DT $DESCRIPTION"
- MSG=""
- echo $MSG | mutt "$RCPT" -s "$SUBJ" -a $f
- done
- # Clean up the mess we made
- rm -f /tmp/$PREFIX-*
- }
- # Dump the MySQL databases
- mysqldump -u $MYSQLUSER -p$MYSQLPASS --all-databases -Q > /tmp/mysqldump.sql
- # Do the backups
- dobackup mysql "1/4 MySQL dump" tmp/mysqldump.sql
- dobackup etc "2/4 ETC" etc
- dobackup usr "3/4 USR" usr/local
- dobackup www "4/4 WWW" var/www
- # Remove the database dump
- rm -f /tmp/mysqldump.sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement