Commit f339d0cf authored by Vitaly Lipatov's avatar Vitaly Lipatov

ad restore_table scripts

parent 80235a6b
#!/bin/sh
. ./config
mysql_query()
{
echo "$@" |
#mysql -s -N --default-character-set=utf8 --user=$DB_USER --password=$DB_PASS --host $DB_HOST $DB
mysql -s -N --default-character-set=utf8 --user=$DB_USER --host $DB_HOST $DB
}
mysql_dump()
{
mysqldump --compact --no-create-info --where "bug_id=$1" $DB $DB_TABLE
}
sleep_bar()
{
echo -n "Sleep $1 ..."
sleep $1
echo "OK"
}
check_mysql()
{
sleep_bar 2
if ! pidof mysqld ; then
echo " missed mysqld, restarting $id" | tee $0.log
serv mysqld restart
sleep_bar 10
fi
}
#mkdir tables || exit
for DB_TABLE in $(mysql_query "SHOW TABLES") ; do
echo "Processing $DB_TABLE ..."
count="$(mysql_query "SELECT COUNT(*) FROM $DB_TABLE")" && continue
echo "Problem with $DB_TABLE ..."
check_mysql
./get_table.sh $DB_TABLE
done
DB_USER=root
#DB_PASS=Wetcyr23
DB_HOST=localhost
DB=eter_rt
#!/bin/sh
# Run: table name
. ./config
DB_TABLE=$1
[ -n "$DB_TABLE" ] || exit
ALL_ID=''
[ "$2" = "--force" ] && ALL_ID=1
mysql_query()
{
echo "$@" |
#mysql -s -N --default-character-set=utf8 --user=$DB_USER --password=$DB_PASS --host $DB_HOST $DB
mysql -s -N --default-character-set=utf8 --user=$DB_USER --host $DB_HOST $DB
}
mysql_dump()
{
mysqldump --compact --no-create-info --where "$1" $DB $DB_TABLE
}
# get first column name
column_name="$(mysql_query "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = SCHEMA() AND table_name = '$DB_TABLE' AND ordinal_position = 1")"
#echo "$column_name"
# can Segfaults
#echo "Total rows in $DB_TABLE: $(mysql_query "SELECT COUNT(*) FROM $DB_TABLE")"
mysqldump --no-data $DB $DB_TABLE >$DB_TABLE.sql
rm -f $0.id.log
# with id
do_iterate()
{
echo -en "$id\r"
#mysql_dump "$column_name=$id" >>$DB_TABLE.sql && continue
mysql_dump "$column_name='$id'" >>$DB_TABLE.sql && continue
echo
echo "Problem with $id" | tee $0.log
echo "$id" >>$0.id.log
sleep 2
if ! pidof mysqld ; then
echo " missed mysqld, restarting $id" | tee $0.log
serv mysqld restart
sleep 10
fi
}
# LIMIT='LIMIT 10'
LIMIT=''
if [ -n "$ALL_ID" ] ; then
id=0
while true ; do
id=$(($id+1))
do_iterate $id
done
else
mysql_query "SELECT $column_name FROM $DB_TABLE $LIMIT" | while read id ; do
do_iterate $id
done
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment