mirror of
https://github.com/YunoHost-Apps/restic_ynh.git
synced 2024-09-03 20:16:22 +02:00
Apply last example_ynh
This commit is contained in:
parent
526944051f
commit
43f540b0a9
12 changed files with 290 additions and 75 deletions
|
@ -1,29 +1,31 @@
|
||||||
;; Test complet
|
;; Test complet
|
||||||
; Manifest
|
; Manifest
|
||||||
server="dst.domain.tld"
|
server="dst.domain.tld"
|
||||||
ssh_user="sam"
|
ssh_user="sam"
|
||||||
passphrase="APassphrase"
|
passphrase="APassphrase"
|
||||||
conf=1
|
conf=1
|
||||||
port=2222
|
port=2222
|
||||||
backup_path=src.domain.tld
|
backup_path=src.domain.tld
|
||||||
data=1
|
data=1
|
||||||
app="all"
|
app="all"
|
||||||
allow_extra_space_use=1
|
allow_extra_space_use=1
|
||||||
on_calendar="Daily"
|
on_calendar="Daily"
|
||||||
check_on_calendar="*-*-8,15,22 3:15"
|
check_on_calendar="*-*-8,15,22 3:15"
|
||||||
check_read_data_on_calendar="*-*-1 3:15"
|
check_read_data_on_calendar="*-*-1 3:15"
|
||||||
; Checks
|
; Checks
|
||||||
pkg_linter=1
|
pkg_linter=1
|
||||||
setup_sub_dir=0
|
setup_sub_dir=0
|
||||||
setup_root=0
|
setup_root=0
|
||||||
setup_nourl=1
|
setup_nourl=1
|
||||||
setup_private=0
|
setup_private=0
|
||||||
setup_public=0
|
setup_public=0
|
||||||
upgrade=1
|
upgrade=1
|
||||||
backup_restore=1
|
# 0.12.0~ynh9
|
||||||
multi_instance=1
|
upgrade=1 from_commit=526944051f68f4149e415be4e862ce3c69d69f18
|
||||||
port_already_use=0
|
backup_restore=1
|
||||||
change_url=0
|
multi_instance=1
|
||||||
|
port_already_use=0
|
||||||
|
change_url=0
|
||||||
;;; Options
|
;;; Options
|
||||||
Email=restic-ynh@coupouchetty-ramouchetty.fr
|
Email=restic-ynh@coupouchetty-ramouchetty.fr
|
||||||
Notification=down
|
Notification=down
|
||||||
|
|
0
doc/.gitkeep
Normal file
0
doc/.gitkeep
Normal file
7
doc/DESCRIPTION.md
Normal file
7
doc/DESCRIPTION.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
A [Restic](https://restic.net/) package for YunoHost (heavily inspired by [the Borg package](https://github.com/YunoHost-Apps/borg_ynh/)).
|
||||||
|
|
||||||
|
Restic is a backup tool that can make local and remote backups.
|
||||||
|
This package uses restic to make backups to a sftp server.
|
||||||
|
The package does not handle local backups yet but you can work around that by using the local sftp server as target server (see my comment [here](https://forum.yunohost.org/t/sauvegarde-yunohost-avec-restic/10275/33)).
|
143
doc/DISCLAIMER.md
Normal file
143
doc/DISCLAIMER.md
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
If you want to backup your server A onto the server B.
|
||||||
|
|
||||||
|
## Setup Restic app on Server A
|
||||||
|
|
||||||
|
Firstly set up this app on the server A you want to backup:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ yunohost app install https://github.com/YunoHost-Apps/restic_ynh
|
||||||
|
Indicate the server where you want put your backups: serverb.domain.tld
|
||||||
|
sftp port of your server (default: 22): 2222
|
||||||
|
The directory where you want your backup repositories to be created in (default: ./): ./servera.domain.tld
|
||||||
|
Indicate the ssh user to use to connect on this server: servera
|
||||||
|
You are now about to define a new user password. The password should be at least 8 characters - though it is good practice to use longer password (i.e. a passphrase) and/or to use various kind of characters (uppercase, lowercase, digits and special characters).
|
||||||
|
Indicate a strong passphrase, that you will keep preciously if you want to be able to use your backups:
|
||||||
|
Would you like to backup your YunoHost configuration ? [yes | no] (default: yes):
|
||||||
|
Would you like to backup mails and user home directory ? [yes | no] (default: yes):
|
||||||
|
Which apps would you backup (list separated by comma or 'all') ? (default: all): gitlab,blogotext,sogo
|
||||||
|
Allow backup method to temporarily use more space? [yes | no] (default: yes):
|
||||||
|
Indicate the backup frequency (see systemd OnCalendar format) (default: *-*-* 0:15:00): *-*-* 0:05
|
||||||
|
Indicate the backup check frequency (see systemd OnCalendar format) (default: Sat *-*-8..31 3:15:00):
|
||||||
|
Indicate the complete backup check frequency (see systemd OnCalendar format) (default: Sun *-*-1..7 3:15:00):
|
||||||
|
```
|
||||||
|
|
||||||
|
You can schedule your backup by choosing an other frequency. Some example:
|
||||||
|
|
||||||
|
Monthly :
|
||||||
|
|
||||||
|
Weekly :
|
||||||
|
|
||||||
|
Daily : Daily at midnight
|
||||||
|
|
||||||
|
Hourly : Hourly o Clock
|
||||||
|
|
||||||
|
Sat *-*-1..7 18:00:00 : The first saturday of every month at 18:00
|
||||||
|
|
||||||
|
4:00 : Every day at 4 AM
|
||||||
|
|
||||||
|
5,17:00 : Every day at 5 AM and at 5 PM
|
||||||
|
|
||||||
|
See here for more info : https://wiki.archlinux.org/index.php/Systemd/Timers#Realtime_timer
|
||||||
|
|
||||||
|
After each invocation an e-mail will be sent to root@yourdomain.tld with the execution log.
|
||||||
|
|
||||||
|
Restic can check backups consistency and verify the actual backed up data has not been modified.
|
||||||
|
If you use the default values for the backup checks frequencies, a full check will be made on the first day of each month and a simple check will be made on each one of the three remaining weeks of the month.
|
||||||
|
|
||||||
|
At the end of the installation, the app displays the public_key and the user to give to the person who has access to the server B.
|
||||||
|
|
||||||
|
You should now authorize the public key for user `servera` on server B by logging into server B with user `servera` and running:
|
||||||
|
|
||||||
|
```
|
||||||
|
mkdir ~/.ssh -p 2>/dev/null
|
||||||
|
touch ~/.ssh/authorized_keys
|
||||||
|
chmod u=rw,go= ~/.ssh/authorized_keys
|
||||||
|
cat << EOPKEY >> ~/.ssh/authorized_keys
|
||||||
|
<paste here the privakey displayed at the end of installation>
|
||||||
|
EOPKEY
|
||||||
|
```
|
||||||
|
If you don't find the mail and you don't see the message in the log bar you can find the public_key with this command:
|
||||||
|
```
|
||||||
|
cat /root/.ssh/id_restic_ed25519.pub
|
||||||
|
```
|
||||||
|
|
||||||
|
## (Optional) set sftp jail on server B
|
||||||
|
|
||||||
|
To improve security, make sure user `servera` can only do sftp and can only access his home directory on server B.
|
||||||
|
This is how you would do it on Debian/Ubuntu, otherwise refer to your distribution manual (don't forget to replace `servera` with the real username)
|
||||||
|
|
||||||
|
```
|
||||||
|
cat << EOCONFIG >> /etc/ssh/sshd_config
|
||||||
|
Match User servera
|
||||||
|
ChrootDirectory %h
|
||||||
|
ForceCommand internal-sftp
|
||||||
|
AllowTcpForwarding no
|
||||||
|
X11Forwarding no
|
||||||
|
EOCONFIG
|
||||||
|
service ssh restart
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
At this step your backup should schedule.
|
||||||
|
|
||||||
|
If you want to be sure, you can test it by running on server A:
|
||||||
|
```
|
||||||
|
systemctl start restic.service
|
||||||
|
```
|
||||||
|
|
||||||
|
Next you can verify the backup contents by running on server A
|
||||||
|
```
|
||||||
|
restic -r sftp:serverb.domain.tld:servera.domain.tld/auto_conf snapshots
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `auto_conf` with `auto_<app>` if you did not choose to backup configuration but only applications.
|
||||||
|
|
||||||
|
If you want to check the backups consistency:
|
||||||
|
```
|
||||||
|
systemctl start restic_check.service
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to make a complete check of the backups - keep in mind that this reads all the backed up data, it can take some time depending on your target server upload speed (more on this topic in [the Restic documentation](https://restic.readthedocs.io/en/latest/045_working_with_repos.html#checking-integrity-and-consistency)):
|
||||||
|
```
|
||||||
|
systemctl start restic_check_read_data.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Display the apps list to backup
|
||||||
|
|
||||||
|
```
|
||||||
|
yunohost app setting restic apps
|
||||||
|
```
|
||||||
|
|
||||||
|
## Edit the apps list to backup
|
||||||
|
|
||||||
|
```
|
||||||
|
yunohost app setting restic apps -v "nextcloud,wordpress"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Launch a backup
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl start restic
|
||||||
|
```
|
||||||
|
|
||||||
|
## Launch a backups check
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl start restic_check.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Launch a complete backups check
|
||||||
|
|
||||||
|
WARNING: this will read data from your backups destination server.
|
||||||
|
It may take a quite long time depending on the target server's internet upload speed and hardware performance.
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl start restic_check_read_data.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Backup on different server, and apply distinct schedule for apps
|
||||||
|
|
||||||
|
You can setup the Restic app several times on the same server so you can backup on several server or manage your frequency backup differently for specific part of your server.
|
||||||
|
|
0
doc/screenshots/.gitkeep
Normal file
0
doc/screenshots/.gitkeep
Normal file
|
@ -8,6 +8,12 @@
|
||||||
},
|
},
|
||||||
"version": "0.12.0~ynh9",
|
"version": "0.12.0~ynh9",
|
||||||
"url": "https://restic.net/",
|
"url": "https://restic.net/",
|
||||||
|
"upstream": {
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"website": "https://restic.net",
|
||||||
|
"admindoc": "https://restic.readthedocs.io/en/latest/",
|
||||||
|
"code": "https://github.com/restic/restic"
|
||||||
|
},
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "Lionel Coupouchetty-Ramouchetty",
|
"name": "Lionel Coupouchetty-Ramouchetty",
|
||||||
|
@ -15,7 +21,7 @@
|
||||||
"url": "https://gnoobix.net"
|
"url": "https://gnoobix.net"
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">= 3.6.5.3"
|
"yunohost": ">= 4.3.0"
|
||||||
},
|
},
|
||||||
"multi_instance": true,
|
"multi_instance": true,
|
||||||
"services": [],
|
"services": [],
|
||||||
|
|
|
@ -131,26 +131,4 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
|
||||||
|
|
||||||
# Send the email to the recipients
|
# Send the email to the recipients
|
||||||
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
|
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_debian_release () {
|
|
||||||
lsb_release --codename --short
|
|
||||||
}
|
|
||||||
|
|
||||||
is_stretch () {
|
|
||||||
if [ "$(ynh_debian_release)" == "stretch" ]
|
|
||||||
then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
is_jessie () {
|
|
||||||
if [ "$(ynh_debian_release)" == "jessie" ]
|
|
||||||
then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
|
@ -6,6 +6,8 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -18,13 +20,19 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info --message="Loading installation settings..."
|
||||||
|
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
export final_path="/opt/yunohost/${app}"
|
export final_path="/opt/yunohost/${app}"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Declaring files to be backed up..."
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP FILES
|
# BACKUP VARIOUS FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup "/usr/local/bin/backup-with-$app"
|
ynh_backup "/usr/local/bin/backup-with-$app"
|
||||||
|
@ -41,3 +49,9 @@ ssh_dir="/root/.ssh"
|
||||||
ynh_backup "${ssh_dir}/id_${app}_ed25519"
|
ynh_backup "${ssh_dir}/id_${app}_ed25519"
|
||||||
ynh_backup "${ssh_dir}/id_${app}_ed25519.pub"
|
ynh_backup "${ssh_dir}/id_${app}_ed25519.pub"
|
||||||
ynh_backup "${ssh_dir}/config"
|
ynh_backup "${ssh_dir}/config"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||||
|
|
|
@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
ynh_clean_check_starting
|
||||||
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
@ -28,20 +31,26 @@ ynh_export server port ssh_user backup_path passphrase on_calendar check_on_cale
|
||||||
#=================================================
|
#=================================================
|
||||||
# STORE SETTINGS FROM MANIFEST
|
# STORE SETTINGS FROM MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
|
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
|
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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL RESTIC
|
# INSTALL RESTIC
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing restic binary" --weight=7
|
ynh_script_progression --message="Installing restic binary" --weight=7
|
||||||
|
|
||||||
install_restic
|
install_restic
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE APP USER
|
# CREATE APP USER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Creating user ${app}"
|
ynh_script_progression --message="Creating user ${app}"
|
||||||
|
|
||||||
useradd -m ${app}
|
useradd -m ${app}
|
||||||
|
|
||||||
ynh_script_progression --message="Configure ${app} user sudoer rights"
|
ynh_script_progression --message="Configure ${app} user sudoer rights"
|
||||||
|
|
||||||
cat > /tmp/${app}_sudoer << EOSUDOER
|
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, ${final_path}/check_method_${app}
|
||||||
EOSUDOER
|
EOSUDOER
|
||||||
|
@ -51,6 +60,7 @@ visudo -cf /tmp/${app}_sudoer && mv /tmp/${app}_sudoer /etc/sudoers.d/${app}
|
||||||
# ACTIVATE BACKUP METHODS
|
# ACTIVATE BACKUP METHODS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Activating backup methods"
|
ynh_script_progression --message="Activating backup methods"
|
||||||
|
|
||||||
mkdir -p /etc/yunohost/hooks.d/backup_method
|
mkdir -p /etc/yunohost/hooks.d/backup_method
|
||||||
mkdir -p /usr/share/yunohost/backup_method
|
mkdir -p /usr/share/yunohost/backup_method
|
||||||
|
|
||||||
|
@ -58,6 +68,7 @@ mkdir -p /usr/share/yunohost/backup_method
|
||||||
# SETUP THE BACKUP METHOD
|
# SETUP THE BACKUP METHOD
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Setting up backup methods"
|
ynh_script_progression --message="Setting up backup methods"
|
||||||
|
|
||||||
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"
|
||||||
ynh_configure check_method "${final_path}/check_method_${app}"
|
ynh_configure check_method "${final_path}/check_method_${app}"
|
||||||
|
|
||||||
|
@ -78,6 +89,7 @@ chown ${app}: "${final_path}/restic_check_log_${app}"
|
||||||
# CONFIGURE CRON
|
# CONFIGURE CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring cron" --weight=5
|
ynh_script_progression --message="Configuring cron" --weight=5
|
||||||
|
|
||||||
ynh_configure backup-with-restic "/usr/local/bin/backup-with-${app}"
|
ynh_configure backup-with-restic "/usr/local/bin/backup-with-${app}"
|
||||||
ynh_configure check-restic "${final_path}/check-${app}"
|
ynh_configure check-restic "${final_path}/check-${app}"
|
||||||
chmod +x "/usr/local/bin/backup-with-${app}"
|
chmod +x "/usr/local/bin/backup-with-${app}"
|
||||||
|
@ -104,12 +116,14 @@ systemctl start ${app}_check_read_data.timer
|
||||||
# SET PERMISSIONS ON FINAL PATH
|
# SET PERMISSIONS ON FINAL PATH
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Set permissions on ${final_path}"
|
ynh_script_progression --message="Set permissions on ${final_path}"
|
||||||
|
|
||||||
chown -R ${app}: ${final_path}
|
chown -R ${app}: ${final_path}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring logrotate"
|
ynh_script_progression --message="Configuring logrotate"
|
||||||
|
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.log
|
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.log
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.err
|
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.err
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log
|
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log
|
||||||
|
@ -130,6 +144,7 @@ test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key
|
||||||
# GENERATE SSH CONFIG
|
# GENERATE SSH CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Generating ssh config for ${app} server ${server}"
|
ynh_script_progression --message="Generating ssh config for ${app} server ${server}"
|
||||||
|
|
||||||
grep -q "${app}" ${ssh_dir}/config 2>/dev/null || cat << EOCONF >> ${ssh_dir}/config
|
grep -q "${app}" ${ssh_dir}/config 2>/dev/null || cat << EOCONF >> ${ssh_dir}/config
|
||||||
# begin $app ssh config
|
# begin $app ssh config
|
||||||
Host ${server}
|
Host ${server}
|
||||||
|
@ -145,8 +160,8 @@ EOCONF
|
||||||
#=================================================
|
#=================================================
|
||||||
# Display key
|
# Display key
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
ynh_script_progression --message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
||||||
|
|
||||||
$(cat ${private_key}.pub)"
|
$(cat ${private_key}.pub)"
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,3 +188,9 @@ If you're facing an issue or want to improve this app, please open a new issue i
|
||||||
|
|
||||||
ynh_send_readme_to_admin "$message" "root"
|
ynh_send_readme_to_admin "$message" "root"
|
||||||
ynh_print_ON
|
ynh_print_ON
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Installation of $app completed"
|
||||||
|
|
|
@ -12,20 +12,34 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
export final_path="/opt/yunohost/${app}"
|
export final_path="/opt/yunohost/${app}"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing logrotate configuration..."
|
||||||
|
|
||||||
|
# Remove the app-specific logrotate config
|
||||||
|
ynh_remove_logrotate
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE DEPENDENCIES
|
# REMOVE DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing dependencies" --weight=4
|
ynh_script_progression --message="Removing dependencies..." --weight=4
|
||||||
|
|
||||||
|
# Remove metapackage and its dependencies
|
||||||
ynh_remove_app_dependencies
|
ynh_remove_app_dependencies
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE FILES
|
# SPECIFIC REMOVE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing files" --weight=2
|
# REMOVE VARIOUS FILES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing various files..." --weight=2
|
||||||
|
|
||||||
systemctl stop ${app}.timer
|
systemctl stop ${app}.timer
|
||||||
systemctl --quiet disable ${app}.timer
|
systemctl --quiet disable ${app}.timer
|
||||||
ynh_remove_systemd_config --service=${app}
|
ynh_remove_systemd_config --service=${app}
|
||||||
|
@ -42,23 +56,27 @@ ynh_secure_remove "${final_path}/restic_log_${app}"
|
||||||
ynh_secure_remove "${final_path}/restic_check_log_${app}"
|
ynh_secure_remove "${final_path}/restic_check_log_${app}"
|
||||||
ynh_secure_remove "${final_path}"
|
ynh_secure_remove "${final_path}"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# REMOVE LOGROTATE CONFIG
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing logrotate config"
|
|
||||||
ynh_remove_logrotate
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE SSH CONFIG
|
# REMOVE SSH CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing ssh config"
|
ynh_script_progression --message="Removing ssh config"
|
||||||
|
|
||||||
ssh_dir="/root/.ssh"
|
ssh_dir="/root/.ssh"
|
||||||
sed -e "/begin ${app}/,/end ${app}/{/.*/d}" ${ssh_dir}/config -i || true
|
sed -e "/begin ${app}/,/end ${app}/{/.*/d}" ${ssh_dir}/config -i || true
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE USER
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing sudoers rights for user ${app}"
|
ynh_script_progression --message="Removing sudoers rights for user ${app}"
|
||||||
rm /etc/sudoers.d/${app}
|
rm /etc/sudoers.d/${app}
|
||||||
|
|
||||||
ynh_script_progression --message="Removing ${app} user" --last
|
ynh_script_progression --message="Removing ${app} user" --last
|
||||||
userdel ${app}
|
userdel ${app}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Removal of $app completed"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
@ -13,16 +14,20 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
ynh_clean_check_starting
|
||||||
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
export server=$(ynh_app_setting_get $app server)
|
export server=$(ynh_app_setting_get --app=$app --key=server)
|
||||||
|
|
||||||
export final_path="/opt/yunohost/${app}"
|
export final_path="/opt/yunohost/${app}"
|
||||||
|
|
||||||
|
@ -40,14 +45,22 @@ mkdir -p /usr/share/yunohost/backup_method
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE FILES
|
# RESTORE FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore
|
ynh_restore
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENABLE TIMER
|
# ENABLE TIMER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
systemctl enable --quiet ${app}.timer
|
systemctl enable --quiet ${app}.timer
|
||||||
systemctl enable --quiet ${app}_check.timer
|
systemctl enable --quiet ${app}_check.timer
|
||||||
systemctl enable --quiet ${app}_check_read_data.timer
|
systemctl enable --quiet ${app}_check_read_data.timer
|
||||||
systemctl start ${app}.timer
|
systemctl start ${app}.timer
|
||||||
systemctl start ${app}_check.timer
|
systemctl start ${app}_check.timer
|
||||||
systemctl start ${app}_check_read_data.timer
|
systemctl start ${app}_check_read_data.timer
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Restoration completed for $app"
|
||||||
|
|
|
@ -12,8 +12,10 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
export final_path="/opt/yunohost/${app}"
|
export final_path="/opt/yunohost/${app}"
|
||||||
export server=$(ynh_app_setting_get $app server)
|
export server=$(ynh_app_setting_get $app server)
|
||||||
export port=$(ynh_app_setting_get $app port)
|
export port=$(ynh_app_setting_get $app port)
|
||||||
|
@ -30,18 +32,22 @@ export allow_extra_space_use=$(ynh_app_setting_get $app allow_extra_space_use)
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF AN UPGRADE IS NEEDED
|
# CHECK VERSION
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_check_app_version_changed
|
ynh_script_progression --message="Checking version..."
|
||||||
|
|
||||||
|
upgrade_type=$(ynh_check_app_version_changed)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
||||||
|
|
||||||
# Backup the current version of the app
|
# Backup the current version of the app
|
||||||
ynh_backup_before_upgrade
|
ynh_backup_before_upgrade
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
# restore it if the upgrade fails
|
ynh_clean_check_starting
|
||||||
|
# Restore it if the upgrade fails
|
||||||
ynh_restore_upgradebackup
|
ynh_restore_upgradebackup
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
|
@ -149,15 +155,6 @@ systemctl start ${app}.timer
|
||||||
systemctl start ${app}_check.timer
|
systemctl start ${app}_check.timer
|
||||||
systemctl start ${app}_check_read_data.timer
|
systemctl start ${app}_check_read_data.timer
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SETUP LOGROTATE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Configuring logrotate"
|
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.log
|
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.err
|
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log
|
|
||||||
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.err
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# UPGRADE SSH CONFIG
|
# UPGRADE SSH CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -185,4 +182,20 @@ Host ${server}
|
||||||
# end $app ssh config
|
# end $app ssh config
|
||||||
EOCONF
|
EOCONF
|
||||||
fi
|
fi
|
||||||
ynh_script_progression --message="End of upgrade process" --last
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# SETUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring logrotate"
|
||||||
|
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.log
|
||||||
|
ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.err
|
||||||
|
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log
|
||||||
|
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.err
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Upgrade of $app completed"
|
||||||
|
|
Loading…
Reference in a new issue