Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ### SSH Info ###
  4. RHOST="sub.domain.tld" # Remote Host
  5. RUSER="username" # Remote User
  6. RDIR="/home/username/backup" # Remote Backup Directory
  7.  
  8. ### System Setup ###
  9. DATE=`date +%Y-%m-%d` # Current Date (2017-10-01)
  10. KEEPDAYS=14 # Days to keep
  11. LDIR="/home/localusername/backups/$RHOST" # Local Backup Directory
  12.  
  13. ### MySQL Setup ###
  14. MUSER="db-user" # MySQL User
  15. MPASS="db-pass" # MySQL Password
  16. MHOST="localhost" # XXXX is mt gs number # MySQL Host
  17. DBS="db-1 db-2 db-3" # Databases
  18.  
  19. mkdir -p $LDIR
  20.  
  21. ### Start MySQL Backup ###
  22. for db in $DBS # For each Database
  23. do
  24. echo ":: Dumping $db on Remote Server"
  25. FILE=$RDIR/$DATE.mysql-$db.sql.gz # Backup Filename
  26. ssh $RUSER@$RHOST "mysqldump -q -u $MUSER -h $MHOST -p$MPASS $db | gzip -9 > $FILE"
  27. # Dump the MySQL and gzip it up
  28. done
  29.  
  30. echo ":: Copying all files to Backup Server"
  31. scp $RUSER@$RHOST:$RDIR/$DATE.mysql-*.sql.gz $LDIR
  32. # Copy all the Files to Backup server
  33.  
  34. echo ":: Removing old Files on Remote and Backup Server"
  35. ssh $RUSER@$RHOST "find $RDIR/*.mysql-*.sql.gz -type f -daystart -mtime +$KEEPDAYS -exec rm {} \;"
  36. # Delete Files on Remote Server
  37.  
  38. find $LDIR/*.mysql-*.sql.gz -type f -daystart -mtime +$KEEPDAYS -exec ls {} \;
  39. find $LDIR/*.mysql-*.sql.gz -type f -daystart -mtime +$KEEPDAYS -exec rm {} \;
  40. # Delete old Files on Backup Server
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement