Advertisement
Guest User

Untitled

a guest
Feb 28th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. DATABASE="homestead"
  4. BACKUP="$DATABASE-`date +%Y%m%d%H%M`_full"
  5. BACKUP_DIR="/var/backups/database"
  6.  
  7.  
  8. # Get the settings
  9. source ~/backup/.env
  10.  
  11. # Backup Database
  12. innobackupex $BACKUP_DIR/$BACKUP --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --rsync --no-timestamp
  13.  
  14. if [ "$?" -e "0" ]; then
  15. echo "Backup failed";
  16. exit 1;
  17. fi
  18.  
  19. # Prepare for restore
  20. innobackupex --apply-log $BACKUP_DIR/$BACKUP
  21.  
  22. if [ "$?" -ne "0" ]; then
  23. # Copy to remote backup destination S3|NAS|local
  24. # Make sure you added the remote to your ssh config file
  25. rsync -vzcrSLhp --progress $BACKUP_DIR/$BACKUP /tmp #remoteServer:/var/backups/$BACKUP
  26.  
  27. if [ "$?" -ne "0" ]; then
  28. echo "Upload to remoteServer failed";
  29. exit 1;
  30. fi
  31. fi
  32.  
  33. # Clean Up
  34. rm -rf $BACKUP_DIR
  35. echo "Backup completed"
  36. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement