Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #########################################
- # Shell script to backup MySQL database #
- #########################################
- # Variables
- USER=""
- PASSWORD=""
- DATABASE=""
- HOST=""
- DESTINATION=""
- DAYS=10
- BASE_NAME="dump_$(date +"%d-%m-%Y")"
- # Create directory if it doesn't exist
- if [ ! -d $DESTINATION ]; then
- mkdir -p $DESTINATION;
- fi
- # Dump database
- mysqldump -u $USER -p"$PASSWORD" $DATABASE > $BASE_NAME.sql
- # Create TAR GZ archive file and remove the original SQL
- tar -czvf $BASE_NAME.tar.gz $BASE_NAME.sql
- rm $BASE_NAME.sql
- # Move file to directory
- mv $BASE_NAME.tar.gz $DESTINATION
- # Remove files that are older that $DAYS days
- find $DESTINATION -mtime +$DAYS -exec rm -f {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement