Browse Source

Add backup/restore scripts

Julien VAUBOURG 9 years ago
parent
commit
411c65eb35
4 changed files with 46 additions and 3 deletions
  1. 10 0
      scripts/backup
  2. 13 2
      scripts/install
  3. 22 0
      scripts/restore
  4. 1 1
      scripts/upgrade

+ 10 - 0
scripts/backup

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# The parameter $1 is the backup directory location
+# which will be compressed afterward
+backup_dir="${1}/apps/piratebox"
+mkdir -p "${backup_dir}/"
+
+sudo cp -a /var/www/piratebox/public/uploads/ "${backup_dir}/"
+
+exit 0

+ 13 - 2
scripts/install

@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This is an upgrade?
-upgrade=$([ "$PIRATEBOX_UPGRADE" == 1 ] && echo true || echo false)
+upgrade=$([ "${PIRATEBOX_UPGRADE}" == 1 ] && echo true || echo false)
 
 # Retrieve arguments
 domain=${1}
@@ -54,7 +54,7 @@ if ! $upgrade; then
   if [ ! $? -eq 0 ]; then
     exit 1
   fi
-  
+
   # Save arguments
   sudo yunohost app setting piratebox service_enabled -v 0
   sudo yunohost app setting piratebox opt_domain -v "${opt_domain}"
@@ -67,6 +67,10 @@ if ! $upgrade; then
 
 fi
 
+# Save git commit
+gitcommit=$(git rev-parse HEAD)
+sudo yunohost app setting piratebox gitcommit -v "${gitcommit}"
+
 # Install packages
 packages='php5-fpm iptables libnet-dns-perl git'
 export DEBIAN_FRONTEND=noninteractive
@@ -91,6 +95,10 @@ sudo install -b -o root -g root -m 0644 ../conf/phpfpm_captive-piratebox.conf /e
 # Copy web sources (piratebox)
 sudo git clone https://github.com/jvaubourg/php-piratebox.git /var/www/piratebox/
 
+if [ ! -z "${PIRATEBOX_GITCOMMIT_UPSTREAM}" ]; then
+  git --work-tree /var/www/piratebox/ --git-dir /var/www/piratebox/.git/ reset --hard "${PIRATEBOX_GITCOMMIT_UPSTREAM}"
+fi
+
 sudo chown -R root: /var/www/piratebox/
 sudo chmod -R 0644 /var/www/piratebox/
 sudo find /var/www/piratebox/ -type d -exec chmod +x {} \;
@@ -98,6 +106,9 @@ sudo find /var/www/piratebox/ -type d -exec chmod +x {} \;
 sudo rm -f /var/www/piratebox/config.php
 sudo install -b -o root -g root -m 0644 ../conf/piratebox_config.php.tpl /var/www/piratebox/config.tpl.php
 
+gitcommit_upstream=$(git --work-tree /var/www/piratebox/ --git-dir /var/www/piratebox/.git/ rev-parse HEAD)
+sudo yunohost app setting piratebox gitcommit_upstream -v "${gitcommit_upstream}"
+
 # Copy web sources (admin)
 sudo mkdir -pm 0755 /var/www/piratebox_admin/
 sudo cp -a ../sources/* /var/www/piratebox_admin/

+ 22 - 0
scripts/restore

@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# The parameter $1 is the uncompressed restore directory location
+backup_dir="${1}/apps/piratebox"
+
+mkdir -p /var/www/piratebox/public/
+mv "${backup_dir}/uploads/" /var/www/piratebox/public/
+
+gitcommit=$(sudo yunohost app setting piratebox gitcommit)
+gitcommit_upstream=$(sudo yunohost app setting piratebox gitcommit_upstream)
+tmpdir=$(mktemp -dp /tmp/ piratebox-restore-XXXXX)
+
+git clone https://github.com/labriqueinternet/piratebox_ynh.git "${tmpdir}/"
+git --work-tree "${tmpdir}/" --git-dir "${tmpdir}/.git/" reset --hard "${gitcommit}"
+
+export PIRATEBOX_GITCOMMIT_UPSTREAM=$gitcommit_upstream
+cd "${tmpdir}/scripts/"
+./upgrade 
+
+sudo rm -r "${tmpdir}/"
+
+exit 0

+ 1 - 1
scripts/upgrade

@@ -19,7 +19,7 @@ tmpdir=$(mktemp -dp /tmp/ piratebox-upgrade-XXXXX)
 sudo mv /var/www/piratebox/public/uploads/ "${tmpdir}/"
 
 export PIRATEBOX_UPGRADE=1
-sudo bash /etc/yunohost/apps/piratebox/scripts/remove
+sudo bash /etc/yunohost/apps/piratebox/scripts/remove &> /dev/null
 bash ./install "${domain}" "${path}" "${opt_domain}" "${opt_name}" "${opt_deleting}" "${opt_renaming}" "${opt_chat}"
 
 sudo mv "${tmpdir}/uploads/"* /var/www/piratebox/public/uploads/ 2> /dev/null