Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Configuration
- DBHOST="localhost"
- DBUSER="dbusername"
- DBPASS="dbp@ssword"
- DBNAME="whoreadme_main"
- FTPHOST="ftp.exmaple.com"
- FTPUSER="ftpuser"
- FTPPASS="ftppasswrd"
- FTPDIR="/backups"
- ZIP="$(which zip)"
- FTP="$(which ftp)"
- MYSQLDUMP="$(which mysqldump)"
- TIMESTART=$(date +%s)
- # Start MySQL Dump
- $MYSQLDUMP --add-drop-table --allow-keywords -q -c -h $DBHOST -u $DBUSER -p$DBPASS --databases $DBNAME > $DBNAME.sql
- # Compress the database to reduce size
- $ZIP -9 $DBNAME.sql.zip $DBNAME.sql
- rm -f $DBNAME.sql
- # Upload to backup server using FTP
- $FTP -np $FTPHOST <<EOF
- quote USER $FTPUSER
- quote PASS $FTPPASS
- prompt
- binary
- cd $FTPDIR
- rename $DBNAME.sql.zip $DBNAME.sql.zip.archive
- put $DBNAME.sql.zip
- quit
- EOF
- # Remove backup files
- rm -f $DBNAME.sql.zip
- TIMEEND=$(date +%s)
- DURATION=$((TIMEEND - TIMESTART))
- 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