1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/restic_ynh.git synced 2024-09-03 20:16:22 +02:00
This commit is contained in:
Éric Gaspar 2023-11-25 19:42:40 +01:00
parent 6fd31642b8
commit 3278e6960b
10 changed files with 199 additions and 79 deletions

View file

@ -20,13 +20,13 @@ CHECK_READ_DATA=${1:-0}
# Check system part conf
conf=$(sudo yunohost app setting {{ app }} conf)
if [ $conf -eq 1 ];then
sudo {{final_path}}/check_method_{{ app }} auto_conf ${CHECK_READ_DATA}
sudo {{install_dir}}/check_method_{{ app }} auto_conf ${CHECK_READ_DATA}
fi
# Check system data
data=$(sudo yunohost app setting {{ app }} data)
if [ $data -eq 1 ];then
sudo {{final_path}}/check_method_{{ app }} auto_data ${CHECK_READ_DATA}
sudo {{install_dir}}/check_method_{{ app }} auto_data ${CHECK_READ_DATA}
fi
# Check all apps independently
@ -40,7 +40,7 @@ for app in $(sudo /usr/bin/find /etc/yunohost/apps -name backup | cut -d / -f 5)
fi
done
if [ "$check_app" == "true" ];then
sudo {{final_path}}/check_method_{{ app }} auto_${app} ${CHECK_READ_DATA}
sudo {{install_dir}}/check_method_{{ app }} auto_${app} ${CHECK_READ_DATA}
fi
done
rm "$LOCK_FILE"

View file

@ -4,7 +4,7 @@ After=network.target
[Service]
Type=oneshot
ExecStart=__FINALPATH__/check-__APP__
ExecStart=__INSTALL_DIR__/check-__APP__
ExecStartPost=/opt/yunohost/__APP__/restic_check_log___APP__ 0
User=__APP__
Group=__APP__

View file

@ -4,7 +4,7 @@ After=network.target
[Service]
Type=oneshot
ExecStart=__FINALPATH__/check-__APP__ "1"
ExecStart=__INSTALL_DIR__/check-__APP__ "1"
ExecStartPost=/opt/yunohost/__APP__/restic_check_log___APP__ 1
User=__APP__
Group=__APP__

120
manifest.toml Normal file
View file

