aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2014-12-30 18:17:03 +0100
committerlookshe <github@lookshe.org>2014-12-30 18:17:03 +0100
commit998d008f8afad722aefb62a995bac16e02128b82 (patch)
tree74788823b55876717c01e2f77d935b0acefda59b
parent61672bf575c84e1f3b313fe9ea2dd4de75b601ae (diff)
restore thread in woltlab from old backup of database
-rw-r--r--restore_thread.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/restore_thread.sh b/restore_thread.sh
new file mode 100644
index 0000000..10a8164
--- /dev/null
+++ b/restore_thread.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+if [ $# -ne 1 ]
+then
+ echo "no thread id"
+ exit 1
+fi
+
+threadID=$1
+
+#clean database
+echo "clean database..."
+mysql -u root -N -e "drop view if exists view_1000_posts;" tmp
+mysql -u root -N -e "show tables;" tmp | xargs -I{} mysql -u root -N -e "drop table if exists {};" tmp
+
+#import backup
+echo "import backup..."
+nice -n19 mysql -u root tmp < database_mitsu-talk.sql
+
+#delete all but the ones we need
+echo "delete unused tables..."
+mysql -u root -N -e "drop view if exists view_1000_posts;" tmp
+mysql -u root -N -e "show tables;" tmp | grep -v "^wbb1_1_post$" | grep -v "^wbb1_1_thread$" | grep -v "^wbb1_1_thread_subscription$" | grep -v "^wbb1_1_thread_visit$" | grep -v "^wbb1_1_savepost$" | grep -v "^wbb1_1_thread_announcement$" | grep -v "^wbb1_1_thread_rating$" | grep -v "^wbb1_1_thread_similar$" | xargs -I{} mysql -u root -N -e "drop table if exists {};" tmp
+
+#delete all entries but the ones with searched threadID
+mysql -u root -N -e "show tables;" tmp | while read tablename
+do
+ echo "deleting entries from $tablename..."
+ nice -n19 mysql -u root -N -e "delete from $tablename where not threadID=$threadID;" tmp
+done
+
+#dump it
+echo "dumping..."
+nice -n19 mysqldump --skip-add-drop-table --no-create-info tmp > $threadID.sql