Improve the Friendica backup script to handle database errors
This commit is contained in:
parent
e6325d597b
commit
b1bf0b8a7e
|
@ -4226,31 +4226,65 @@ Make sure that the database gets backed up. By using cron if anything goes wron
|
|||
editor /etc/cron.daily/backup
|
||||
#+END_SRC
|
||||
|
||||
Enter the following
|
||||
Enter the following, replacing /myusername@mydomainname.com/ with your email address.
|
||||
|
||||
#+BEGIN_SRC: bash
|
||||
#!/bin/sh
|
||||
|
||||
# stop the web server to avoid any changes to the databases during backup
|
||||
service apache2 stop
|
||||
EMAIL=myusername@mydomainname.com
|
||||
|
||||
MYSQL_PASSWORD=<mysql root password>
|
||||
umask 0077
|
||||
|
||||
# stop the web server to avoid any changes to the databases during backup
|
||||
service apache2 stop
|
||||
|
||||
# Save to a temporary file first so that it can be checked for non-zero size
|
||||
TEMPFILE=/tmp/friendicared.sql
|
||||
|
||||
# Backup the database
|
||||
mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
|
||||
mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
|
||||
FILESIZE=$(stat -c%s $TEMPFILE)
|
||||
if [ "$FILESIZE" -eq "0" ]; then
|
||||
# restart the web server
|
||||
service apache2 start
|
||||
|
||||
# Send a warning email
|
||||
echo "Unable to create a backup of the Friendica database" | mail -s "Friendica backup" $EMAIL
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chmod 600 $TEMPFILE
|
||||
mv $TEMPFILE /var/backups/friendica_daily.sql
|
||||
|
||||
# Make the backup readable only by root
|
||||
chmod 600 /var/backups/friendica_daily.sql
|
||||
|
||||
# Backup the database
|
||||
#mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_daily.sql
|
||||
#mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
|
||||
|
||||
FILESIZE=$(stat -c%s $TEMPFILE)
|
||||
if [ "$FILESIZE" -eq "0" ]; then
|
||||
# restart the web server
|
||||
service apache2 start
|
||||
|
||||
# Send a warning email
|
||||
echo "Unable to create a backup of the Red Matrix database" | mail -s "Red Matrix backup" $EMAIL
|
||||
|
||||
exit 2
|
||||
fi
|
||||
|
||||
chmod 600 $TEMPFILE
|
||||
mv $TEMPFILE /var/backups/redmatrix_daily.sql
|
||||
|
||||
# Make the backup readable only by root
|
||||
#chmod 600 /var/backups/redmatrix_daily.sql
|
||||
|
||||
# restart the web server
|
||||
service apache2 start
|
||||
|
||||
exit 0
|
||||
#+END_SRC
|
||||
|
||||
Save and exit.
|
||||
|
|
Loading…
Reference in New Issue