1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00

rework backup/restore for yunohost 2.4

This commit is contained in:
mbugeia 2016-02-07 00:56:33 +01:00
parent 37c7f2c4bb
commit 4ca7b7197f
2 changed files with 44 additions and 28 deletions

View file

@ -1,23 +1,27 @@
#!/bin/bash #!/bin/bash
set -e set -e
app=kanboard
# The parameter $1 is the backup directory location # The parameter $1 is the backup directory location dedicated to the app
# which will be compressed afterward BACKUP_DIR=$1
backup_dir=$1/apps/$app
sudo mkdir -p $backup_dir
sudo chown admin: $backup_dir
# Backup sources & data # The parameter $2 is the id of the app instance ex: strut__2
sudo cp -a /var/www/$app/. $backup_dir/sources APP=$2
# retrieve useful param
domain=$(sudo yunohost app setting ${APP} domain)
db_pwd=$(sudo yunohost app setting ${APP} mysqlpwd)
# Backup app files
sudo mkdir -p "${BACKUP_DIR}/www"
sudo cp -a /var/www/${app}/. "${BACKUP_DIR}/www"
# Backup conf files
sudo mkdir -p "${BACKUP_DIR}/conf"
sudo cp -a /etc/nginx/conf.d/$domain.d/${APP}.conf "${BACKUP_DIR}/conf/${APP}.conf"
sudo cp -a /etc/php5/fpm/pool.d/${APP}.conf "${BACKUP_DIR}/conf/php-fpm.conf"
# Backup mysql # Backup mysql
db_pwd=$(sudo yunohost app setting $app mysqlpwd) mysqldump -u ${APP} -p$db_pwd ${APP} | sudo dd of=${BACKUP_DIR}/${APP}.dmp
sudo mysqldump -u $app -p$db_pwd $app > $backup_dir/$app.dmp
# Copy Nginx and YunoHost parameters to make the script "standalone" exit 0
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
domain=$(sudo yunohost app setting $app domain)
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $backup_dir/nginx.conf
sudo cp -a /etc/php5/fpm/pool.d/$app.conf $backup_dir/php-fpm.conf

View file

@ -1,29 +1,41 @@
#!/bin/bash #!/bin/bash
set -e set -e
app=kanboard
# The parameter $1 is the uncompressed restore directory location # The parameter $1 is the backup directory location dedicated to the app
backup_dir=$1/apps/$app BACKUP_DIR=$1
# The parameter $2 is the id of the app instance ex: strut__2
APP=$2
# retrieve useful param
domain=$(sudo yunohost app setting ${APP} domain)
db_pwd=$(sudo yunohost app setting ${APP} mysqlpwd)
path=$(sudo yunohost app setting ${APP} path)
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a ${APP} \
|| (echo "Path not available: $domain$path" && exit 1)
# Restore sources & data # Restore sources & data
sudo cp -a $backup_dir/sources/. /var/www/$app final_path=/var/www/${APP}
sudo mkdir $final_path
sudo cp -a ${BACKUP_DIR}/www/. $final_path
# Restore permissions # Restore permissions
sudo chown -R root:root $final_path sudo chown -R root:root $final_path
sudo chown -R www-data:www-data $final_path/data sudo chown -R www-data:www-data $final_path/data
# Restore mysql dump # Restore conf files
db_pwd=$(sudo yunohost app setting $app mysqlpwd) sudo cp -a "${BACKUP_DIR}/conf/${APP}.conf" /etc/nginx/conf.d/$domain.d/${APP}.conf
sudo mysql -u $app -p$db_pwd $app < $backup_dir/$app.dmp sudo cp -a "${BACKUP_DIR}/conf/php-fpm.conf" /etc/php5/fpm/pool.d/${APP}.conf
# Restore Nginx and YunoHost parameters # Restore mysql dump
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app sudo su -c "mysql -u ${APP} -p$db_pwd ${APP} < ${BACKUP_DIR}/${APP}.dmp"
domain=$(sudo yunohost app setting $app domain)
sudo cp -a $backup_dir/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo cp -a $backup_dir/php-fpm.conf /etc/php5/fpm/pool.d/$app.conf
# Reload Nginx, PHP5-FPM and regenerate SSOwat conf # Reload Nginx, PHP5-FPM and regenerate SSOwat conf
sudo service php5-fpm restart sudo service php5-fpm restart
sudo service nginx reload sudo service nginx reload
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
exit 0