Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # MySQL username
- USER="root"
- # MySQL Password
- PASS="password"
- # Location to store backups including trailing /
- STORAGE="/home/yourusername/backups/"
- # List of databases to ignore. Ignore "Database" as it's the table header and not an actual database, and information_schema as it isn't lockable and is just metadata
- IGNORELIST=( "Database" "information_schema" )
- # You don't need to edit anything beyond this point
- # Where is the mysql executable? (usually /usr/bin/mysql)
- MYSQL=($which mysql)
- # Get a list of databases
- DATABASES=`echo "SHOW DATABASES;" | $MYSQL -u$USER -p$PASS`
- function isignored() {
- for IGNORED in "${IGNORELIST[@]}"
- do
- if [ "$1" == "$IGNORED" ]
- then
- return 0
- fi
- done
- return 1
- }
- echo "Backup started at `date`"
- # Loop through list of databases
- for DATABASE in $DATABASES
- do
- # Check if we are ignoring this database
- if ( isignored "$DATABASE" )
- then
- continue
- fi
- # Create the directories if needed
- mkdir -p $STORAGE`date +%Y/%B/%d`
- # Perform the backup
- echo "Backing up $DATABASE to $STORAGE`date +%Y/%B/%d`/$DATABASE.sql.gz"
- START=`date +%s`
- mysqldump -u$USER -p$PASS $DATABASE | ionice -c 3 gzip -c > $STORAGE`date +%Y/%B/%d`/$DATABASE.sql.gz
- echo "Backed up $DATABASE to $STORAGE`date +%Y/%B/%d`/$DATABASE.sql.gz in $((`date +%s`-$START)) seconds"
- done
- echo "Backup complete at `date`"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement