gogs backup

This commit is contained in:
Bob Mottram 2015-03-18 19:33:43 +00:00
parent 7a42b63c20
commit e22426569a
1 changed files with 44 additions and 1 deletions

View File

@ -1728,6 +1728,49 @@ function create_backup_script {
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME
fi
if grep -Fxq "install_gogs" $COMPLETION_FILE; then
BACKUP_INCLUDES_DATABASES="yes"
echo "if [ ! -d $USB_MOUNT/backup/gogs ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " mkdir -p $USB_MOUNT/backup/gogs" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "if [ ! -d $USB_MOUNT/backup/gogs2 ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " mkdir -p $USB_MOUNT/backup/gogs2" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "if [ ! -d $USB_MOUNT/backup/gogsdata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " mkdir -p $USB_MOUNT/backup/gogsdata" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "if [ ! -d /root/tempgogsdata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " mkdir -p /root/tempgogsdata" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'mysqldump --password=$DATABASE_PASSWORD gogs > /root/tempgogsdata/gogs.sql' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "if [ ! -s /root/tempgogsdata/gogs.sql ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "Gogs database could not be saved"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " echo 'No MariaDB password was given'" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " fi" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' shred -zu /root/tempgogsdata/*' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf /root/tempgogsdata' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' exit 377' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "fi" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "rsyncrypto -v -r /root/tempgogsdata $USB_MOUNT/backup/gogsdata $USB_MOUNT/backup/gogsdata.keys $BACKUP_CERTIFICATE" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' exit 188' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'shred -zu /root/tempgogsdata/*' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'rm -rf /root/tempgogsdata' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'echo "Obtaining Gogs data backup"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "rsyncrypto -v -r /etc/gocode/src/github.com/gogits/gogs $USB_MOUNT/backup/gogs $USB_MOUNT/backup/gogs.keys $BACKUP_CERTIFICATE" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' exit 632' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME
fi
if grep -Fxq "install_wiki" $COMPLETION_FILE; then
echo "if [ ! -d $USB_MOUNT/backup/wiki ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo " mkdir -p $USB_MOUNT/backup/wiki" >> /usr/bin/$BACKUP_SCRIPT_NAME
@ -6549,7 +6592,7 @@ quit" > $INSTALL_DIR/batch.sql
chmod 600 $INSTALL_DIR/batch.sql
mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
shred -zu $INSTALL_DIR/batch.sql
echo '#! /bin/sh' > /etc/init.d/gogs
echo '### BEGIN INIT INFO' >> /etc/init.d/gogs
echo '# Provides: gogs' >> /etc/init.d/gogs