Created
May 1, 2014 20:19
-
-
Save Demontager/1a1cd52860f87e4a489c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Batch Mysql databases and users' priveleges restore | |
# Backup directory | |
BDIR="/home/www/backup/mysql-15-Apr-2014" | |
LOG="restore.txt" | |
DATE=`date +%d-%b-%Y_%H:%M:%S` | |
DBL=`find "$BDIR" -type f \( ! -iname "*.sh" -a ! -iname "*.sql" -a ! -iname "*.txt" \) -print0 | xargs -0 basename -a|awk -F. '{print $1}'` | |
echo $DBL | |
exit 0 | |
# Mysql details | |
DBUSER="root" | |
DBPASS="pass" | |
# Create empty databases | |
for db in $DBL; do | |
mysql -v -u"$DBUSER" -p"$DBPASS" -e "CREATE DATABASE IF NOT EXISTS \`$db\`" >> "$BDIR/$LOG" 2>&1 | |
done | |
# Restore users and their privileges | |
mysql -v -u"$DBUSER" -p"$DBPASS" < "$BDIR/users.sql" >> "$BDIR/$LOG" 2>&1 | |
# Restore databases from archives | |
for arch in $DBL; do | |
gunzip < "$BDIR/$arch.gz" | mysql -f -u"$DBUSER" -p"$DBPASS" $arch >> "$BDIR/$LOG" 2>&1 | |
done | |
# Clean up log | |
sed -e '/^$/d' "$BDIR/$LOG"|uniq -u|uniq > "$BDIR/tmp.txt" | |
rm "$BDIR/$LOG" | |
mv "$BDIR/tmp.txt" "$BDIR/$DATE.$LOG" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
root@debian:~/scripts# find /home/www/backup/mysql-15-Apr-2014 -type f ( ! -iname ".sh" -a ! -iname ".sql" -a ! -iname "*.txt" ) -print|awk -F / '{print $NF}'|awk -F . '{print $1}'
escswim
sauvig
amitysource
ennixtalks
voxl
pdalady
minecraft365
ultratouch
printcounter
piyazilim
forexinvest
bestwestern
belcity