Backing up and restoring MySQL
Instructions and scripts for backing up and restoring MySQL databases.
Backing up MySQL
#!/bin/sh
if [ -z $3 ]; then
echo "Wrong syntax..."
echo "use: $0 <mysql_root> <mysql_password> <dump_dir>"
exit
fi
echo Dumping MySQL database to $3.
umask 077
rm $3/*
mkdir $3 &>/dev/null
cd $3
for i in `echo "SHOW DATABASES" |/usr/bin/mysql -s -u $1 -p$2`; do
/usr/bin/mysqldump --single-transaction -f -u $1 -p$2 $i >$i.sql
if [ $? -ne 0 ] ; then
echo ERROR: Fail when dumping $i
fi
done
du -sh $3
echo Databasedump doneRestoring MySQL
Last updated
Was this helpful?