瀏覽代碼

Improved Friendica backup

Bob Mottram 11 年之前
父節點
當前提交
b386f92e86
共有 1 個文件被更改,包括 39 次插入26 次删除
  1. 39
    26
      beaglebone.txt

+ 39
- 26
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, replacing /myusername@mydomainname.com/ with your email address.
4229
+Enter the following, replacing /myusername@mydomainname.com/ with your email address and the mysql root password as appropriate.
4230
 
4230
 
4231
 #+BEGIN_SRC: bash
4231
 #+BEGIN_SRC: bash
4232
 #!/bin/sh
4232
 #!/bin/sh
4242
 # Save to a temporary file first so that it can be checked for non-zero size
4242
 # Save to a temporary file first so that it can be checked for non-zero size
4243
 TEMPFILE=/tmp/friendicared.sql
4243
 TEMPFILE=/tmp/friendicared.sql
4244
 
4244
 
4245
-# Backup the database
4245
+# Backup the Friendica database
4246
+DAILYFILE=/var/backups/friendica_daily.sql
4246
 mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
4247
 mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
4247
 FILESIZE=$(stat -c%s $TEMPFILE)
4248
 FILESIZE=$(stat -c%s $TEMPFILE)
4248
 if [ "$FILESIZE" -eq "0" ]; then
4249
 if [ "$FILESIZE" -eq "0" ]; then
4249
-    # restart the web server
4250
-    service apache2 start
4250
+    if [ -f $DAILYFILE ]; then
4251
+        cp $DAILYFILE $TEMPFILE
4251
 
4252
 
4252
-	# Send a warning email
4253
-	echo "Unable to create a backup of the Friendica database" | mail -s "Friendica backup" $EMAIL
4253
+        # try to restore yesterday's database
4254
+        mysql -D friendica -o < $DAILYFILE
4254
 
4255
 
4255
-    exit 1
4256
+        # Send a warning email
4257
+        echo "Unable to create a backup of the Friendica database. Attempted to restore from yesterday's backup." | mail -s "Friendica backup" $EMAIL
4258
+	else
4259
+        # Send a warning email
4260
+        echo "Unable to create a backup of the Friendica database." | mail -s "Friendica backup" $EMAIL
4261
+    fi
4262
+else
4263
+    chmod 600 $TEMPFILE
4264
+    mv $TEMPFILE $DAILYFILE
4265
+
4266
+    # Make the backup readable only by root
4267
+    chmod 600 $DAILYFILE
4256
 fi
4268
 fi
4257
 
4269
 
4258
-chmod 600 $TEMPFILE
4259
-mv $TEMPFILE /var/backups/friendica_daily.sql
4260
 
4270
 
4261
-# Make the backup readable only by root
4262
-chmod 600 /var/backups/friendica_daily.sql
4263
-
4264
-# Backup the database
4271
+# Backup the Red Matrix database
4272
+DAILYFILE=/var/backups/redmatrix_daily.sql
4265
 #mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
4273
 #mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
4266
-
4267
 #FILESIZE=$(stat -c%s $TEMPFILE)
4274
 #FILESIZE=$(stat -c%s $TEMPFILE)
4268
 #if [ "$FILESIZE" -eq "0" ]; then
4275
 #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
+#    if [ -f $DAILYFILE ]; then
4277
+#        cp $DAILYFILE $TEMPFILE
4278
+
4279
+#        # try to restore yesterday's database
4280
+#        mysql -D redmatrix -o < $DAILYFILE
4281
+
4282
+#        # Send a warning email
4283
+#        echo "Unable to create a backup of the Red Matrix database. Attempted to restore from yesterday's backup" | mail -s "Red Matrix backup" $EMAIL
4284
+#	else
4285
+#        # Send a warning email
4286
+#        echo "Unable to create a backup of the Red Matrix database." | mail -s "Red Matrix backup" $EMAIL
4287
+#    fi
4288
+#else
4289
+#    chmod 600 $TEMPFILE
4290
+#    mv $TEMPFILE $DAILYFILE
4291
+
4292
+#    # Make the backup readable only by root
4293
+#    chmod 600 $DAILYFILE
4276
 #fi
4294
 #fi
4277
 
4295
 
4278
-#chmod 600 $TEMPFILE
4279
-#mv $TEMPFILE /var/backups/redmatrix_daily.sql
4280
-
4281
-# Make the backup readable only by root
4282
-#chmod 600 /var/backups/redmatrix_daily.sql
4283
 
4296
 
4284
 # restart the web server
4297
 # restart the web server
4285
 service apache2 start
4298
 service apache2 start