@ -0,0 +1,120 @@
packaging_format = 2
id = "restic"
name = "Restic"
description.en = "Backup your server with Restic"
description.fr = "Sauvegardez votre serveur avec Restic"
version = "0.12.0~ynh9"
maintainers = ["Lionel Coupouchetty-Ramouchetty"]
[upstream]
license = "BSD-2-Clause"
website = "https://restic.net"
admindoc = "https://restic.readthedocs.io/en/latest/"
code = "https://github.com/restic/restic"
cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number)
fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin.
[integration]
yunohost = ">= 11.2"
architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"]
multi_instance = true
ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials.
sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal.
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.server]
ask.en = "Indicate the server where you want put your backups"
ask.fr = "Indiquez le serveur où vous voulez faire vos sauvegardes"
help.en = "IP address or resolvable hostname of your destination server"
help.fr = "Adresse IP ou nom résolvable de votre serveur de destination"
type = "string"
example = "example.com"
[install.port]
ask.en = "sftp port of your server"
ask.fr = "Le port sftp de votre serveur"
help.en = "Listening port of your sftp or ssh server. The default value is 22"
help.fr = "Le port d'écoute de votre serveur sftp ou ssh. La valeur par défaut est 22"
type = "string"
example = "22"
default = "22"
[install.backup_path]
ask.en = "The directory where you want your backup repositories to be created in"
ask.fr = "Le répertoire dans lequel les dépôts restic seront créés"
help.en = "A complete or relative path to an existing directory on the remote server writable by the remote backup user. Defaults to the login directory"
help.fr = "Un chemin complet ou relatif vers un répertoire existant sur le serveur distant et accessible en écriture au compte utilisé pour la sauvegarde. Répertoire d'accueil par défaut"
type = "string"
example = "./backups"
default = "."
[install.ssh_user]
ask.en = "Indicate the ssh user to use to connect on this server"
ask.fr = "Indiquez l'utilisateur ssh à utiliser pour se connecter au serveur"
type = "string"
example = "john"
[install.passphrase]
ask.en = "Indicate a strong passphrase, that you will keep preciously if you want to be able to use your backups"
ask.fr = "Indiquez une phrase de passe forte que vous garderez précieusement si vous voulez être en mesure d'utiliser vos sauvegardes"
type = "password"
[install.conf]
ask.en = "Would you like to backup your YunoHost configuration ?"
ask.fr = "Souhaitez-vous effectuer des sauvegardes des configurations du système YunoHost ?"
type = "boolean"
default = true
[install.data]
ask.en = "Would you like to backup mails and user home directory ?"
ask.fr = "Souhaitez-vous effectuer des sauvegardes des mails et des répertoire des utilisateurs ?"
type = "boolean"
default = true
[install.apps]
ask.en = "Which apps would you backup (list separated by comma or 'all') ?"
ask.fr = "Souhaitez-vous effectuer des sauvegardes de vos applications ?"
type = "string"
default = "all"
[install.allow_extra_space_use]
ask.en = "Allow backup method to temporarily use more space?"
ask.fr = "Permettre à la sauvegarde de consommer temporairement de l'espace supplémentaire?"
help.en = "Some applications as Gitlab can't be backed up with the standard method and require extra space temporarily"
help.fr = "Certaines applications comme Gitlab ne peuvent être sauvegardées avec la méthode standard et nécessitent d'utiliser plus d'espace disque temporairement"
type = "boolean"
default = true
[install.on_calendar]
ask.en = "Indicate the backup frequency (see systemd OnCalendar format)"
ask.fr = "Indiquez la fréquence de la sauvegarde (voir le format OnCalendar de systemd)"
type = "string"
example = "Daily"
default = "*-*-* 0:15:00"
[install.check_on_calendar]
ask.en = "Indicate the backup check frequency (see systemd OnCalendar format)"
ask.fr = "Indiquez la fréquence de vérification de la sauvegarde (voir le format OnCalendar de systemd)"
type = "string"
example = "Tue *-*-* 00:15:00"
default = "Sat *-*-8..31 3:15:00"
[install.check_read_data_on_calendar]
ask.en = "Indicate the complete backup check frequency (see systemd OnCalendar format)"
ask.fr = "Indiquez la fréquence de vérification complète de la sauvegarde (voir le format OnCalendar de systemd)"
type = "string"
example = "Tue *-*-* 00:15:00"
default = "Sat *-*-1..7 3:15:00"
[resources]
[resources.system_user]
[resources.install_dir]
[resources.permissions]

View file

@ -50,10 +50,10 @@ ynh_export () {
for var in $@;
do
ynh_arg=$(echo $var | awk '{print toupper($0)}')
if [ "$var" == "path_url" ]; then
if [ "$var" == "path" ]; then
ynh_arg="PATH"
fi
ynh_arg="YNH_APP_ARG_$ynh_arg"
#REMOVEME? ynh_arg="YNH_APP_ARG_$ynh_arg"
export $var="${!ynh_arg}"
done
}
@ -63,7 +63,7 @@ ynh_save_args () {
for var in $@;
do
local setting_var="$var"
if [ "$var" == "path_url" ]; then
if [ "$var" == "path" ]; then
setting_var="path"
fi
ynh_app_setting_set $app $setting_var "${!var}"

View file

@ -15,15 +15,15 @@ source /usr/share/yunohost/helpers
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
#REMOVEME? ynh_print_info --message="Loading installation settings..."
export app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}"
#REMOVEME? export app=$YNH_APP_INSTANCE_NAME
export install_dir="/opt/yunohost/${app}"
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
@ -43,8 +43,8 @@ ynh_backup "/etc/systemd/system/${app}_check.timer"
ynh_backup "/etc/systemd/system/${app}_check_read_data.service"
ynh_backup "/etc/systemd/system/${app}_check_read_data.timer"
ynh_backup "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_backup "${final_path}/check_method_${app}"
ynh_backup "${final_path}/restic_log_${app}"
ynh_backup "${install_dir}/check_method_${app}"
ynh_backup "${install_dir}/restic_log_${app}"
ssh_dir="/root/.ssh"
ynh_backup "${ssh_dir}/id_${app}_ed25519"
ynh_backup "${ssh_dir}/id_${app}_ed25519.pub"

