1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/borgserver_ynh.git synced 2024-09-03 20:36:20 +02:00
This commit is contained in:
ljf (zamentur) 2022-12-16 20:15:49 +01:00 committed by GitHub
commit 631658f49e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 87 additions and 49 deletions

View file

@ -5,7 +5,7 @@ It shall NOT be edited by hand.
# Borg Server for YunoHost # Borg Server for YunoHost
[![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg) [![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Working status](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg)
[![Install Borg Server with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver) [![Install Borg Server with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver)
*[Lire ce readme en français.](./README_fr.md)* *[Lire ce readme en français.](./README_fr.md)*
@ -21,26 +21,24 @@ The main goal of Borg is to provide an efficient and secure way to backup data.
**Shipped version:** 1.1.16~ynh9 **Shipped version:** 1.1.16~ynh9
## Documentation and resources ## Documentation and resources
* Official app website: https://www.borgbackup.org/ * Official app website: <https://www.borgbackup.org/>
* Official admin documentation: https://borgbackup.readthedocs.io/en/stable/ * Official admin documentation: <https://borgbackup.readthedocs.io/en/stable/>
* Upstream app code repository: https://github.com/borgbackup/borg * Upstream app code repository: <https://github.com/borgbackup/borg>
* YunoHost documentation for this app: https://yunohost.org/app_borgserver * YunoHost documentation for this app: <https://yunohost.org/app_borgserver>
* Report a bug: https://github.com/YunoHost-Apps/borgserver_ynh/issues * Report a bug: <https://github.com/YunoHost-Apps/borgserver_ynh/issues>
## Developer info ## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing). Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing).
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
```
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug
or or
sudo yunohost app upgrade borgserver -u https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug sudo yunohost app upgrade borgserver -u https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug
``` ```
**More info regarding app packaging:** https://yunohost.org/packaging_apps **More info regarding app packaging:** <https://yunohost.org/packaging_apps>

View file

@ -1,10 +1,14 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
# Borg Server pour YunoHost # Borg Server pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg) [![Niveau d'intégration](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg)
[![Installer Borg Server avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver) [![Installer Borg Server avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver)
*[Read this readme in english.](./README.md)* *[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer Borg Server rapidement et simplement sur un serveur YunoHost. > *Ce package vous permet d'installer Borg Server rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
@ -17,26 +21,24 @@ The main goal of Borg is to provide an efficient and secure way to backup data.
**Version incluse :** 1.1.16~ynh9 **Version incluse :** 1.1.16~ynh9
## Documentations et ressources ## Documentations et ressources
* Site officiel de l'app : https://www.borgbackup.org/ * Site officiel de l'app : <https://www.borgbackup.org/>
* Documentation officielle de l'admin : https://borgbackup.readthedocs.io/en/stable/ * Documentation officielle de l'admin : <https://borgbackup.readthedocs.io/en/stable/>
* Dépôt de code officiel de l'app : https://github.com/borgbackup/borg * Dépôt de code officiel de l'app : <https://github.com/borgbackup/borg>
* Documentation YunoHost pour cette app : https://yunohost.org/app_borgserver * Documentation YunoHost pour cette app : <https://yunohost.org/app_borgserver>
* Signaler un bug : https://github.com/YunoHost-Apps/borgserver_ynh/issues * Signaler un bug : <https://github.com/YunoHost-Apps/borgserver_ynh/issues>
## Informations pour les développeurs ## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing). Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit. Pour essayer la branche testing, procédez comme suit.
```
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug
ou ou
sudo yunohost app upgrade borgserver -u https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug sudo yunohost app upgrade borgserver -u https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug
``` ```
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps **Plus d'infos sur le packaging d'applications :** <https://yunohost.org/packaging_apps>

View file

@ -2,6 +2,7 @@
; Manifest ; Manifest
ssh_user="sam" ssh_user="sam"
public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
datadir=/home/USER
alert_delay=1 alert_delay=1
alert_mails="sam@domain.tld" alert_mails="sam@domain.tld"
quota="1G" quota="1G"

View file

@ -1,2 +1,2 @@
SHELL=/bin/bash SHELL=/bin/bash
0 9,20 * * * root : Monitor __SSH_USER__ backup ; ALERT_DELAY="$(grep '^alert_delay: ' /etc/yunohost/apps/__APP__/settings.yml | awk -F\' '{print $2}')"; [[ $(find /home/__SSH_USER__/backup/data -follow -mtime -${ALERT_DELAY} -ls | wc -l) > 0 ]] || ( echo "No file has been backuped in /home/__SSH_USER__ since ${ALERT_DELAY} days" | mail -s "[YNH] Backup missing : __SSH_USER__" $(grep '^alert_mails: ' /etc/yunohost/apps/__APP__/settings.yml | awk '{print $2}')) 0 9,20 * * * root : Monitor __SSH_USER__ backup ; ALERT_DELAY="$(grep '^alert_delay: ' /etc/yunohost/apps/__APP__/settings.yml | awk -F\' '{print $2}')"; [[ $(find __DATADIR__/backup/data -follow -mtime -${ALERT_DELAY} -ls | wc -l) > 0 ]] || ( echo "No file has been backuped in __DATADIR__ since ${ALERT_DELAY} days" | mail -s "[YNH] Backup missing : __SSH_USER__" $(grep '^alert_mails: ' /etc/yunohost/apps/__APP__/settings.yml | awk '{print $2}'))

View file

@ -44,6 +44,15 @@
"fr": "Indiquez la clé publique donnée par l'app borg_ynh" "fr": "Indiquez la clé publique donnée par l'app borg_ynh"
} }
}, },
{
"name": "datadir",
"type": "string",
"ask": {
"en": "Indicate the path of the ssh user home directory where create the borg archive",
"fr": "Indiquez le chemin du dossier de l'utilisateur ssh où créer l'archive borg"
},
"default": "/home/__SSH_USER__"
},
{ {
"name": "alert_delay", "name": "alert_delay",
"type": "string", "type": "string",

View file

@ -22,16 +22,17 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
export ssh_user="$(ynh_app_setting_get $app ssh_user)" export ssh_user="$(ynh_app_setting_get $app ssh_user)"
export datadir="$(ynh_app_setting_get $app datadir)"
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
#================================================= #=================================================
ynh_print_info --message="Declaring files to be backed up..." ynh_print_info --message="Declaring files to be backed up..."
ynh_backup "/home/$ssh_user/.ssh" ynh_backup "$datadir/.ssh"
ynh_backup "/home/$ssh_user/.nobackup" ynh_backup "$datadir/.nobackup"
ynh_backup "/etc/cron.d/$app" ynh_backup "/etc/cron.d/$app"
ynh_print_info --message="Borg backup repo in /home/$ssh_user/ won't be backup to avoid backup of backup loop issue." ynh_print_info --message="Borg backup repo in $datadir/ won't be backup to avoid backup of backup loop issue."
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -23,7 +23,7 @@ ynh_abort_if_errors
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments # Retrieve arguments
ynh_export ssh_user public_key quota alert_delay alert_mails ynh_export ssh_user public_key quota datadir alert_delay alert_mails
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
@ -35,11 +35,21 @@ if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
fi fi
ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists" ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists"
datadir=$(echo "$datadir" | sed "s/__SSH_USER__/$ssh_user/" | sed "s/__APP__/$app/")
if [[ -z "$datadir" ]]; then
datadir=/home/$ssh_user
fi
if _acceptable_path_to_delete "$datadir"; then
ynh_die --message="This path can't be used as home dir for the ssh_user"
fi
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_save_args ssh_user public_key quota alert_delay alert_mails ynh_save_args ssh_user public_key quota alert_delay alert_mails datadir
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
@ -54,30 +64,29 @@ install_borg_with_pip
#================================================= #=================================================
ynh_script_progression --message="Creating SSH user used by Borg..." ynh_script_progression --message="Creating SSH user used by Borg..."
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app ynh_system_user_create --username=$ssh_user --home_dir=$datadir --use_shell --groups ssh.app
#================================================= #=================================================
# AUTORIZE SSH FOR THIS USER # AUTORIZE SSH FOR THIS USER
#================================================= #=================================================
ynh_script_progression --message="Configuring SSH public key for remote connexion..." ynh_script_progression --message="Configuring SSH public key for remote connexion..."
home=/home/$ssh_user mkdir -p $datadir/.ssh
mkdir -p /home/$ssh_user/.ssh chmod o=--- $datadir
chmod o=--- /home/$ssh_user chown -R $ssh_user:$ssh_user $datadir
chown -R $ssh_user:$ssh_user /home/$ssh_user touch $datadir/.ssh/authorized_keys
touch /home/$ssh_user/.ssh/authorized_keys
extra="--storage-quota $quota" extra="--storage-quota $quota"
if [ "$quota" = "" ]; then if [ "$quota" = "" ]; then
extra="" extra=""
fi fi
echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys echo "command=\"borg serve $extra --restrict-to-repository $datadir/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $datadir/.ssh/authorized_keys
#================================================= #=================================================
# AVOID BACKUP OF BACKUP # AVOID BACKUP OF BACKUP
#================================================= #=================================================
ynh_script_progression --message="Avoiding to backup the backup itself..." ynh_script_progression --message="Avoiding to backup the backup itself..."
touch $home/.nobackup touch $datadir/.nobackup
#================================================= #=================================================
# SETUP CRON # SETUP CRON

View file

@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
ssh_user=$(ynh_app_setting_get $app ssh_user) ssh_user=$(ynh_app_setting_get $app ssh_user)
datadir=$(ynh_app_setting_get $app ssh_user)
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
@ -36,6 +37,17 @@ fi
# backups stored in the home directory # backups stored in the home directory
ynh_system_user_delete --username=$ssh_user ynh_system_user_delete --username=$ssh_user
#=================================================
# REMOVE DATA DIR
#=================================================
# Remove the data directory if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..." --weight=1
ynh_secure_remove --file="$datadir"
fi
#================================================= #=================================================
# REMOVE CRON FILES # REMOVE CRON FILES
#================================================= #=================================================

View file

@ -25,6 +25,7 @@ app=$YNH_APP_INSTANCE_NAME
export ssh_user=$(ynh_app_setting_get $app ssh_user) export ssh_user=$(ynh_app_setting_get $app ssh_user)
export public_key=$(ynh_app_setting_get $app public_key) export public_key=$(ynh_app_setting_get $app public_key)
export quota=$(ynh_app_setting_get $app quota) export quota=$(ynh_app_setting_get $app quota)
export datadir=$(ynh_app_setting_get $app datadir)
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
@ -45,22 +46,21 @@ ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_she
# AUTORIZE SSH FOR THIS USER # AUTORIZE SSH FOR THIS USER
#================================================= #=================================================
home=/home/$ssh_user mkdir -p $datadir/.ssh
mkdir -p /home/$ssh_user/.ssh chmod o=--- $datadir
chmod o=--- /home/$ssh_user chown -R $ssh_user:$ssh_user $datadir
chown -R $ssh_user:$ssh_user /home/$ssh_user touch $datadir/.ssh/authorized_keys
touch /home/$ssh_user/.ssh/authorized_keys
extra="--storage-quota $quota" extra="--storage-quota $quota"
if [ "$quota" = "" ]; then if [ "$quota" = "" ]; then
extra="" extra=""
fi fi
echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys echo "command=\"borg serve $extra --restrict-to-repository $datadir/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $datadir/.ssh/authorized_keys
#================================================= #=================================================
# AVOID BACKUP OF BACKUP # AVOID BACKUP OF BACKUP
#================================================= #=================================================
touch $home/.nobackup touch $datadir/.nobackup
ynh_restore ynh_restore
#================================================= #=================================================

View file

@ -16,6 +16,7 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user) ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
public_key=$(ynh_app_setting_get --app=$app --key=public_key) public_key=$(ynh_app_setting_get --app=$app --key=public_key)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay) alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay)
alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails) alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails)
@ -77,12 +78,17 @@ if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then
ynh_secure_remove /opt/borg-env ynh_secure_remove /opt/borg-env
fi fi
if [ -z "$datadir" ];
then
datadir="/home/${ssh_user}"
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
fi
#================================================= #=================================================
# CREATE SSH USER USED BY BORG # CREATE SSH USER USED BY BORG
#================================================= #=================================================
ynh_script_progression --message="Creating SSH user used by Borg..." ynh_script_progression --message="Creating SSH user used by Borg..."
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app ynh_system_user_create --username=$ssh_user --home_dir=$datadir --use_shell --groups ssh.app
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
@ -105,16 +111,16 @@ install_borg_with_pip
#================================================= #=================================================
ynh_script_progression --message="Seting good permissions..." ynh_script_progression --message="Seting good permissions..."
mkdir -p /home/$ssh_user/.ssh mkdir -p $datadir/.ssh
chmod o=--- /home/$ssh_user chmod o=--- $datadir
chown -R $ssh_user:$ssh_user /home/$ssh_user chown -R $ssh_user:$ssh_user $datadir
#================================================= #=================================================
# AVOID BACKUP OF BACKUP # AVOID BACKUP OF BACKUP
#================================================= #=================================================
ynh_script_progression --message="Avoiding to backup the backup itself..." ynh_script_progression --message="Avoiding to backup the backup itself..."
touch /home/$ssh_user/.nobackup touch $datadir/.nobackup
#================================================= #=================================================
# SETUP CRON # SETUP CRON