Commit ef695e0a authored by Spctrl's avatar Spctrl

backup restore

parent ecaf23b1
......@@ -5,7 +5,7 @@
"description": {
"en": "Pleroma package for YunoHost application."
},
"version": "0.0.1",
"version": "0.0.1~ynh1",
"url": "",
"license": "free",
"maintainer": {
......
......@@ -18,11 +18,8 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_die "Backup isn't implemented yet"
: <<'COMMENT'
#=================================================
# LOAD SETTINGS
#=================================================
......@@ -35,32 +32,28 @@ db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$app-cache.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
mkdir --parents $final_path/backup
chown postgres $final_path/backup
su - postgres -c "pg_dump $db_name > $final_path/backup/$db_name.sql"
#=================================================
# BACKUP THE MYSQL DATABASE
# BACKUP THE APP MAIN DIR
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
ynh_backup "$final_path"
#=================================================
#================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
......@@ -71,12 +64,5 @@ ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP THE CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app"
COMMENT
systemd_location=/usr/lib/systemd/system
ynh_backup "$systemd_location/$app.service"
#!/bin/bash
#=================================================
# GENERIC START
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
......@@ -27,6 +28,8 @@ admin_mail=$YNH_APP_ARG_ADMIN_MAIL
email=$admin_mail
is_public=1 # TODO make this a question. Non-public means no new subscriptions.
app=$YNH_APP_INSTANCE_NAME
db_name="pleroma_dev" # Change this to $app when DB-name can be easily chosen
port=$(ynh_find_port 4000)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
......@@ -51,16 +54,15 @@ ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app db_name $db_name
ynh_app_setting_set $app port $port
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND OPEN THE PORT
# OPEN THE PORT
#=================================================
# TODO This is prob not really needed
# Find a free port
port=$(ynh_find_port 4000)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
......@@ -110,10 +112,8 @@ cat $final_path/pleroma/config/setup_db.psql | grep "<%= .* %>" && ynh_die "$fin
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
# Fail installation if database already exists. Always return true, otherwise the installation failes regardless
# Instead maybe use
## ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -ws pleroma_dev || echo 'The database pleroma_dev already exists'
su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -ws pleroma_dev && ynh_die 'The database pleroma_dev already exists' || true
# Fail installation if database already exists.
! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -ws pleroma_dev || ynh_die 'The database pleroma_dev already exists'
chmod +x $final_path/pleroma/config/setup_db.psql
su - postgres -c "psql -f $final_path/pleroma/config/setup_db.psql"
......@@ -142,7 +142,7 @@ su - $app -c "cd $final_path/pleroma;mix local.rebar --force;mix local.hex --for
#=================================================
cp -rf "../conf/nginx.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
cp -rf "../conf/pleroma_cache.conf" "/etc/nginx/conf.d/pleroma_cache.conf"
cp -rf "../conf/pleroma_cache.conf" "/etc/nginx/conf.d/$app-cache.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
......@@ -178,7 +178,7 @@ yunohost service add postgresql
ynh_app_setting_set $app skipped_uris "/"
#=================================================
# RELOAD NGINX
# FINALIZATION
#=================================================
systemctl reload nginx
......@@ -187,7 +187,4 @@ systemctl reload nginx
sleep 10
systemctl restart $app
#=================================================
# VICTORY MESSAGE
#=================================================
echo "If you're not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!"
......@@ -17,6 +17,7 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
#=================================================
# STANDARD REMOVE
......@@ -46,7 +47,7 @@ fi
# REMOVE THE DATABASE
#=================================================
# I wrote this in a script an ran that, but it failed and I don't know why, so I 'fixed' it like this.
# TODO: I wrote this in a script an ran that, but it failed and I don't know why, so I 'fixed' it like this.
su - postgres -c "
touch drop_$app_db.psql
> drop_$app_db.psql
......@@ -75,7 +76,7 @@ ynh_secure_remove "$final_path"
#=================================================
ynh_remove_nginx_config
rm /etc/nginx/conf.d/pleroma_cache.conf
rm /etc/nginx/conf.d/$app-cache.conf
#=================================================
# REMOVE LOGROTATE CONFIGURATION
......
#!/bin/bash
# yunohost backup --debug restore 20180908-191040
#=================================================
# GENERIC START
#=================================================
......@@ -21,98 +22,107 @@ source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_die "Restore isn't implemented yet"
: <<'COMMENT'
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get $app domain)
#db_name=$(ynh_app_setting_get $app db_name)
db_name=pleroma_dev
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
ynh_webpath_available $domain / \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
# STANDARD MODIFICATIONS
#=================================================
# RESTORE THE NGINX CONFIGURATION
# FIND OPEN THE PORT
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# TODO This is prob not really needed
# Find a free port
port=$(ynh_find_port 4000)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# RESTORE THE APP MAIN DIR
# INSTALL DEPENDENCIES
#=================================================
ynh_restore_file "$final_path"
if ! [ -e /etc/apt/sources.list.d/erlang-solutions.list ]
then
mkdir --parents /etc/apt/sources.list.d/
touch /etc/apt/sources.list.d/erlang-solutions.list
echo "deb https://packages.erlang-solutions.com/debian stretch contrib" > /etc/apt/sources.list.d/erlang-solutions.list
wget https://packages.erlang-solutions.com/debian/erlang_solutions.asc
apt-key add erlang_solutions.asc
rm erlang_solutions.asc
fi
apt-get update
ynh_install_app_dependencies git build-essential postgresql-9.6 postgresql-contrib-9.6 elixir erlang-dev erlang-parsetools erlang-xmerl erlang-tools esl-erlang
#=================================================
# RESTORE THE MYSQL DATABASE
# RECREATE DEDICATED USER
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
mkdir --parents $final_path
useradd $app --home-dir=$final_path
#=================================================
# RECREATE THE DEDICATED USER
# RESTORE THE APP MAIN DIR
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
ynh_restore_file "$final_path"
chown -R $app: $final_path
#=================================================
# RESTORE USER RIGHTS
# RESTORE THE POSTGRESQL DATABASE
#=================================================
# Restore permissions on app files
chown -R root: $final_path
! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -ws pleroma_dev || ynh_die "The database $db_name already exists"
chown postgres $final_path/backup
su - postgres -c "psql -c \"create database $db_name\""
su - postgres -c "psql $db_name < $final_path/backup/$db_name.sql"
rm -r $final_path/backup
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
# SPECIFIC SETUP
#=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
su - $app -c "cd $final_path/pleroma;mix local.rebar --force;mix local.hex --force;MIX_ENV=prod mix ecto.migrate;"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies deb1 deb2
# STANDARD RESTORATION STEPS
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# RESTORE THE NGINX CONFIGURATION
#=================================================
yunohost service add $app --log "/var/log/$app/APP.log"
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file "/etc/nginx/conf.d/$app-cache.conf"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
systemd_location=/usr/lib/systemd/system
mkdir --parents $systemd_location
ynh_restore_file "$systemd_location/$app.service"
systemctl daemon-reload
systemctl enable --now $app.service
#=================================================
# RESTORE THE CRON FILE
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
ynh_restore_file "/etc/cron.d/$app"
yunohost service add $app --log "/var/log/$app/APP.log"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
......@@ -121,11 +131,21 @@ ynh_restore_file "/etc/cron.d/$app"
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
# SETUP SSOWAT
#=================================================
# Skip ynh login for accessing the application
ynh_app_setting_set $app skipped_uris "/"
#=================================================
# RELOAD NGINX AND PHP-FPM
# FINALIZATION
#=================================================
systemctl reload php5-fpm
systemctl reload nginx
COMMENT
# Restart 'cause I always have an internal server error the first time.
sleep 10
systemctl restart $app
echo "If you're not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment