Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- DATABASE="homestead"
- BACKUP="$DATABASE-`date +%Y%m%d%H%M`_full"
- BACKUP_DIR="/var/backups/database"
- # Get the settings
- source ~/backup/.env
- # Backup Database
- innobackupex $BACKUP_DIR/$BACKUP --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --rsync --no-timestamp
- if [ "$?" -e "0" ]; then
- echo "Backup failed";
- exit 1;
- fi
- # Prepare for restore
- innobackupex --apply-log $BACKUP_DIR/$BACKUP
- if [ "$?" -ne "0" ]; then
- # Copy to remote backup destination S3|NAS|local
- # Make sure you added the remote to your ssh config file
- rsync -vzcrSLhp --progress $BACKUP_DIR/$BACKUP /tmp #remoteServer:/var/backups/$BACKUP
- if [ "$?" -ne "0" ]; then
- echo "Upload to remoteServer failed";
- exit 1;
- fi
- fi
- # Clean Up
- rm -rf $BACKUP_DIR
- echo "Backup completed"
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement