1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/borg_ynh.git synced 2024-09-03 18:16:05 +02:00

[fix] Upgrade borgbackup correctly

This commit is contained in:
ljf 2021-03-04 16:38:12 +01:00
parent ff0be0b044
commit 5f3085aae3
4 changed files with 101 additions and 51 deletions

View file

@ -6,7 +6,7 @@
"en": "Backup your server on a host server using Borg.", "en": "Backup your server on a host server using Borg.",
"fr": "Sauvegardez votre serveur sur un serveur distant avec Borg." "fr": "Sauvegardez votre serveur sur un serveur distant avec Borg."
}, },
"version": "1.1.15~ynh1", "version": "1.1.15~ynh2",
"url": "https://borgbackup.readthedocs.io", "url": "https://borgbackup.readthedocs.io",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"maintainer": { "maintainer": {

View file

@ -5,19 +5,26 @@
#================================================= #=================================================
# App package root directory should be the parent folder # App package root directory should be the parent folder
PKG_DIR=$(cd ../; pwd) PKG_DIR=$(cd ../; pwd)
BORG_VERSION=1.1.15
pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python-virtualenv virtualenv" pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python-virtualenv virtualenv libfuse-dev pkg-config"
# Install borg with pip if borg is not here # Install borg with pip if borg is not here
install_borg_with_pip () { install_borg_with_pip () {
if [ -d /opt/borg-env ]; then
/opt/borg-env/bin/python /opt/borg-env/bin/pip list | grep "Version: $BORG_VERSION" || ynh_secure_remove /opt/borg-env
fi
if [ ! -d /opt/borg-env ]; then if [ ! -d /opt/borg-env ]; then
python3 -m venv /opt/borg-env python3 -m venv /opt/borg-env
/opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup[fuse]==1.1.15 /opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup[fuse]==$BORG_VERSION
echo "#!/bin/bash echo "#!/bin/bash
/opt/borg-env/bin/python /opt/borg-env/bin/borg \"\$@\"" > /usr/local/bin/borg /opt/borg-env/bin/python /opt/borg-env/bin/borg \"\$@\"" > /usr/local/bin/borg
# We need this to be executable by if is_buster; then
chmod a+x /usr/local/bin/borg touch /opt/borg-env/buster
fi
fi fi
# We need this to be executable by other borg apps
chmod a+x /usr/local/bin/borg
} }
#================================================= #=================================================

View file

@ -44,7 +44,8 @@ ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
install_borg_with_pip install_borg_with_pip
#=================================================
# SPECIFIC SETUP
#================================================= #=================================================
# ACTIVATE BACKUP METHODS # ACTIVATE BACKUP METHODS
#================================================= #=================================================
@ -56,49 +57,34 @@ mkdir -p /usr/share/yunohost/backup_method
# SETUP THE BACKUP METHOD # SETUP THE BACKUP METHOD
#================================================= #=================================================
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app" ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
#=================================================
# CONFIGURE CRON
#=================================================
ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app" ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app"
chmod u+x "/usr/local/bin/backup-with-$app" chmod u+x "/usr/local/bin/backup-with-$app"
ynh_add_systemd_config
ynh_configure systemd.timer "/etc/systemd/system/$app.timer"
systemctl enable $app.timer --quiet
systemctl start $app.timer
#yunohost service add $app.timer
#yunohost service enable $app.timer
#yunohost service start $app.timer
#================================================= if [ ! -z "$server" ]; then
# ADVERTISE SERVICE IN ADMIN PANEL #=================================================
#================================================= # GENERATE SSH KEY
ynh_script_progression --message="Integrating service in YunoHost..." #=================================================
yunohost service add $app --description="Deduplicating backup program" private_key="/root/.ssh/id_${app}_ed25519"
test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key
#================================================= #=================================================
# GENERATE SSH KEY # Display key
#================================================= #=================================================
private_key="/root/.ssh/id_${app}_ed25519" echo "You should now install the \"Borg Server\" app on $server and fill questions like this:
test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key User: ${ssh_user}
Public key: $(cat ${private_key}.pub)"
#================================================= #=================================================
# Display key # SEND A README FOR THE ADMIN
#================================================= #=================================================
echo "You should now install the \"Borg Server\" app on $server and fill questions like this: ynh_print_OFF
User: ${ssh_user} message="You should now install the \"Borg Server\" app on $server and fill questions like this:
Public key: $(cat ${private_key}.pub)"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
ynh_print_OFF
message="You should now install the \"Borg Server\" app on $server and fill questions like this:
User: ${ssh_user} User: ${ssh_user}
Public key: $(cat ${private_key}.pub) Public key: $(cat ${private_key}.pub)
@ -108,8 +94,32 @@ yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh -a \"ssh_us
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/borg_ynh" If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/borg_ynh"
ynh_send_readme_to_admin "$message" "root" ynh_send_readme_to_admin "$message" "root"
ynh_print_ON ynh_print_ON
fi
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --time --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# CONFIGURE SYSTEMD TIMER
#=================================================
ynh_configure systemd.timer "/etc/systemd/system/$app.timer"
systemctl enable $app.timer --quiet
systemctl start $app.timer
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Deduplicating backup program"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -67,36 +67,69 @@ if grep "borg.timer" /etc/yunohost/services.yml > /dev/null ; then
fi fi
# Replace backports with pip # Replace backports with pip
rm -f /etc/apt/sources.list.d/$app-stretch-backports.list
# Reinstall borg if stretch -> buster migration
if is_buster; then if is_buster; then
if [ ! -f /opt/borg-env/buster ] ; then if [ ! -f /opt/borg-env/buster ] ; then
rm -f /etc/apt/sources.list.d/$app-stretch-backports.list ynh_secure_remove /opt/borg-env
ynh_secure_remove /opt/borg-env
install_borg_with_pip
touch /opt/borg-env/buster
fi fi
fi fi
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Upgrade borgbackup
#=================================================
ynh_script_progression --message="Upgrading borgbackup..." --weight=1
install_borg_with_pip
#================================================= #=================================================
# SETUP THE BACKUP METHOD # SETUP THE BACKUP METHOD
#================================================= #=================================================
ynh_script_progression --message="Setting up backup method..." --weight=1 ynh_script_progression --message="Setting up backup method..." --weight=1
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app" ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
#=================================================
# CONFIGURE CRON
#=================================================
ynh_script_progression --message="Configuring systemd timer..." --weight=1
ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app" ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app"
chmod u+x "/usr/local/bin/backup-with-$app" chmod u+x "/usr/local/bin/backup-with-$app"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#=================================================
# CONFIGURE SYSTEMD TIMER
#=================================================
ynh_configure systemd.timer "/etc/systemd/system/$app.timer" ynh_configure systemd.timer "/etc/systemd/system/$app.timer"
systemctl enable $app.timer --quiet systemctl enable $app.timer --quiet
systemctl start $app.timer systemctl start $app.timer
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # GENERIC FINALIZATION
#================================================= #=================================================
ynh_script_progression --message="Exposing borg service in webadmin..." --weight=1 # SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Deduplicating backup program" yunohost service add $app --description="Deduplicating backup program"