Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Fill this in
- DB_USER=""
- DB_PASSWORD=""
- DB_HOST="localhost"
- DB_PORT="3306"
- S3_BUCKET=""
- SECRET_KEY=""
- # Basic variables
- mysqlpass="$DB_PASSWORD"
- mysqluser="$DB_USER"
- mysqlhost="$DB_HOST"
- mysqlport="$DB_PORT"
- bucket="s3://$S3_BUCKET"
- secret_key="$SECRET_KEY"
- # Timestamp (sortable AND readable)
- stamp=`date +"%s - %A %d %B %Y @ %H%M"`
- # List all the databases
- databases=`mysql -u $DB_USER -p$mysqlpass -P $DB_PORT -h $DB_HOST -e "SHOW DATABASES;" | tr -d "| " | grep -v "\(Database\|information_schema\|performance_schema\|sys\|mysql\|test\)"`
- # Feedback
- echo -e "Dumping to \e[1;32m$bucket/$stamp/\e[00m"
- # Loop the databases
- for db in $databases; do
- # Define our filenames
- filename="$stamp - $db.sql.gpg"
- tmpfile="/tmp/$filename"
- object="$bucket/$stamp/$filename"
- # Feedback
- echo -e "Filename: $tmpfile"
- echo -e "Destination: $object"
- echo -e "\e[1;34m$db\e[00m"
- # Dump and gpg encrypt
- echo -e " creating \e[0;35m$tmpfile\e[00m"
- mysqldump -u root -p$mysqlpass --force --opt --databases "$db" | gzip -c > "$tmpfile"
- # Upload
- echo -e " uploading..."
- s3cmd put "$tmpfile" "$object"
- # Delete
- rm -f "$tmpfile"
- done;
- # Jobs a goodun
- echo -e "\e[1;32mJobs a goodun\e[00m"
Add Comment
Please, Sign In to add comment