mirror of
https://github.com/YunoHost-Apps/nextcloud_ynh.git
synced 2024-09-03 19:55:57 +02:00
[enh] Rewrite and update backup/restore scripts to use helpers
This commit is contained in:
parent
8ecface268
commit
5d9232f082
4 changed files with 100 additions and 105 deletions
|
@ -29,10 +29,10 @@ or from the Web administration:
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* Test the upgrade from the current official package
|
* Test the upgrade from the current official package
|
||||||
* Update backup and restore scripts
|
|
||||||
* Develop an app to integrate SSOwat logout - see
|
* Develop an app to integrate SSOwat logout - see
|
||||||
[here](https://doc.owncloud.org/server/9.0/developer_manual/app/hooks.html#session)
|
[here](https://doc.owncloud.org/server/9.0/developer_manual/app/hooks.html#session)
|
||||||
* Check the external storage plugin
|
* Update the external storage plugin configuration - see
|
||||||
|
[here](https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/occ_command.html#files-external-label)
|
||||||
* ...
|
* ...
|
||||||
|
|
||||||
## Links ##
|
## Links ##
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Section: misc
|
Section: misc
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Homepage: https://mediagoblin.org/
|
Homepage: https://owncloud.org/
|
||||||
Standards-Version: 3.9.2
|
Standards-Version: 3.9.2
|
||||||
|
|
||||||
Package: owncloud-deps
|
Package: owncloud-deps
|
||||||
|
|
|
@ -1,31 +1,37 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
APP=${!#}
|
|
||||||
|
|
||||||
|
# Retrieve arguments
|
||||||
CAN_BIND=1
|
|
||||||
|
|
||||||
# The parameter $1 is the backup directory location dedicated to the app
|
|
||||||
backup_dir=$1
|
backup_dir=$1
|
||||||
|
app=${!#}
|
||||||
|
|
||||||
|
# Set app specific variables
|
||||||
|
dbname=$app
|
||||||
|
dbuser=$app
|
||||||
|
|
||||||
|
# Source app helpers
|
||||||
|
. /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Retrieve app settings
|
||||||
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
path=$(ynh_app_setting_get $app path)
|
||||||
|
dbpass=$(ynh_app_setting_get $app mysqlpwd)
|
||||||
|
|
||||||
domain=$(sudo yunohost app setting $APP domain)
|
# Copy the app source files
|
||||||
path=$(sudo yunohost app setting $APP path)
|
DESTDIR="/var/www/$app"
|
||||||
user=$(sudo yunohost app setting $APP admin_user)
|
sudo cp -a "$DESTDIR" ./www
|
||||||
|
|
||||||
# Backup sources & data
|
# Copy the data directory
|
||||||
sudo cp -a /var/www/$APP $backup_dir/www
|
DATADIR="/home/yunohost.app/${app}/data"
|
||||||
# TODO Shallow copy because data could be very big
|
ynh_bind_or_cp "$DATADIR" "${backup_dir}/data" 1
|
||||||
sudo cp -a /home/yunohost.app/$APP/data $backup_dir/data
|
|
||||||
|
|
||||||
# Copy Conf
|
# Copy the conf files
|
||||||
sudo mkdir -p "${backup_dir}/conf"
|
mkdir ./conf
|
||||||
sudo cp -a /etc/nginx/conf.d/$domain.d/$APP.conf $backup_dir/conf/nginx.conf
|
sudo cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./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/pool.d/${app}.conf" ./conf/php-fpm.conf
|
||||||
sudo cp -a /etc/php5/cli/conf.d/20-apc.ini $backup_dir/conf/ \
|
|
||||||
|| sudo cp -a /etc/php5/cli/conf.d/20-apcu.ini $backup_dir/conf/
|
|
||||||
|
|
||||||
# Backup db
|
# Dump the database
|
||||||
db_pwd=$(sudo yunohost app setting $APP mysqlpwd)
|
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql
|
||||||
sudo su -c "mysqldump -u $APP -p"$db_pwd" --no-create-db $APP > ${backup_dir}/db.sql"
|
|
||||||
|
# Copy the control file of the dependency package
|
||||||
|
# FIXME: find a way to retrieve package name from _common.sh?
|
||||||
|
dpkg-query -s owncloud-deps > ./owncloud-deps.control
|
||||||
|
|
151
scripts/restore
151
scripts/restore
|
@ -1,100 +1,89 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# This restore script is adapted to Yunohost >=2.4
|
|
||||||
APP=${!#}
|
|
||||||
|
|
||||||
# The parameter $1 is the backup directory location dedicated to the app
|
# Retrieve arguments
|
||||||
backup_dir=$1
|
backup_dir=$1
|
||||||
|
app=${!#}
|
||||||
|
|
||||||
|
# TODO: Put a simple die function in app helpers, redeclare it since
|
||||||
|
# _common.sh cannot be easily sourced
|
||||||
|
die() {
|
||||||
|
printf "%s" "$1" 1>&2
|
||||||
|
exit "${2:-1}"
|
||||||
|
}
|
||||||
|
|
||||||
# Get old parameter of the app
|
# Set app specific variables
|
||||||
domain=$(sudo yunohost app setting $APP domain)
|
dbname=$app
|
||||||
path=$(sudo yunohost app setting $APP path)
|
dbuser=$app
|
||||||
user=$(sudo yunohost app setting $APP admin_user)
|
|
||||||
|
|
||||||
# Check domain/path availability
|
# Source app helpers
|
||||||
sudo yunohost app checkurl $domain$path -a $APP
|
. /usr/share/yunohost/helpers
|
||||||
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
|
# Retrieve old app settings
|
||||||
if [ -d $final_path ]; then
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
echo "There is already a directory: $final_path " | sudo tee /dev/stderr
|
path=$(ynh_app_setting_get $app path)
|
||||||
exit 1
|
dbpass=$(ynh_app_setting_get $app mysqlpwd)
|
||||||
fi
|
|
||||||
data_path=/home/yunohost.app/$APP/data
|
|
||||||
if [ -d $data_path ]; then
|
|
||||||
echo "There is already a directory: $data_path " | sudo tee /dev/stderr
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
conf_nginx=/etc/nginx/conf.d/$domain.d/$APP.conf
|
# TODO: Check domain/path availability with app helper
|
||||||
if [ -f $conf_nginx ]; then
|
sudo yunohost app checkurl $domain$path -a $app \
|
||||||
echo "There is already a nginx conf file at this path: $conf_nginx " | sudo tee /dev/stderr
|
|| die "The path ${domain}${path} is not available for app installation."
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
conf_fpm=/etc/php5/fpm/pool.d/$APP.conf
|
# Check destination directory
|
||||||
if [ -f $conf_fpm ]; then
|
DESTDIR="/var/www/$app"
|
||||||
echo "There is already a nginx conf file at this path: $conf_fpm " | sudo tee /dev/stderr
|
[[ -d $DESTDIR ]] && die \
|
||||||
exit 1
|
"The destination directory '$DESTDIR' already exists.\
|
||||||
fi
|
You should safely delete it before restoring this app."
|
||||||
|
|
||||||
|
# Define app's data directory
|
||||||
|
DATADIR="/home/yunohost.app/${app}/data"
|
||||||
|
|
||||||
|
# Check configuration files
|
||||||
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||||
|
[[ -f $nginx_conf ]] && die \
|
||||||
|
"The NGINX configuration already exists at '${nginx_conf}'.
|
||||||
|
You should safely delete it before restoring this app."
|
||||||
|
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||||
|
[[ -f $phpfpm_conf ]] && die \
|
||||||
|
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
||||||
|
You should safely delete it before restoring this app."
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
sudo apt-get update -qq
|
ynh_package_install_from_equivs ./owncloud-deps.control \
|
||||||
sudo DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" -y --force-yes -qq install acl smbclient php5-cli php-apc coreutils gnupg tar
|
|| die "Unable to install dependencies"
|
||||||
|
|
||||||
# Create user if not exists
|
# Create a system account for ownCloud
|
||||||
sudo useradd -d /var/www/$APP $APP || echo "User $APP"
|
sudo useradd -c "$app system account" \
|
||||||
|
-d /var/lib/$app --system --user-group $app \
|
||||||
|
|| die "Unable to create $app system account"
|
||||||
|
|
||||||
# Restore sources & data
|
# Restore the app files
|
||||||
sudo cp -a "${backup_dir}/www" $final_path
|
sudo cp -a ./www "$DESTDIR"
|
||||||
sudo mkdir -p $data_path
|
sudo mkdir -p "$DATADIR"
|
||||||
sudo cp -a "${backup_dir}/data/." $data_path
|
sudo cp -a ./data/. "$DATADIR"
|
||||||
|
|
||||||
db_pwd=$(sudo yunohost app setting $APP mysqlpwd)
|
# Create and restore the database
|
||||||
db_user=$APP
|
ynh_mysql_create_db $dbname $dbuser $dbpass
|
||||||
sudo yunohost app initdb $db_user -p $db_pwd
|
ynh_mysql_connect_as $dbuser $dbpass $dbname < ./db.sql
|
||||||
sudo su -c "mysql -u $db_user -p$db_pwd $APP < ${backup_dir}/db.sql"
|
|
||||||
# TODO Change config.php with potential new database name
|
|
||||||
|
|
||||||
# Set permissions
|
# Iterate over users to extend their home folder permissions - for the external
|
||||||
sudo chown -hR $APP:www-data $final_path
|
# storage plugin usage - and create relevant ownCloud directories
|
||||||
sudo chown -hR $APP:www-data $data_path
|
for u in $(ynh_user_list); do
|
||||||
sudo chown $APP:www-data /home/yunohost.app/$APP
|
sudo mkdir -p "${DATADIR}/${u}"
|
||||||
sudo chmod 755 /home/yunohost.app
|
sudo setfacl -m g:$app:rwx "/home/$u" || true
|
||||||
sudo chmod -R u=rwX,g=rwX,o=rX $final_path
|
|
||||||
sudo chmod -R u=rwX,g=rwX,o= $data_path
|
|
||||||
sudo chmod -R 665 $final_path
|
|
||||||
sudo find $final_path -type d -print0 | xargs -0 sudo chmod 775 \
|
|
||||||
|| echo "No file to modify"
|
|
||||||
sudo chmod -R 770 $data_path
|
|
||||||
|
|
||||||
# Set permissions to owncloud directories and /home directories + add Home external storage
|
|
||||||
for i in $(ls /home)
|
|
||||||
do
|
|
||||||
sudo yunohost user list --json | grep -q "\"username\": \"$i\"" && (
|
|
||||||
sudo setfacl -m g:$APP:rwx /home/$i || echo "ACL not available"
|
|
||||||
) || true
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Needed for Jessie/PHP5.6 compatibility
|
# Fix app ownerships & permissions
|
||||||
sudo sed -i "s/;always_populate_raw/always_populate_raw/" /etc/php5/cli/php.ini
|
sudo chown -R $app: "$DESTDIR" "$DATADIR"
|
||||||
|
sudo find ${DESTDIR}/ -type f -print0 | sudo xargs -0 chmod 0644
|
||||||
|
sudo find ${DESTDIR}/ -type d -print0 | sudo xargs -0 chmod 0755
|
||||||
|
sudo find ${DATADIR}/ -type f -print0 | sudo xargs -0 chmod 0640
|
||||||
|
sudo find ${DATADIR}/ -type d -print0 | sudo xargs -0 chmod 0750
|
||||||
|
sudo chmod 640 "${DESTDIR}/config/config.php"
|
||||||
|
sudo chmod 755 /home/yunohost.app
|
||||||
|
|
||||||
# Restore conf files
|
# Restore configuration files
|
||||||
sudo cp -a "${backup_dir}/conf/nginx.conf" $conf_nginx
|
sudo cp -a ./conf/nginx.conf "$nginx_conf"
|
||||||
sudo cp -a "${backup_dir}/conf/php-fpm.conf" $conf_fpm
|
sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf"
|
||||||
sudo cp -a "${backup_dir}/conf/20-apc.ini" /etc/php5/cli/conf.d/ \
|
|
||||||
|| sudo cp -a "${backup_dir}/conf/20-apcu.ini" /etc/php5/cli/conf.d/
|
|
||||||
|
|
||||||
# Reload Services
|
# Reload services
|
||||||
sudo killall php5-fpm
|
sudo service php5-fpm restart || true
|
||||||
sudo service php5-fpm start
|
sudo service nginx reload || true
|
||||||
sudo service nginx reload
|
|
||||||
sudo yunohost app setting $APP unprotected_uris -v "/"
|
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
|
|
||||||
# Set ssowat config
|
|
||||||
sudo yunohost app setting $APP unprotected_uris -v "/"
|
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue