1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/moodle_ynh.git synced 2024-09-03 19:46:23 +02:00

Added backup and restore

This commit is contained in:
anmol26s 2017-12-15 04:23:33 +05:30
parent ff6b923d32
commit 3390389acc
5 changed files with 225 additions and 37 deletions

View file

@ -11,12 +11,12 @@ integrated system to create personalised learning environments.
Moodle is widely used around the world by universities, schools, companies and
all manner of organisations and individuals.
#Installation
# Installation
** After the installation go to your domain https://domain.tld/moodle and create the admin account. **
## To-do
- [X] Install script
- [X] Remove script
- [ ] Upgrade script
- [ ] Backup and Restore scripts
- [X] Backup and Restore scripts(need testing)
- [ ] LDAP integration

View file

@ -33,7 +33,7 @@ ynh_remove_php7 () {
}
# Create a dedicated php-fpm config
# Create a dedicated php-fpm config for php7.1
#
# usage: ynh_add_fpm_config
ynh_add_php7.1-fpm_config () {
@ -58,11 +58,8 @@ ynh_add_php7.1-fpm_config () {
sudo systemctl reload php7.1-fpm
}
<<<<<<< HEAD
# Remove the dedicated php-fpm config for php7.1
=======
# Remove the dedicated php-fpm config
>>>>>>> 4d1446000580d39209c48e91f1e764e3bb677881
#
# usage: ynh_remove_fpm_config
ynh_remove_php7.1-fpm_config () {
@ -70,28 +67,3 @@ ynh_remove_php7.1-fpm_config () {
ynh_secure_remove "/etc/php/7.1/fpm/conf.d/20-$app.ini" 2>&1
sudo systemctl reload php7.1-fpm
}
<<<<<<< HEAD
ynh_install_php7 () {
ynh_package_update
ynh_package_install apt-transport-https --no-install-recommends
wget -q -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.list
ynh_package_update
ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-soap php7.1-pgsql
sudo update-alternatives --install /usr/bin/php php /usr/bin/php5 70
sudo systemctl reload php7.1-fpm
}
ynh_remove_php7 () {
sudo rm -f /etc/apt/sources.list.d/php7.list
sudo apt-key del 4096R/89DF5277
sudo apt-key del 2048R/11A06851
ynh_remove_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-soap php7.1-pgsql
}
=======
>>>>>>> 4d1446000580d39209c48e91f1e764e3bb677881

78
scripts/backup Normal file
View file

@ -0,0 +1,78 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source psql.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app psql_db)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
# BACKUP APP home directory
ynh_backup "/home/yunohost.app/$app"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup "/etc/php/7.1/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.1/fpm/conf.d/20-$app.ini"
#=================================================
# BACKUP THE PSQL DATABASE
#=================================================
ynh_psql_dump_db "$db_name" > db.sql
ynh_backup "db.sql"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP THE CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app"

View file

@ -33,7 +33,9 @@ ynh_psql_execute_as_root () {
# | arg: file - the file containing SQL commands
# | arg: db - the database to connect to
ynh_psql_execute_file_as_root() {
ynh_die "ynh_psql_execute_file_as_root is not yet implemented"
file="$1"
db="$2"
su -c "psql $db" postgres < "$file"
}
# Create a database and grant optionnaly privilegies to a user
@ -70,7 +72,8 @@ ynh_psql_drop_db() {
# | arg: db - the database name to dump
# | ret: the psqldump output
ynh_psql_dump_db() {
ynh_die "ynh_psql_dump_db is not yet implemented"
db="$1"
su --command="pg_dump \"${db}\"" postgres
}
@ -97,13 +100,25 @@ ynh_psql_test_if_first_run() {
then
echo "PostgreSQL is already installed, no need to create master password"
else
local pgsql=$(ynh_string_random)
pgsql=$(ynh_string_random)
pg_hba=""
echo "$pgsql" >> /etc/yunohost/psql
if [ -e /etc/postgresql/9.4/ ]
then
pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
elif [ -e /etc/postgresql/9.6/ ]
then
pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
else
ynh_die "postgresql shoud be 9.4 or 9.6"
fi
systemctl start postgresql
sudo -u postgres psql -c"ALTER user postgres WITH PASSWORD '${pgsql}'"
su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres
# we can't use peer since YunoHost create users with nologin
sed -i '/local\s*all\s*all\s*peer/i \
local all all password' /etc/postgresql/9.4/main/pg_hba.conf
local all all password' "$pg_hba"
systemctl enable postgresql
systemctl reload postgresql
fi

123
scripts/restore Normal file
View file

@ -0,0 +1,123 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source psql.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# 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 psql_db)
db_pwd=$(ynh_app_setting_get $app psqlpwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
var_root=/home/yunohost.app/$app
ynh_restore_file "$final_path"
ynh_restore_file "$var_root"
#=================================================
# RESTORE THE psql DATABASE
#=================================================
ynh_psql_test_if_first_run
ynh_psql_create_user $app $db_pwd
ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
ynh_psql_execute_file_as_root ./db.sql "$db_name"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
chown -R root: $final_path/config.php
mkdir -p $var_root
chown -R $app:root $var_root
chmod -R 700 $var_root
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php/7.1/pool.d/$app.conf"
ynh_restore_file "/etc/php/7.1/conf.d/20-$app.ini"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_php7
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file "/etc/cron.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload php7.1-fpm
systemctl reload nginx