From b754b9a9f80ee31782826b693ed4c383ec7ee969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Wed, 4 May 2016 19:32:36 +0200 Subject: [PATCH] [enh] Add backup and restore scripts --- README.md | 6 +++--- scripts/backup | 28 ++++++++++++++++++++++++++ scripts/restore | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 scripts/backup create mode 100644 scripts/restore diff --git a/README.md b/README.md index 51d6db3..3537eb7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Baïkal for YunoHost *This is a work-in-progress package review to update Baikal to 0.4.x and make use of new YunoHost facilities - e.g. helpers - coming with 2.3.x.* -[Baikal](http://baikal-server.com/) is a Cal and CardDAV server, based on +[Baïkal](http://baikal-server.com/) is a Cal and CardDAV server, based on sabre/dav, that includes an administrative interface for easy management. **Shipped version:** 0.4.4 @@ -26,11 +26,11 @@ or from the Web administration: ## TODO * Test the upgrade from the current official package - * Add `backup` and `remove` scripts * Update `config.php` and `config.system.php` at upgrade + * Add a PHP-FPM pool for Baïkal? ## Links ## -**Baikal**: http://baikal-server.com/ +**Baïkal**: http://baikal-server.com/ **YunoHost**: https://yunohost.org/ diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..9a799d2 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,28 @@ +#!/bin/bash + +# Retrieve arguments +backup_dir=$1 +app=$2 + +# Set app specific variables +dbname=$app +dbuser=$app + +# Source app helpers +. /usr/share/yunohost/helpers + +# Retrieve app settings +domain=$(ynh_app_setting_get "$app" domain) +path=$(ynh_app_setting_get "$app" path) +dbpass=$(ynh_app_setting_get "$app" mysqlpwd) + +# Copy the app files +DESTDIR="/var/www/$app" +sudo cp -a "$DESTDIR" ./sources + +# Copy the conf files +sudo cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./nginx.conf +#sudo cp -a "/etc/php5/fpm/pool.d/${app}.conf" ./php-fpm.conf + +# Dump the database +mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..09b9982 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,53 @@ +#!/bin/bash + +# Retrieve arguments +backup_dir=$1 +app=$2 + +# Set app specific variables +dbname=$app +dbuser=$app + +# Source app helpers +. /usr/share/yunohost/helpers + +# Retrieve old app settings +domain=$(ynh_app_setting_get "$app" domain) +path=$(ynh_app_setting_get "$app" path) +dbpass=$(ynh_app_setting_get "$app" mysqlpwd) + +# Check domain/path availability +sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || exit 1 + +# Check destination directory +DESTDIR="/var/www/$app" +[[ -d $DESTDIR ]] && ynh_die \ +"The destination directory '$DESTDIR' already exists.\ + You should safely delete it before restoring this app." + +# Check configuration files +nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" +[[ -f $nginx_conf ]] && ynh_die \ +"The NGINX configuration already exists at '${nginx_conf}'. + You should safely delete it before restoring this app." +#phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +#[[ -f $phpfpm_conf ]] && ynh_die \ +#"The PHP FPM configuration already exists at '${phpfpm_conf}'. +# You should safely delete it before restoring this app." + +# Restore the app files and set permissions +sudo cp -a ./sources "$DESTDIR" +sudo chown -R www-data: "$DESTDIR" + +# Create and restore the database +ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" +ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql + +# Restore configuration files +sudo cp -a ./nginx.conf "$nginx_conf" +#sudo cp -a ./php-fpm.conf "$phpfpm_conf" + +# Reload services +#sudo service php5-fpm restart || true +sudo service nginx reload || true