mirror of
https://github.com/YunoHost-Apps/abantecart_ynh.git
synced 2024-09-03 18:06:16 +02:00
Creation of backup and restore scripts
This commit is contained in:
parent
512f22346b
commit
e85b83bd94
4 changed files with 78 additions and 7 deletions
31
scripts/backup
Normal file
31
scripts/backup
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
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 db_name)
|
||||
|
||||
# The parameter $1 is the backup directory location
|
||||
# which will be compressed afterward
|
||||
|
||||
# Backup sources & data
|
||||
ynh_backup "$final_path" "sources"
|
||||
|
||||
# Copy Nginx and YunoHost parameters to make the script "standalone"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf"
|
||||
|
||||
ynh_backup "/etc/yunohost/apps/$app/" "yunohost"
|
||||
|
||||
# Copy dedicated php-fpm process to backup folder
|
||||
ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "php-fpm.conf"
|
||||
|
||||
# Backup db
|
||||
root_pwd=$(sudo cat /etc/yunohost/mysql)
|
||||
sudo mysqldump -u root -p$root_pwd --no-create-db $db_user --result-file="db.sql"
|
||||
ynh_backup "db.sql" "backupdb.sql"
|
||||
|
|
@ -52,10 +52,6 @@ ynh_mysql_create_db "$db_name" "$db_user" "$db_pass"
|
|||
ynh_app_setting_set "$app" db_name "$db_name"
|
||||
ynh_app_setting_set "$app" db_pass "$db_pass"
|
||||
|
||||
# Store the database access
|
||||
echo -e "# MySQL Database"
|
||||
|
||||
|
||||
# Remove trailing "/" for next commands
|
||||
if [[ ! "$path" == "/" ]]; then
|
||||
path=${path%/}
|
||||
|
@ -63,6 +59,7 @@ fi
|
|||
|
||||
# Copy files to the right place
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set "$app" final_path "$final_path"
|
||||
|
||||
# We download the sources and check the md5sum
|
||||
SFILE=`sudo cat ../sources/source_file`;
|
||||
|
|
46
scripts/restore
Normal file
46
scripts/restore
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path=$(ynh_app_setting_get $app path)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pass=$(ynh_app_setting_get $app db_pass)
|
||||
|
||||
if [ -d $final_path ]; then
|
||||
echo "There is already a directory: $final_path " >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Restore Nginx
|
||||
conf=/etc/nginx/conf.d/$domain.d/$app.conf
|
||||
if [ -f $conf ]; then
|
||||
echo "There is already a nginx conf file at this path: $conf " >&2
|
||||
exit 1
|
||||
fi
|
||||
sudo cp -a ./nginx.conf $conf
|
||||
|
||||
# Restore YunoHost parameters
|
||||
sudo cp -a ./yunohost/. /etc/yunohost/apps/$app/
|
||||
|
||||
# Restore sources & data
|
||||
sudo mkdir -p $final_path
|
||||
sudo cp -a ./sources/. $final_path/
|
||||
|
||||
ynh_mysql_create_db $db_name $db_name $db_pass
|
||||
mysql --debug-check -u $db_user -p$db_pwd $db_user < ./backupdb.sql
|
||||
|
||||
# Copy dedicated php-fpm process from backup folder to the right location
|
||||
sudo cp -a ./php-fpm.conf /etc/php5/fpm/pool.d/$app.conf
|
||||
|
||||
# And Reload services
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
|
||||
sudo yunohost app ssowatconf
|
||||
|
|
@ -24,9 +24,6 @@ if [[ ! "$path" == "/" ]]; then
|
|||
path=${path%/}
|
||||
fi
|
||||
|
||||
# Copy files to the right place
|
||||
final_path=/var/www/$app
|
||||
|
||||
# We download the sources and check the md5sum
|
||||
SFILE=`sudo cat ../sources/source_file`;
|
||||
sudo wget -nv -i ../sources/source_url -O ${SFILE}.tar.gz
|
||||
|
|
Loading…
Reference in a new issue