Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #########################################
  4. # Shell script to backup MySQL database #
  5. #########################################
  6.  
  7. # Variables
  8. USER=""
  9. PASSWORD=""
  10. DATABASE=""
  11. HOST=""
  12. DESTINATION=""
  13. DAYS=10
  14. BASE_NAME="dump_$(date +"%d-%m-%Y")"
  15.  
  16. # Create directory if it doesn't exist
  17. if [ ! -d $DESTINATION ]; then
  18. mkdir -p $DESTINATION;
  19. fi
  20.  
  21. # Dump database
  22. mysqldump -u $USER -p"$PASSWORD" $DATABASE > $BASE_NAME.sql
  23.  
  24. # Create TAR GZ archive file and remove the original SQL
  25. tar -czvf $BASE_NAME.tar.gz $BASE_NAME.sql
  26. rm $BASE_NAME.sql
  27.  
  28. # Move file to directory
  29. mv $BASE_NAME.tar.gz $DESTINATION
  30.  
  31. # Remove files that are older that $DAYS days
  32. find $DESTINATION -mtime +$DAYS -exec rm -f {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement