Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- DATE=`date +%Y%m%d%H%M`
- MYSQL=mysql
- MYSQLDUMP=mysqldump
- DBNAME="dbname"
- USER="mysqldump"
- PASSWORD="***"
- mkdir $DATE
- echo "Exporting database $DBNAME"
- $MYSQL -u$USER -p$PASSWORD -e "SHOW tables IN $DBNAME;" | while read table; do
- if [ $table == "Tables_in_$DBNAME" ]; then
- continue
- fi
- echo " -> exporting table '$table': started"
- $MYSQLDUMP -u$USER -p$PASSWORD --single-transaction --routines --triggers --add-drop-table --add-locks --create-options --disable-keys --extended-insert --quick --set-charset $DBNAME $table | gzip > ./$DATE/$DATE_$table.sql.gz
- echo " -> exporting table '$table': ended"
- done
- s3cmd sync --recursive ./$DATE s3://mysql/
- find . -name *.sql.gz -mtime +2 -exec rm {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement