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