| 1 | Script created on ticket:907 and used on PuffinServer. |
| 2 | |
| 3 | {{{ |
| 4 | #!/bin/bash |
| 5 | |
| 6 | # Directory for root to dump all database files |
| 7 | DUMP_DIR="/var/backups/mysql/sqldump" |
| 8 | |
| 9 | if [[ ! -d "${DUMP_DIR}" ]]; then |
| 10 | mkdir "${DUMP_DIR}" -p |
| 11 | chmod 700 "${DUMP_DIR}" |
| 12 | fi |
| 13 | |
| 14 | # All the MySQL databases, excluding ones we don't want |
| 15 | DATABASES=$(mysql -NBA -e 'SHOW DATABASES' | grep -vw 'mysql' | grep -vw 'information_schema' | grep -vw 'performance_schema' ) |
| 16 | |
| 17 | # Loop through the databases and dump them |
| 18 | for d in ${DATABASES} ; do |
| 19 | # Find the cache tables |
| 20 | CACHE_TABLES=$(mysql -NBA -e 'show tables' ${d} | egrep '^cach|flood|watchdog') |
| 21 | for c in ${CACHE_TABLES}; do |
| 22 | mysql -NBA -e "TRUNCATE ${c}" ${d} |
| 23 | done |
| 24 | # Dump the databases to DUMP_DIR |
| 25 | echo "Dumping ${d}" |
| 26 | nice -n19 mysqldump --add-drop-table ${d} > ${DUMP_DIR}/${d}.sql || exit 1 |
| 27 | done |
| 28 | }}} |