瀏覽代碼

Database maintenance

Bob Mottram 10 年之前
父節點
當前提交
40d34d41b9
共有 1 個文件被更改,包括 81 次插入0 次删除
  1. 81
    0
      beaglebone.txt

+ 81
- 0
beaglebone.txt 查看文件

@@ -7124,6 +7124,87 @@ service cron restart
7124 7124
 
7125 7125
 This will delete all pasted content once per day.
7126 7126
 
7127
+** Database maintenance
7128
+
7129
+#+BEGIN_VERSE
7130
+/To be ready to fail is to be prepared for success./
7131
+
7132
+-- Jose Bergamin
7133
+#+END_VERSE
7134
+
7135
+Ideally the system should be as close to "/install and forget/" as possible, but sometimes mysql databases can become corrupted. To handle that situation we can set up a script to monitor the databases and automatically try to repair them, and if the repair fails then to roll back to the previous day's backup, so that at most you may have lost one day of social media updates, rather than losing everything.
7136
+
7137
+#+BEGIN_SRC: bash
7138
+editor /usr/bin/repairdatabase
7139
+#+END_SRC
7140
+
7141
+Add the following, using your mysql root password and entering your email address.
7142
+
7143
+#+BEGIN_SRC: bash
7144
+#!/bin/bash
7145
+
7146
+DATABASE=$1
7147
+EMAIL=myusername@mydomainname.com
7148
+
7149
+MYSQL_ROOT_PASSWORD=mysqlrootpassword
7150
+TEMPFILE=/tmp/repairdatabase_$DATABASE
7151
+
7152
+umask 0077
7153
+
7154
+# check the database
7155
+mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
7156
+
7157
+# Attempt to repair the database if it contains errors
7158
+if grep -q "Error" "$TEMPFILE"; then
7159
+    mysqlcheck -u root --password=$MYSQL_ROOT_PASSWORD --auto-repair $DATABASE
7160
+else
7161
+    # No errors were found, so exit
7162
+    rm -f $TEMPFILE
7163
+    exit 0
7164
+fi
7165
+rm -f $TEMPFILE
7166
+
7167
+# Check the database again
7168
+mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
7169
+
7170
+# If it still contains errors then restore from backup
7171
+if grep -q "Error" "$TEMPFILE"; then
7172
+    mysql -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE -o < /var/backups/$DATABASE_daily.sql
7173
+
7174
+    # Send a warning email
7175
+    echo "$DATABASE database corruption within could not be repaired. Restored from backup." $EMAIL
7176
+    rm -f $TEMPFILE
7177
+
7178
+    exit 1
7179
+fi
7180
+rm -f $TEMPFILE
7181
+
7182
+exit 0
7183
+#+END_SRC
7184
+
7185
+Save and exit.
7186
+
7187
+#+BEGIN_SRC: bash
7188
+chmod 600 /usr/bin/repairdatabase
7189
+editor /etc/cron.hourly/repair
7190
+#+END_SRC
7191
+
7192
+Add the following. If you're using Red Matrix then uncomment that line.
7193
+
7194
+#+BEGIN_SRC: bash
7195
+#!/bin/bash
7196
+
7197
+repairdatabase friendica
7198
+#repairdatabase redmatrix
7199
+repairdatabase roundcubemail
7200
+#+END_SRC
7201
+
7202
+Save and exit.
7203
+
7204
+#+BEGIN_SRC: bash
7205
+chmod +x /etc/cron.hourly/repair
7206
+#+END_SRC
7207
+
7127 7208
 ** Install Tripwire
7128 7209
 
7129 7210
 #+BEGIN_VERSE