View file

@ -13,17 +13,17 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
export app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}"
#REMOVEME? export app=$YNH_APP_INSTANCE_NAME
export install_dir="/opt/yunohost/${app}"
# Retrieve arguments
ynh_export server port ssh_user backup_path passphrase on_calendar check_on_calendar check_read_data_on_calendar conf data apps allow_extra_space_use
@ -31,7 +31,7 @@ ynh_export server port ssh_user backup_path passphrase on_calendar check_on_cale
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
#REMOVEME? ynh_script_progression --message="Storing installation settings..."
ynh_save_args server port ssh_user backup_path passphrase on_calendar check_on_calendar check_read_data_on_calendar conf data apps allow_extra_space_use
@ -52,7 +52,7 @@ useradd -m ${app}
ynh_script_progression --message="Configure ${app} user sudoer rights"
cat > /tmp/${app}_sudoer << EOSUDOER
${app} ALL = (root) NOPASSWD: /usr/bin/yunohost*, /bin/journalctl*, /usr/bin/find /etc/yunohost/apps -name backup, ${final_path}/check_method_${app}
${app} ALL = (root) NOPASSWD: /usr/bin/yunohost*, /bin/journalctl*, /usr/bin/find /etc/yunohost/apps -name backup, ${install_dir}/check_method_${app}
EOSUDOER
visudo -cf /tmp/${app}_sudoer && mv /tmp/${app}_sudoer /etc/sudoers.d/${app}
@ -70,21 +70,21 @@ mkdir -p /usr/share/yunohost/backup_method
ynh_script_progression --message="Setting up backup methods"
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_configure check_method "${final_path}/check_method_${app}"
ynh_configure check_method "${install_dir}/check_method_${app}"
#=================================================
# SETUP LOG SCRIPTS
#=================================================
ynh_script_progression --message="Setting up backup log script"
ynh_configure restic_log "${final_path}/restic_log_${app}"
chmod +x "${final_path}/restic_log_${app}"
chown ${app}: "${final_path}/restic_log_${app}"
ynh_configure restic_log "${install_dir}/restic_log_${app}"
chmod +x "${install_dir}/restic_log_${app}"
chown ${app}: "${install_dir}/restic_log_${app}"
ynh_script_progression --message="Setting up check log script"
ynh_configure restic_check_log "${final_path}/restic_check_log_${app}"
chmod +x "${final_path}/restic_check_log_${app}"
chown ${app}: "${final_path}/restic_check_log_${app}"
ynh_configure restic_check_log "${install_dir}/restic_check_log_${app}"
chmod +x "${install_dir}/restic_check_log_${app}"
chown ${app}: "${install_dir}/restic_check_log_${app}"
#=================================================
# CONFIGURE CRON
@ -92,11 +92,11 @@ chown ${app}: "${final_path}/restic_check_log_${app}"
ynh_script_progression --message="Configuring cron" --weight=5
ynh_configure backup-with-restic "/usr/local/bin/backup-with-${app}"
ynh_configure check-restic "${final_path}/check-${app}"
ynh_configure check-restic "${install_dir}/check-${app}"
chmod +x "/usr/local/bin/backup-with-${app}"
chown ${app}: "/usr/local/bin/backup-with-${app}"
chmod +x "${final_path}/check-${app}"
chmod +x "${final_path}/check_method_${app}"
chmod +x "${install_dir}/check-${app}"
chmod +x "${install_dir}/check_method_${app}"
ynh_add_systemd_config --service=${app} --template=systemd.service
ynh_add_systemd_config --service=${app}_check --template=systemd_check.service
ynh_add_systemd_config --service=${app}_check_read_data --template=systemd_check_read_data.service
@ -116,9 +116,9 @@ systemctl start ${app}_check_read_data.timer
#=================================================
# SET PERMISSIONS ON FINAL PATH
#=================================================
ynh_script_progression --message="Set permissions on ${final_path}"
ynh_script_progression --message="Set permissions on ${install_dir}"
chown -R ${app}: ${final_path}
chown -R ${app}: ${install_dir}
#=================================================
# SETUP LOGROTATE

