#!/bin/sh

# =====================================================
#     Backup of all dbs
# =====================================================

password="%%mypassword%%!"

echo "-> Cleaning tmp/"
mkdir -p tmp
rm -f tmp/*

echo "-> creating mysql db backup of all dbs"
date=`date +%Y%m%d`

filename=$date

for i in `mysql -u root --password=$password -h localhost -Bse 'show  databases'`; do
        echo -n " -> "
        printf '%35s: ' "$i"
        mysqldump  -h localhost --password=$password -u root --databases $i > tmp/${filename}_${i} &&
        echo -n "[done]" || echo -n "[FAIL]"

        echo -n "     compressing with bzip: "
        nice -n 19 bzip2 -z tmp/${filename}_${i} && echo "[done]" ||  echo "[FAIL]"
done

filenameall="${filename}_mysql_all_dbs_dump.tar"
echo "-> Add all dbs into one big file called ${filenameall}"
tar cf ${filenameall} tmp/
nice -n 19 bzip2 -z ${filenameall}
echo " [done]"
Powered by MediaWiki