Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ### SSH Info ###
- RHOST="sub.domain.tld" # Remote Host
- RUSER="username" # Remote User
- RDIR="/home/username/backup" # Remote Backup Directory
- ### System Setup ###
- DATE=`date +%Y-%m-%d` # Current Date (2017-10-01)
- KEEPDAYS=14 # Days to keep
- LDIR="/home/localusername/backups/$RHOST" # Local Backup Directory
- ### MySQL Setup ###
- MUSER="db-user" # MySQL User
- MPASS="db-pass" # MySQL Password
- MHOST="localhost" # XXXX is mt gs number # MySQL Host
- DBS="db-1 db-2 db-3" # Databases
- mkdir -p $LDIR
- ### Start MySQL Backup ###
- for db in $DBS # For each Database
- do
- echo ":: Dumping $db on Remote Server"
- FILE=$RDIR/$DATE.mysql-$db.sql.gz # Backup Filename
- ssh $RUSER@$RHOST "mysqldump -q -u $MUSER -h $MHOST -p$MPASS $db | gzip -9 > $FILE"
- # Dump the MySQL and gzip it up
- done
- echo ":: Copying all files to Backup Server"
- scp $RUSER@$RHOST:$RDIR/$DATE.mysql-*.sql.gz $LDIR
- # Copy all the Files to Backup server
- echo ":: Removing old Files on Remote and Backup Server"
- ssh $RUSER@$RHOST "find $RDIR/*.mysql-*.sql.gz -type f -daystart -mtime +$KEEPDAYS -exec rm {} \;"
- # Delete Files on Remote Server
- find $LDIR/*.mysql-*.sql.gz -type f -daystart -mtime +$KEEPDAYS -exec ls {} \;
- find $LDIR/*.mysql-*.sql.gz -type f -daystart -mtime +$KEEPDAYS -exec rm {} \;
- # Delete old Files on Backup Server
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement