From d16152c9849bdd507123102fd33f72b804e27256 Mon Sep 17 00:00:00 2001 From: opi Date: Sat, 14 May 2016 10:06:20 +0200 Subject: [PATCH] [enh] Add backup & restore script. --- scripts/backup | 25 +++++++++++++++++ scripts/restore | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 scripts/backup create mode 100644 scripts/restore diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..4e16b53 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,25 @@ +#!/bin/bash + +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e + +# Source YNH helpers +. /usr/share/yunohost/helpers + +# Get app instance name +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) + +# Backup directory location for the app from where the script is executed and +# which will be compressed afterward +backup_dir=$YNH_APP_BACKUP_DIR + +# Backup sources & data +ynh_backup "/home/yunohost.transmission" "data" +ynh_backup "/usr/share/transmission" "sources" + +# Copy configuration files +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" +ynh_backup "/etc/transmission-daemon/settings.json" "conf/transmission.json" \ No newline at end of file diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..f081c59 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,75 @@ +#!/bin/bash + +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e + +# Source YNH helpers +. /usr/share/yunohost/helpers + +# Get app instance name +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a $app +if [[ ! $? -eq 0 ]]; then + echo "There is already an app on this URL : $domain$path" | sudo tee /dev/stderr + exit 1 +fi + +sources_path=/usr/share/transmission +if [ -d $sources_path ]; then + echo "There is already a directory: $sources_path " | sudo tee /dev/stderr + exit 1 +fi + +data_path=/home/yunohost.transmission +if [ -d $data_path ]; then + echo "There is already a directory: $data_path " | sudo tee /dev/stderr + exit 1 +fi + +nginx_conf=/etc/nginx/conf.d/$domain.d/$app.conf +if [ -f $nginx_conf ]; then + echo "There is already a nginx conf file at this path: $nginx_conf " | sudo tee /dev/stderr + exit 1 +fi + +app_conf=/etc/transmission-daemon/settings.json +if [ -f $app_conf ]; then + echo "There is already a PHP-FPM conf file at this path: $app_conf " | sudo tee /dev/stderr + exit 1 +fi + +# Open port in firewall +sudo yunohost firewall allow TCP 51413 > /dev/null 2>&1 + +# Install official debian package +sudo apt-get install transmission-daemon -y -qq + +# Make directories and set rights +sudo mkdir -p /home/yunohost.transmission/{progress,completed} +sudo chown -R debian-transmission:www-data /home/yunohost.transmission/ +sudo chown -R debian-transmission:debian-transmission /home/yunohost.transmission/progress +sudo find /home/yunohost.transmission/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done +sudo find /home/yunohost.transmission/ -type d | while read LINE; do sudo chmod 750 "$LINE" ; done + +# Reload transmission service +sudo service transmission-daemon reload + +# Monitor service +sudo yunohost service add transmission-daemon + +# Restore sources & data +sudo cp -a "./sources" $sources_path +sudo cp -a "./data" $data_path + +# Restore conf files +sudo cp -a "./conf/nginx.conf" $nginx_conf +sudo cp -a "./conf/transmission.conf" $app_conf + +# Reload Nginx +sudo service nginx reload