瀏覽代碼

Improve the Friendica backup script to handle database errors

Bob Mottram 10 年之前
父節點
當前提交
b1bf0b8a7e
共有 1 個檔案被更改,包括 39 行新增5 行删除
  1. 39
    5
      beaglebone.txt

+ 39
- 5
beaglebone.txt 查看文件

4226
 editor /etc/cron.daily/backup
4226
 editor /etc/cron.daily/backup
4227
 #+END_SRC
4227
 #+END_SRC
4228
 
4228
 
4229
-Enter the following
4229
+Enter the following, replacing /myusername@mydomainname.com/ with your email address.
4230
 
4230
 
4231
 #+BEGIN_SRC: bash
4231
 #+BEGIN_SRC: bash
4232
 #!/bin/sh
4232
 #!/bin/sh
4233
 
4233
 
4234
-# stop the web server to avoid any changes to the databases during backup
4235
-service apache2 stop
4234
+EMAIL=myusername@mydomainname.com
4236
 
4235
 
4237
 MYSQL_PASSWORD=<mysql root password>
4236
 MYSQL_PASSWORD=<mysql root password>
4238
 umask 0077
4237
 umask 0077
4239
 
4238
 
4239
+# stop the web server to avoid any changes to the databases during backup
4240
+service apache2 stop
4241
+
4242
+# Save to a temporary file first so that it can be checked for non-zero size
4243
+TEMPFILE=/tmp/friendicared.sql
4244
+
4240
 # Backup the database
4245
 # Backup the database
4241
-mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
4246
+mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
4247
+FILESIZE=$(stat -c%s $TEMPFILE)
4248
+if [ "$FILESIZE" -eq "0" ]; then
4249
+    # restart the web server
4250
+    service apache2 start
4251
+
4252
+	# Send a warning email
4253
+	echo "Unable to create a backup of the Friendica database" | mail -s "Friendica backup" $EMAIL
4254
+
4255
+    exit 1
4256
+fi
4257
+
4258
+chmod 600 $TEMPFILE
4259
+mv $TEMPFILE /var/backups/friendica_daily.sql
4242
 
4260
 
4243
 # Make the backup readable only by root
4261
 # Make the backup readable only by root
4244
 chmod 600 /var/backups/friendica_daily.sql
4262
 chmod 600 /var/backups/friendica_daily.sql
4245
 
4263
 
4246
 # Backup the database
4264
 # Backup the database
4247
-#mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_daily.sql
4265
+#mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
4266
+
4267
+FILESIZE=$(stat -c%s $TEMPFILE)
4268
+if [ "$FILESIZE" -eq "0" ]; then
4269
+    # restart the web server
4270
+    service apache2 start
4271
+
4272
+	# Send a warning email
4273
+	echo "Unable to create a backup of the Red Matrix database" | mail -s "Red Matrix backup" $EMAIL
4274
+
4275
+    exit 2
4276
+fi
4277
+
4278
+chmod 600 $TEMPFILE
4279
+mv $TEMPFILE /var/backups/redmatrix_daily.sql
4248
 
4280
 
4249
 # Make the backup readable only by root
4281
 # Make the backup readable only by root
4250
 #chmod 600 /var/backups/redmatrix_daily.sql
4282
 #chmod 600 /var/backups/redmatrix_daily.sql
4251
 
4283
 
4252
 # restart the web server
4284
 # restart the web server
4253
 service apache2 start
4285
 service apache2 start
4286
+
4287
+exit 0
4254
 #+END_SRC
4288
 #+END_SRC
4255
 
4289
 
4256
 Save and exit.
4290
 Save and exit.