diff --git a/backup_legacy_app_ynh/conf/index.html b/backup_legacy_app_ynh/conf/index.html new file mode 100644 index 0000000..7c87ff6 --- /dev/null +++ b/backup_legacy_app_ynh/conf/index.html @@ -0,0 +1,5 @@ + + + This is a dummy app to test the legacy backup app + + diff --git a/backup_legacy_app_ynh/conf/nginx.conf b/backup_legacy_app_ynh/conf/nginx.conf new file mode 100644 index 0000000..7242d79 --- /dev/null +++ b/backup_legacy_app_ynh/conf/nginx.conf @@ -0,0 +1,3 @@ +location PATHTOCHANGE { + alias /var/www/FOLDER; +} diff --git a/backup_legacy_app_ynh/manifest.json b/backup_legacy_app_ynh/manifest.json new file mode 100644 index 0000000..832cea9 --- /dev/null +++ b/backup_legacy_app_ynh/manifest.json @@ -0,0 +1,36 @@ +{ + "name": "Backup (legacy-way) Test App", + "id": "backup_legacy_app", + "description": { + "en": "App to test the 'legacy' ways of doing backups" + }, + "license": "GPL-3+", + "maintainer": { + "name": "Aleks", + "email": "alex.aubin@mailoo.org", + "url": "https://github.com/alexAubin/" + }, + "requirements": { + "yunohost": ">> 2.5.0" + }, + "multi_instance": false, + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path" + }, + "example": "/", + "default": "/" + } + ] + } +} diff --git a/backup_legacy_app_ynh/scripts/backup b/backup_legacy_app_ynh/scripts/backup new file mode 100644 index 0000000..9b25a3a --- /dev/null +++ b/backup_legacy_app_ynh/scripts/backup @@ -0,0 +1,28 @@ +#!/bin/bash +set -eu + +# Source app helpers +source /usr/share/yunohost/helpers + +# Retrieve parameters + +# Backup directory (location dedicated to the app) +backup_dir=$1 +# App instance name +app=$2 +domain=$(ynh_app_setting_get $app domain) + +# Copy the app files (explicitly specifying the backup dir) +sudo mkdir -p "${backup_dir}/var/www" +ynh_backup /var/www/$app "${backup_dir}/var/www/$app" + +# Copy the conf files (without explicitly specifying the backup dir) +sudo mkdir -p "${backup_dir}/conf" +ynh_backup /etc/nginx/conf.d/$domain.d/$app.conf "conf/nginx.conf" + +# Copy the custom file as if it was a big file (1 at the end) +ynh_backup /etc/importantfile "${backup_dir}/importantfile" 1 + +# Backup db +root_pwd=$(sudo cat /etc/yunohost/mysql) +sudo su -c "mysqldump -u root -p$root_pwd --no-create-db $app > ${backup_dir}/db.sql" diff --git a/backup_legacy_app_ynh/scripts/install b/backup_legacy_app_ynh/scripts/install new file mode 100644 index 0000000..616fec6 --- /dev/null +++ b/backup_legacy_app_ynh/scripts/install @@ -0,0 +1,35 @@ +set -eux + +# Retrieve arguments +app=$YNH_APP_INSTANCE_NAME +number=$YNH_APP_INSTANCE_NUMBER +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH + +# Source app helpers +source /usr/share/yunohost/helpers + +# Check domain/path availability +sudo yunohost app checkurl $domain/$path -a $app + +# Add config for nginx +sudo sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf +sudo sed -i "s@FOLDER@$app/@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf + +# Make directory for app web data +sudo mkdir -p /var/www/$app +sudo cp ../conf/index.html /var/www/$app + +# Create a dummy mysql db +db_user=$app +db_pwd="yoloswag42" +ynh_mysql_create_db "$db_user" "$db_user" $db_pwd +ynh_app_setting_set $app mysqlpwd $db_pwd + +# Other custom stuff +sudo cp ../sources/importantfile /etc/ + +# Reload Nginx and regenerate SSOwat conf +sudo service nginx reload +#sudo yunohost app ssowatconf diff --git a/backup_legacy_app_ynh/scripts/remove b/backup_legacy_app_ynh/scripts/remove new file mode 100644 index 0000000..75fd1c0 --- /dev/null +++ b/backup_legacy_app_ynh/scripts/remove @@ -0,0 +1,19 @@ +set -eux + +# Source app helpers +source /usr/share/yunohost/helpers + +# Recover arguments +app=$YNH_APP_INSTANCE_NAME +domain=$(sudo yunohost app setting $app domain) + +sudo rm -rf /var/www/$app +sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +sudo rm -f /etc/importantfile + +db_user=$app +ynh_mysql_drop_db $db_user +ynh_mysql_drop_user $db_user + +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/backup_legacy_app_ynh/scripts/restore b/backup_legacy_app_ynh/scripts/restore new file mode 100644 index 0000000..d35873c --- /dev/null +++ b/backup_legacy_app_ynh/scripts/restore @@ -0,0 +1,37 @@ +#!/bin/bash + +# No set -eu for this particular app restore script (see comment near the end) +#set -eu + +# Source app helpers +source /usr/share/yunohost/helpers + +restore_dir=$1 +app=$2 + +# Get old parameter of the app +domain=$(ynh_app_setting_get $app domain) +path=$(ynh_app_setting_get $app path) + +# Restore www directory +sudo cp -a "${restore_dir}/var/www/$app" /var/www/$app + +# Restore nginx conf +nginx_conf=/etc/nginx/conf.d/$domain.d/$app.conf +sudo cp -a "${restore_dir}/conf/nginx.conf" $nginx_conf + +# Restore custom file +sudo cp -a "${restore_dir}/importantfile" /etc/importantfile + +# Restore the database +db_user=$app +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +ynh_mysql_create_db $db_user $db_user $db_pwd +sudo su -c "mysql -u $db_user -p$db_pwd $app < ${restore_dir}/db.sql" +# Some scripts wanted to delete the db.sql... This won't make the script crash +# even if restore_dir is in read-only as long as there's no set -eu activated... +sudo rm ${restore_dir}/db.sql + +# Reload/reconfigure services +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/backup_legacy_app_ynh/sources/importantfile b/backup_legacy_app_ynh/sources/importantfile new file mode 100644 index 0000000..2fa8b7e --- /dev/null +++ b/backup_legacy_app_ynh/sources/importantfile @@ -0,0 +1 @@ +Cats are cute