View file

@ -12,10 +12,10 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}"
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
export install_dir="/opt/yunohost/${app}"
#=================================================
# REMOVE LOGROTATE CONFIGURATION
@ -28,10 +28,10 @@ ynh_remove_logrotate
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=4
#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=4
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#REMOVEME? ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
@ -50,11 +50,11 @@ ynh_secure_remove "/etc/systemd/system/${app}_check.timer"
ynh_secure_remove "/etc/systemd/system/${app}_check_read_data.timer"
ynh_secure_remove "/usr/local/bin/backup-with-${app}"
ynh_secure_remove "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_secure_remove "${final_path}/check_method_${app}"
ynh_secure_remove "${final_path}/check-${app}"
ynh_secure_remove "${final_path}/restic_log_${app}"
ynh_secure_remove "${final_path}/restic_check_log_${app}"
ynh_secure_remove "${final_path}"
ynh_secure_remove "${install_dir}/check_method_${app}"
ynh_secure_remove "${install_dir}/check-${app}"
ynh_secure_remove "${install_dir}/restic_log_${app}"
ynh_secure_remove "${install_dir}/restic_check_log_${app}"
ynh_secure_remove "${install_dir}"
#=================================================
# REMOVE SSH CONFIG

View file

@ -14,22 +14,22 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
export app=$YNH_APP_INSTANCE_NAME
#REMOVEME? export app=$YNH_APP_INSTANCE_NAME
export server=$(ynh_app_setting_get --app=$app --key=server)
#REMOVEME? export server=$(ynh_app_setting_get --app=$app --key=server)
export final_path="/opt/yunohost/${app}"
export install_dir="/opt/yunohost/${app}"
#=================================================
# INSTALL RESTIC

View file

