Advertisement
Guest User

Untitled

a guest
May 9th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.05 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Configuration
  4. DBHOST="localhost"
  5. DBUSER="dbusername"
  6. DBPASS="dbp@ssword"
  7. DBNAME="whoreadme_main"
  8. FTPHOST="ftp.exmaple.com"
  9. FTPUSER="ftpuser"
  10. FTPPASS="ftppasswrd"
  11. FTPDIR="/backups"
  12.  
  13. ZIP="$(which zip)"
  14. FTP="$(which ftp)"
  15. MYSQLDUMP="$(which mysqldump)"
  16.  
  17. TIMESTART=$(date +%s)
  18.  
  19. # Start MySQL Dump
  20. $MYSQLDUMP --add-drop-table --allow-keywords -q -c -h $DBHOST -u $DBUSER -p$DBPASS --databases $DBNAME > $DBNAME.sql
  21.  
  22. # Compress the database to reduce size
  23. $ZIP -9 $DBNAME.sql.zip $DBNAME.sql
  24. rm -f $DBNAME.sql
  25.  
  26. # Upload to backup server using FTP
  27. $FTP -np $FTPHOST <<EOF
  28. quote USER $FTPUSER
  29. quote PASS $FTPPASS
  30. prompt
  31. binary
  32. cd $FTPDIR
  33. rename $DBNAME.sql.zip $DBNAME.sql.zip.archive
  34. put $DBNAME.sql.zip
  35. quit
  36. EOF
  37.  
  38. # Remove backup files
  39. rm -f $DBNAME.sql.zip
  40.  
  41. TIMEEND=$(date +%s)
  42. DURATION=$((TIMEEND - TIMESTART))
  43.  
  44. echo -e 'Backup completed on '$(date +"%e %b %Y, %a %r")' ('$(( DURATION / 60 ))'min '$(( DURATION % 60 ))'sec taken).' | mail -s "Backup for example.com" -a "From: BackupManager <root@`hostname`>" myemail@email.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement