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

[enh] Add backup/restore scripts

This commit is contained in:
zamentur 2016-01-11 00:04:10 +01:00
parent a4fd979018
commit 80cbada5e9
2 changed files with 121 additions and 0 deletions

28
scripts/backup Normal file
View file

@ -0,0 +1,28 @@
#!/bin/bash
# The parameter $1 is the backup directory location dedicated to the app
backup_dir=$1
# The parameter $2 is theid of the app instance
app=$2
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
admin=$(sudo yunohost app setting $app admin)
language=$(sudo yunohost app setting $app language)
public_site=$(sudo yunohost app setting $app public_site)
# Copy the app files
final_path=/var/www/$app
sudo mkdir -p ${backup_dir}/var/www
sudo cp -a $final_path "${backup_dir}/var/www/$app"
# Copy the conf files
sudo mkdir -p "${backup_dir}/conf"
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf "${backup_dir}/conf/nginx.conf"
sudo cp -a /etc/php5/fpm/pool.d/$app.conf "${backup_dir}/conf/php-fpm.conf"
sudo cp -a /etc/php5/fpm/conf.d/20-$app.ini "${backup_dir}/conf/php-fpm.ini"
# Backup db
db_pwd=$(sudo yunohost app setting $app mysqlpwd)
sudo su -c "mysqldump -u $app -p"$db_pwd" --no-create-db $app > ${backup_dir}/db.sql"

93
scripts/restore Normal file
View file

@ -0,0 +1,93 @@
#!/bin/bash
# This restore script is adapted to Yunohost >=2.4
# The parameter $1 is the backup directory location dedicated to the app
backup_dir=$1
# The parameter $2 is the id of the app instance ex: ynhexample__2
app=$2
# Get old parameter of the app
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
admin_wordpress=$(sudo yunohost app setting $app admin)
language=$(sudo yunohost app setting $app language)
public_site=$(sudo yunohost app setting $app public_site)
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
echo "There is already an app on this URL : $domain$path" | sudo tee /dev/stderr
exit 1
fi
final_path=/var/www/$app
if [ -d $final_path ]; then
echo "There is already a directory: $final_path " | sudo tee /dev/stderr
exit 1
fi
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 " | sudo tee /dev/stderr
exit 1
fi
phpconf=/etc/php5/fpm/pool.d/$app.conf
if [ -f $phpconf ]; then
echo "There is already a php-fpm conf file at this path: $phpconf " | sudo tee /dev/stderr
exit 1
fi
phpini=/etc/php5/fpm/conf.d/20-$app.ini
if [ -f $phpini ]; then
echo "There is already a php-fpm ini file at this path: $phpini " | sudo tee /dev/stderr
exit 1
fi
# Dependences
sudo DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" -y --force-yes -qq install php-fpdf
# Restore sources & data
sudo cp -a "${backup_dir}/var/www/$app" $final_path
db_pwd=$(sudo yunohost app setting $app mysqlpwd)
db_user=$app
sudo yunohost app initdb $db_user -p $db_pwd
sudo su -c "mysql -u $db_user -p$db_pwd $app < ${backup_dir}/db.sql"
sudo rm -f "${backup_dir}/db.sql"
sudo sed -i -e "s/'DB_USER', *'[^']*'/'DB_USER', '$app'/g" $final_path/wp-config.php
sudo sed -i -e "s/'DB_NAME', *'[^']*'/'DB_NAME', '$app'/g" $final_path/wp-config.php
# Set permissions
sudo chmod 700 $final_path/admin/logs_studs.txt
sudo chown -R www-data:www-data $final_path
# Restore conf files
sudo cp -a "${backup_dir}/conf/nginx.conf" $conf
sudo cp -a "${backup_dir}/conf/php-fpm.conf" $phpconf
sudo chown root: $phpconf
sudo chmod 644 $phpconf
sudo cp -a "${backup_dir}/conf/php-fpm.ini" $phpini
sudo chown root: $phpini
sudo chmod 644 $phpini
# Set Administrator
if sudo yunohost user info test > /dev/null; then
sudo yunohost app addaccess opensondage -u $admin
fi
# Reload Nginx
sudo service php5-fpm restart
sudo service nginx reload
# Set ssowat config
sudo yunohost app setting opensondage skipped_uris -v "/"
if [ $public_site = "No" ];
then
sudo yunohost app setting opensondage protected_uris -v "/admin,/index.php,/choix_date.php,/choix_autre.php,/infos_sondage.php,/scripts"
else
sudo yunohost app setting opensondage protected_uris -v "/admin/index.php,/admin/logs_studs.txt,/scripts"
fi
sudo yunohost app ssowatconf