Adding app to test recommended way for backup/restore

This commit is contained in:
Alexandre Aubin 2017-04-28 17:46:46 +02:00
parent 21b2e84511
commit 59cd29633b
8 changed files with 158 additions and 0 deletions

View file

@ -0,0 +1,5 @@
<html>
<body>
This is a dummy app to test the legacy backup app
</body>
</html>

View file

@ -0,0 +1,3 @@
location PATHTOCHANGE {
alias /var/www/FOLDER;
}

View file

@ -0,0 +1,36 @@
{
"name": "Backup (recommended-way) Test App",
"id": "backup_recommended_app",
"description": {
"en": "App to test the 'recommanded' 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": "/"
}
]
}
}

View file

@ -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)
# Backup the app files
#sudo mkdir -p "${backup_dir}/var/www"
ynh_backup /var/www/$app
# Backup the conf files
#sudo mkdir -p "${backup_dir}/conf"
ynh_backup /etc/nginx/conf.d/$domain.d/$app.conf
# Backup the custom file to a different location
ynh_backup /etc/importantfile /etc/yoloswag
# 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"

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,31 @@
#!/bin/bash
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
ynh_restore_file /var/www/$app
# Restore nginx conf
ynh_restore_file /etc/nginx/conf.d/$domain.d/$app.conf
# Restore custom file (with different source/destinations)
ynh_restore_file /etc/yoloswag /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"
# Reload/reconfigure services
sudo service nginx reload
sudo yunohost app ssowatconf

View file

@ -0,0 +1 @@
Cats are cute