mirror of
https://github.com/YunoHost/test_apps.git
synced 2024-09-03 20:06:29 +02:00
Adding first app for backup test
This commit is contained in:
parent
3f7439f58e
commit
21b2e84511
8 changed files with 164 additions and 0 deletions
5
backup_legacy_app_ynh/conf/index.html
Normal file
5
backup_legacy_app_ynh/conf/index.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This is a dummy app to test the legacy backup app
|
||||||
|
</body>
|
||||||
|
</html>
|
3
backup_legacy_app_ynh/conf/nginx.conf
Normal file
3
backup_legacy_app_ynh/conf/nginx.conf
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
location PATHTOCHANGE {
|
||||||
|
alias /var/www/FOLDER;
|
||||||
|
}
|
36
backup_legacy_app_ynh/manifest.json
Normal file
36
backup_legacy_app_ynh/manifest.json
Normal file
|
@ -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": "/"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
28
backup_legacy_app_ynh/scripts/backup
Normal file
28
backup_legacy_app_ynh/scripts/backup
Normal 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)
|
||||||
|
|
||||||
|
# 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"
|
35
backup_legacy_app_ynh/scripts/install
Normal file
35
backup_legacy_app_ynh/scripts/install
Normal 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
|
19
backup_legacy_app_ynh/scripts/remove
Normal file
19
backup_legacy_app_ynh/scripts/remove
Normal 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
|
37
backup_legacy_app_ynh/scripts/restore
Normal file
37
backup_legacy_app_ynh/scripts/restore
Normal file
|
@ -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
|
1
backup_legacy_app_ynh/sources/importantfile
Normal file
1
backup_legacy_app_ynh/sources/importantfile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Cats are cute
|
Loading…
Add table
Reference in a new issue