restore 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # This restore script is adapted to Yunohost >=2.4
  3. # Exit on command errors and treat unset variables as an error
  4. set -eu
  5. # The parameter $1 is the backup directory location dedicated to the app
  6. backup_dir=$1
  7. # The parameter $2 is the id of the app instance ex: ynhexample__2
  8. app=$2
  9. # Source app helpers
  10. source /usr/share/yunohost/helpers
  11. # Get old parameter of the app
  12. domain=$(ynh_app_setting_get $app domain)
  13. path=$(ynh_app_setting_get $app path)
  14. is_public=$(ynh_app_setting_get $app is_public)
  15. final_path=$(ynh_app_setting_get $app final_path)
  16. if [ -d $final_path ]; then
  17. ynh_die "There is already a directory: $final_path"
  18. fi
  19. conf=/etc/nginx/conf.d/$domain.d/$app.conf
  20. if [ -f $conf ]; then
  21. ynh_die "There is already a nginx conf file at this path: $conf"
  22. fi
  23. # Restore conf files
  24. sudo cp -a "${backup_dir}/conf/nginx.conf" $conf
  25. # Reload Nginx
  26. sudo service nginx reload
  27. sudo cp -a "${backup_dir}/var/www/$app" $final_path
  28. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  29. db_user=$app
  30. ynh_mysql_create_db $db_user $db_user $db_pwd
  31. sudo su -c "mysql -u $db_user -p$db_pwd $app < ${backup_dir}/db.sql"
  32. sudo rm -f "${backup_dir}/db.sql"
  33. sudo sed -i -e "s/'DB_USER', *'[^']*'/'DB_USER', '$app'/g" $final_path/config/connect.php
  34. sudo sed -i -e "s/'DB_NAME', *'[^']*'/'DB_NAME', '$app'/g" $final_path/config/connect.php
  35. # Set permissions
  36. # Les fichiers appartiennent à www-data, pour permettre les mises à jour.
  37. sudo chown -R www-data: $final_path
  38. # Sauf le fichier de config connect.php qui appartient à root
  39. sudo chown root: $final_path/config/connect.php
  40. # Copy dedicated php-fpm process from backup folder to the right location
  41. sudo cp -a $backup_dir/conf/php-fpm.conf /etc/php5/fpm/pool.d/$app.conf
  42. sudo cp -a $backup_dir/conf/php-fpm.ini /etc/php5/fpm/conf.d/20-$app.ini
  43. # And restart service
  44. sudo service php5-fpm reload
  45. # Set ssowat config
  46. if [ "$is_public" = "No" ];
  47. then
  48. ynh_app_setting_delete $app skipped_uris
  49. fi
  50. sudo yunohost app ssowatconf