@ -12,23 +12,23 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
export app=$YNH_APP_INSTANCE_NAME
#REMOVEME? export app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}"
export server=$(ynh_app_setting_get $app server)
export port=$(ynh_app_setting_get $app port)
export ssh_user=$(ynh_app_setting_get $app ssh_user)
export backup_path=$(ynh_app_setting_get $app backup_path)
export passphrase=$(ynh_app_setting_get $app passphrase)
export on_calendar=$(ynh_app_setting_get $app on_calendar)
export check_on_calendar=$(ynh_app_setting_get $app check_on_calendar)
export check_read_data_on_calendar=$(ynh_app_setting_get $app check_read_data_on_calendar)
export conf=$(ynh_app_setting_get $app conf)
export data=$(ynh_app_setting_get $app data)
export apps=$(ynh_app_setting_get $app apps)
export allow_extra_space_use=$(ynh_app_setting_get $app allow_extra_space_use)
export install_dir="/opt/yunohost/${app}"
#REMOVEME? export server=$(ynh_app_setting_get $app server)
#REMOVEME? export port=$(ynh_app_setting_get $app port)
#REMOVEME? export ssh_user=$(ynh_app_setting_get $app ssh_user)
#REMOVEME? export backup_path=$(ynh_app_setting_get $app backup_path)
#REMOVEME? export passphrase=$(ynh_app_setting_get $app passphrase)
#REMOVEME? export on_calendar=$(ynh_app_setting_get $app on_calendar)
#REMOVEME? export check_on_calendar=$(ynh_app_setting_get $app check_on_calendar)
#REMOVEME? export check_read_data_on_calendar=$(ynh_app_setting_get $app check_read_data_on_calendar)
#REMOVEME? export conf=$(ynh_app_setting_get $app conf)
#REMOVEME? export data=$(ynh_app_setting_get $app data)
#REMOVEME? export apps=$(ynh_app_setting_get $app apps)
#REMOVEME? export allow_extra_space_use=$(ynh_app_setting_get $app allow_extra_space_use)
#=================================================
# CHECK VERSION
@ -39,17 +39,17 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
if grep "${app}.timer" /etc/yunohost/services.yml > /dev/null ; then
@ -73,7 +73,7 @@ ynh_script_progression --message="Creating user ${app}"
id ${app} 2>/dev/null || useradd -m ${app}
ynh_script_progression --message="Configure ${app} user sudoer rights"
cat > /tmp/${app}_sudoer << EOSUDOER
${app} ALL = (root) NOPASSWD: /usr/bin/yunohost*, /bin/journalctl*, /usr/bin/find /etc/yunohost/apps -name backup, ${final_path}/check_method_${app}
${app} ALL = (root) NOPASSWD: /usr/bin/yunohost*, /bin/journalctl*, /usr/bin/find /etc/yunohost/apps -name backup, ${install_dir}/check_method_${app}
EOSUDOER
visudo -cf /tmp/${app}_sudoer && mv /tmp/${app}_sudoer /etc/sudoers.d/${app}
ynh_script_progression --message="Move ssh keys from root to ${app} user's home"
@ -116,21 +116,21 @@ mkdir -p /usr/share/yunohost/backup_method
ynh_script_progression --message="Setting up backup methods"
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_configure check_method "${final_path}/check_method_${app}"
ynh_configure check_method "${install_dir}/check_method_${app}"
#=================================================
# SETUP LOG SCRIPTS
#=================================================
ynh_script_progression --message="Setting up backup log script"
ynh_configure restic_log "${final_path}/restic_log_${app}"
chmod +x "${final_path}/restic_log_${app}"
chown ${app}: "${final_path}/restic_log_${app}"
ynh_configure restic_log "${install_dir}/restic_log_${app}"
chmod +x "${install_dir}/restic_log_${app}"
chown ${app}: "${install_dir}/restic_log_${app}"
ynh_script_progression --message="Setting up check log script"
ynh_configure restic_check_log "${final_path}/restic_check_log_${app}"
chmod +x "${final_path}/restic_check_log_${app}"
chown ${app}: "${final_path}/restic_check_log_${app}"
ynh_configure restic_check_log "${install_dir}/restic_check_log_${app}"
chmod +x "${install_dir}/restic_check_log_${app}"
chown ${app}: "${install_dir}/restic_check_log_${app}"
#=================================================
# CONFIGURE CRON
@ -138,11 +138,11 @@ chown ${app}: "${final_path}/restic_check_log_${app}"
ynh_script_progression --message="Configuring cron" --weight=5
ynh_configure backup-with-restic "/usr/local/bin/backup-with-${app}"
ynh_configure check-restic "${final_path}/check-${app}"
ynh_configure check-restic "${install_dir}/check-${app}"
chmod +x "/usr/local/bin/backup-with-${app}"
chown ${app}: "/usr/local/bin/backup-with-${app}"
chmod +x "${final_path}/check-${app}"
chmod +x "${final_path}/check_method_${app}"
chmod +x "${install_dir}/check-${app}"
chmod +x "${install_dir}/check_method_${app}"
ynh_add_systemd_config --service=${app} --template=systemd.service
ynh_add_systemd_config --service=${app}_check --template=systemd_check.service
ynh_add_systemd_config --service=${app}_check_read_data --template=systemd_check_read_data.service