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

Merge pull request #110 from YunoHost-Apps/testing

Config panel
This commit is contained in:
ljf (zamentur) 2021-11-30 19:29:12 +01:00 committed by GitHub
commit 3ffe00899e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 185 additions and 18 deletions

View file

@ -22,15 +22,16 @@ You should received an email after the first backup succeeded.
### Set up Borg Backup App on guest Server A ### Set up Borg Backup App on guest Server A
Firstly, set up the Borg Backup App (`borg`) on the guest Server A you want to backup: Firstly, set up the Borg Backup App (`borg`) on the guest Server A you want to backup:
``` ```
$ yunohost app install borg $ yunohost app install borg
Indicate the domain name of server B where to upload backups: host.serverb In which borg repository location do you want to backup your files ?: user@host.serverb:/remote/repository
Indicate the ssh user to use to connect on this server: servera Provide a strong passphrase to encrypt your backups. No blank space:
Indicate a strong passphrase, that you will keep preciously if you want to be able to use your backups: N0tAW3akp4ssw0rdYoloMacN!guets Should Borg backup your YunoHost configuration? [yes | no] (default: yes):
Would you like to backup your YunoHost configuration ? [0 | 1] (default: 1): Should Borg backup emails and user home directory? [yes | no] (default: yes):
Would you like to backup mails and user home directory ? [0 | 1] (default: 1): Which apps should Borg backup ? (default: all):
Which apps would you backup (list separated by comma or 'all') ? (default: all): With which regular time schedule should the backups be performed? (see systemd OnCalendar format) (default: Daily):
Indicate the backup frequency (see systemd OnCalendar format) (default: Daily): Do you want admin to receive mail notifications on backups ? [always | errors_only | never]: never
``` ```
#### Syntax to define a backup time schedule #### Syntax to define a backup time schedule

View file

@ -22,6 +22,8 @@ filter_hooks() {
fail_if_partially_failed() { fail_if_partially_failed() {
grep Skipped|Error grep Skipped|Error
} }
sudo yunohost app setting ${borg_id} last_run -v "${current_date}"
sudo yunohost app setting ${borg_id} state -v "ongoing"
# Backup system part conf # Backup system part conf
conf=$(sudo yunohost app setting ${borg_id} conf) conf=$(sudo yunohost app setting ${borg_id} conf)
@ -74,6 +76,12 @@ fi
domain=$(hostname) domain=$(hostname)
repository="$(sudo yunohost app setting ${borg_id} repository)" repository="$(sudo yunohost app setting ${borg_id} repository)"
mailalert="$(sudo yunohost app setting ${borg_id} mailalert)" mailalert="$(sudo yunohost app setting ${borg_id} mailalert)"
if [[ ! -z "$errors" ]]; then
sudo yunohost app setting ${borg_id} state -v "failed"
else
sudo yunohost app setting ${borg_id} state -v "successful"
fi
if [[ ! -z "$errors" && $mailalert != "never" ]]; then if [[ ! -z "$errors" && $mailalert != "never" ]]; then
cat <(echo -e "$errors\n\n\n") "$log_file" "$err_file" | mail -s "[borg] Backup failed from $domain onto $repository" root cat <(echo -e "$errors\n\n\n") "$log_file" "$err_file" | mail -s "[borg] Backup failed from $domain onto $repository" root
exit 1 exit 1

77
config_panel.toml Normal file
View file

@ -0,0 +1,77 @@
version = "1.0"
[main]
services = []
[main.settings]
name = ""
visible = "false"
[main.settings.state]
type = "string"
[main.settings.last_run]
type = "string"
[main.general]
[main.general.info]
ask = """\
Backup state : {{state}}
Last run: {{last_run}}
"""
type = "alert"
style = "info"
[main.general.repository]
ask.en = "Repository"
type = "string"
help = "Specify a local repository like /mount/my_external_harddrive/backups or a remote repository using this format: ssh://USER@DOMAIN.TLD:PORT/~/backup . If you plan to use borgserver_ynh app : 'USER' is *not* meant to be an existing user on the guest server, instead, it will be created *on the host server* during the installation of the Borg Server App. With borgserver_ynh apps you can't specify another repo path than ~/backup."
[main.general.ssh_public_key]
ask.en = "Public key: {ssh_public_key}"
type = "markdown"
bind = "/root/.ssh/id___APP___ed25519.pub"
[main.general.on_calendar]
ask.en = "Frequency"
type = "string"
help = "With which regular time schedule should the backups be performed? (see systemd OnCalendar format)"
bind = "OnCalendar:/etc/systemd/system/__APP__.timer"
[main.general.mailalert]
ask.en = "Mail alert"
type = "select"
choices.always = "Always"
choices.errors_only = "Only if an error occured"
choices.never = "Never alert me"
help = "Alerts are sent to the first user of this server"
[main.content]
name = "What should be backuped ?"
optional = false
[main.content.conf]
ask.en = "Configuration"
type = "boolean"
[main.content.data]
ask.en = "Data"
type = "boolean"
[main.content.data_multimedia]
ask.en = "Data multimedia"
type = "boolean"
[main.content.apps]
ask.en = "Apps"
type = "tags"
help = "App list separated by comma. You can write 'all' to select all apps, even those installed after this borg app. You can also select all apps but some apps by writing 'exclude:' following by an app list separated by comma."
[advanced]
name = "Advanced"
services = []
[advanced.list]
name = "Last backups list"
[advanced.list.last_backups]
ask.en = ""
type = "markdown"

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.16~ynh24", "version": "1.1.16~ynh26",
"url": "https://borgbackup.readthedocs.io", "url": "https://borgbackup.readthedocs.io",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"maintainer": { "maintainer": {
@ -15,7 +15,7 @@
"url": "https://reflexlibre.net" "url": "https://reflexlibre.net"
}, },
"requirements": { "requirements": {
"yunohost": ">= 4.1.0" "yunohost": ">= 4.3.0"
}, },
"multi_instance": true, "multi_instance": true,
"services": [], "services": [],

View file

@ -12,7 +12,7 @@ pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev pyth
# 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 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 /opt/borg-env/bin/python /opt/borg-env/bin/pip list | grep "borgbackup *$BORG_VERSION" || ynh_secure_remove /opt/borg-env
fi 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

78
scripts/config Normal file
View file

@ -0,0 +1,78 @@
#!/bin/bash
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__info() {
cat << EOF
ask:
en: "**Backup state**: ${old[state]}
**Last run**: ${old[last_run]}"
EOF
if [ "${old[state]}" == "failed" ]; then
style: "danger"
EOF
elif [ "${old[state]}" == "successful" ]; then
cat << EOF
style: "success"
EOF
else
cat << EOF
style: "info"
EOF
fi
}
get__ssh_public_key() {
cat << EOF
ask:
en: "**Public key**: \`$(cat /root/.ssh/id_${app}_ed25519.pub || echo '')\`"
EOF
}
get__data_multimedia() {
if [ -e /home/yunohost.multimedia/.nobackup ]; then
echo "value: false"
else
echo "value: true"
fi
}
get__last_backups() {
cat << EOF
ask: |-
$(BORG_PASSPHRASE="$(yunohost app setting $app passphrase)" BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes " borg list --short --last 50 ${old[repository]} | sed 's/^/ /g' 2> /dev/null)
EOF
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
validate__on_calendar() {
(systemd-analyze calendar $on_calendar > /dev/null) ||
echo 'Please follow systemd OnCalendar format: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS'
}
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__data_multimedia() {
if [ "$data_multimedia" == "0" ]; then
mkdir -p /home/yunohost.multimedia/
touch /home/yunohost.multimedia/.nobackup
else
ynh_secure_remove /home/yunohost.multimedia/.nobackup
fi
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1

View file

@ -21,7 +21,6 @@ ynh_abort_if_errors
#================================================= #=================================================
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments # Retrieve arguments
ynh_export repository passphrase on_calendar conf data apps mailalert ynh_export repository passphrase on_calendar conf data apps mailalert
@ -36,7 +35,9 @@ if [[ $repository == *"@"* ]]; then
fi fi
ssh_user=$(echo "$repository" | cut -d"@" -f1 | cut -d"/" -f2) ssh_user=$(echo "$repository" | cut -d"@" -f1 | cut -d"/" -f2)
fi fi
ynh_save_args repository server passphrase on_calendar conf data apps mailalert state="repository uncreated"
last_run="-"
ynh_save_args repository server passphrase on_calendar conf data apps mailalert state last_run
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES

View file

@ -28,6 +28,8 @@ if [[ $mailalert != "always" && $mailalert != "errors_only" && $mailalert != "ne
ynh_app_setting_set --app=$app --key="mailalert" --value="errors_only" ynh_app_setting_set --app=$app --key="mailalert" --value="errors_only"
export mailalert="errors_only" export mailalert="errors_only"
fi fi
ynh_app_setting_set --app=$app --key="state" --value="not run since last update"
ynh_app_setting_set --app=$app --key="last_run" --value="-"
#================================================= #=================================================
# CHECK IF AN UPGRADE IS NEEDED # CHECK IF AN UPGRADE IS NEEDED