Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
60f9aba
Merge branch 'testing'
Feb 27, 2020
40355da
Merge branch 'testing'
Mar 2, 2020
5753e56
Merge branch 'testing'
Mar 3, 2020
148f8bc
Merge branch 'testing'
Mar 4, 2020
91313f4
Merge branch 'testing'
Apr 12, 2020
8cc00c8
Merge branch 'testing'
Jun 19, 2020
a9e8664
bump app version from 0.9.6~ynh5 to 0.9.6~ynh6
Jun 19, 2020
7448183
Merge branch 'testing'
Nov 12, 2020
1223982
Merge branch 'testing'
Nov 14, 2020
c9a2844
Merge branch 'testing'
Nov 14, 2020
3b056e3
Merge branch 'testing'
Nov 18, 2020
cb84369
Merge branch 'testing'
Feb 18, 2021
f86be87
Merge branch 'testing'
Mar 1, 2021
ea4457d
Merge branch 'testing'
Mar 7, 2021
0454da8
Merge branch 'testing'
Mar 14, 2021
c3e20aa
Merge branch 'testing'
Mar 16, 2021
fb54139
Merge branch 'testing'
Mar 21, 2021
cc15aba
Merge branch 'testing'
Mar 21, 2021
77b9085
Merge branch 'testing'
Mar 29, 2021
5269440
Merge branch 'testing'
May 26, 2021
43f540b
Apply last example_ynh
yalh76 Mar 13, 2022
0c55210
Auto-update README
yunohost-bot Mar 13, 2022
06a1842
Merge pull request #8 from YunoHost-Apps/example
yalh76 Mar 14, 2022
1983a6e
Merge pull request #9 from YunoHost-Apps/testing
yalh76 Mar 15, 2022
0e8425b
Linter
ericgaspar Jan 16, 2023
37e7614
Auto-update README
yunohost-bot Jan 16, 2023
6b1f02e
Update install
ericgaspar Jan 16, 2023
93297ba
Merge branch 'testing' of https://github.com/YunoHost-Apps/restic_ynh…
ericgaspar Jan 16, 2023
a515196
Merge pull request #15 from YunoHost-Apps/testing
ericgaspar Jan 20, 2023
dba776f
Auto-update README
yunohost-bot Oct 31, 2023
6fd3164
0.16.2
ericgaspar Nov 25, 2023
b073a2f
Merge pull request #18 from YunoHost-Apps/0.16.2
ericgaspar Nov 25, 2023
82310a4
Merge pull request #20 from YunoHost-Apps/testing
ericgaspar Nov 26, 2023
42c03e6
Auto-update README
yunohost-bot Mar 29, 2024
075ce5d
Auto-update READMEs
yunohost-bot May 22, 2024
099f056
Manifest v2
Salamandar May 25, 2024
10659e2
Fix tests
Salamandar May 25, 2024
58356e7
fix j2 template names
Salamandar May 25, 2024
08958e6
fix unit name
Salamandar May 25, 2024
252a830
oops fix _ynh_add_config_j2
Salamandar May 25, 2024
ecad810
Fix : $app -> restic
Salamandar May 25, 2024
f27ce2b
Cleanup packagingv2
Salamandar May 25, 2024
bc1b127
Cleanup packagingv2, debug
Salamandar May 25, 2024
5993684
update doc the wrong way lol
Salamandar May 25, 2024
ffe5dc1
Auto-update READMEs
yunohost-bot May 25, 2024
4bfd794
Add yunohost service add in restore
Salamandar May 25, 2024
a8fe840
fix systemd_action
Salamandar May 25, 2024
c9cea9c
cleanup upgrade for linter
Salamandar May 25, 2024
c3c86a1
Fix remove
Salamandar May 26, 2024
de72383
restore debug
Salamandar May 26, 2024
581aed5
Fix remove script
Salamandar May 26, 2024
1e618d1
do not setup_source in restore
Salamandar May 26, 2024
d31ec14
Fix restore script by calling the proper function
Salamandar May 26, 2024
1df315c
Fix upgrade script
Salamandar May 26, 2024
6cb309b
Fix restore, remove debug
Salamandar May 26, 2024
7c7c509
simpler post_install
Salamandar May 26, 2024
93396b2
fix upgrade
Salamandar May 26, 2024
a3b733a
cleanup messages
Salamandar May 26, 2024
272f84d
Auto-update READMEs
yunohost-bot May 26, 2024
d8f56bf
Add test_upgrade_from
Salamandar May 26, 2024
984281b
upgrade: try to clean up
Salamandar May 26, 2024
daad20e
Remove fixmes from manifest
Salamandar May 26, 2024
295c737
Fix paths in installed scripts
Salamandar May 26, 2024
6999420
re-fix upgrade
Salamandar May 26, 2024
0687aa0
re-fix upgrade
Salamandar May 26, 2024
62f213a
cleanup more in upgrade
Salamandar May 26, 2024
64bc269
cleanup more in upgrade
Salamandar May 26, 2024
9de5c8b
Merge pull request #21 from YunoHost-Apps/packagingv2
Salamandar May 26, 2024
cf80dee
Merge pull request #22 from YunoHost-Apps/testing
ericgaspar May 26, 2024
9606bc4
Create ADMIN.md
alexAubin Jul 10, 2024
bd8da69
Auto-update READMEs
yunohost-bot Jul 10, 2024
dfad39f
Update DESCRIPTION.md
alexAubin Jul 10, 2024
9853e4d
Auto-update READMEs
yunohost-bot Jul 10, 2024
968e321
Update POST_INSTALL.md
alexAubin Jul 10, 2024
23e05c4
Update POST_INSTALL.md
alexAubin Jul 10, 2024
6891b39
Update ADMIN.md
alexAubin Jul 10, 2024
425cc99
[autopatch] Automatic patch attempt for helpers 2.1
Aug 31, 2024
ed2e0c1
cleaning
ericgaspar Oct 17, 2024
0b00fc7
clarify storage support in docs
devloberto Dec 29, 2024
56bd148
Update manifest.toml
ericgaspar Apr 14, 2025
9958b3a
Update _common.sh
ericgaspar Apr 14, 2025
6dbcf70
0.18.0
ericgaspar Apr 14, 2025
f2e6b82
Auto-update READMEs
yunohost-bot Apr 14, 2025
3f28c93
Merge pull request #29 from YunoHost-Apps/0.18.0
ericgaspar Apr 14, 2025
b5745ff
Merge pull request #30 from YunoHost-Apps/testing
ericgaspar May 2, 2025
fab53bb
Auto-update READMEs
yunohost-bot May 2, 2025
bc9e627
Update Restic
Gildas-GH Jul 13, 2025
5e5b2fe
Fix script
Gildas-GH Jul 13, 2025
99abb33
Fix script 2
Gildas-GH Jul 13, 2025
23cbb0c
Fix script 3
Gildas-GH Jul 13, 2025
dbde693
Fix script 4
Gildas-GH Jul 13, 2025
5361c31
Fix script 5
Gildas-GH Jul 13, 2025
d4fe2f5
Fix logs
Gildas-GH Jul 13, 2025
eef95c9
Fix file names
Gildas-GH Jul 13, 2025
d5924d0
better?
Gildas-GH Jul 13, 2025
058d1af
Amélioration script backup
Gildas-GH Jul 13, 2025
e0098ce
Fix scripts
Gildas-GH Jul 13, 2025
bb4fea9
oups
Gildas-GH Jul 13, 2025
2ce91ba
fix backup/restore
Gildas-GH Jul 13, 2025
04c4f0e
fix script
Gildas-GH Jul 13, 2025
211ad56
update
Gildas-GH Jul 13, 2025
9c44558
fix scripts
Gildas-GH Jul 13, 2025
c0856c8
fix sudo conf
Gildas-GH Jul 13, 2025
d01aa62
enable config panel
Gildas-GH Jul 13, 2025
dd1b1cd
fix config panel
Gildas-GH Jul 13, 2025
8fcad26
Merge branch 'testing' into pr/28
ericgaspar Jul 13, 2025
ccb984f
Merge pull request #28 from devloberto/testing
ericgaspar Jul 13, 2025
d84dd4f
cleaning
ericgaspar Jul 13, 2025
3a9f8ee
améliorations
Gildas-GH Jul 13, 2025
18981cb
Merge remote-tracking branch 'origin/testing' into auto-helpers-2.1
Gildas-GH Jul 13, 2025
75971bf
changed log system
Gildas-GH Jul 13, 2025
ac221c2
upgrade script
Gildas-GH Jul 13, 2025
2fa3303
fix upgrade script
Gildas-GH Jul 13, 2025
ca7ac0d
set/use environment variables
Gildas-GH Jul 16, 2025
21a9e7b
fix env variable
Gildas-GH Jul 16, 2025
5f0f2bf
Merge branch 'testing' into auto-helpers-2.1
Gildas-GH Jul 16, 2025
a4135e8
Fix tests
Gildas-GH Jul 17, 2025
e9a7a8a
fix linter results
Gildas-GH Jul 17, 2025
63826d0
fix scripts to work in CI
Gildas-GH Jul 17, 2025
d21ed28
initialize config panel question 'state' during upgrade
Gildas-GH Jul 17, 2025
58f5b8b
Merge pull request #34 from Gildas-GH/auto-helpers-2.1
ericgaspar Jul 20, 2025
7599ef5
Auto-update READMEs
yunohost-bot Jul 20, 2025
aa0da0d
cleaning
ericgaspar Jul 20, 2025
ab020b6
Merge pull request #33 from YunoHost-Apps/testing
ericgaspar Jul 20, 2025
b971be4
Fix systemd conf
Gildas-GH Jul 23, 2025
6824c44
Upgrade to 0.18.0~ynh3
Gildas-GH Jul 23, 2025
cd1e5fb
Fix scripts
Gildas-GH Jul 23, 2025
a05945e
Check restic backup in CI
Gildas-GH Jul 23, 2025
3c0bc0b
Fix upgrade
Gildas-GH Jul 23, 2025
ab85b70
Fix upgrade 2
Gildas-GH Jul 23, 2025
e1b3867
Close ssh agent on script exit
Gildas-GH Jul 24, 2025
4156dc1
Fix restic
Gildas-GH Jul 29, 2025
92383cf
typo
Gildas-GH Jul 29, 2025
04cb440
trying to fix test on CI
Gildas-GH Jul 30, 2025
15dca17
Won't work in CI as we call a "yunohost" command line during another …
Gildas-GH Jul 30, 2025
10f7e6a
Fix mixed up help message translations for server configuration in ma…
dniku Aug 31, 2025
bffa107
Merge pull request #36 from Gildas-GH/auto-helpers-2.1
Gildas-GH Sep 1, 2025
4456917
Auto-update READMEs
yunohost-bot Sep 1, 2025
dbb9951
Merge branch 'testing' into patch-1
Gildas-GH Sep 1, 2025
21aa411
Merge pull request #37 from dniku/patch-1
Gildas-GH Sep 1, 2025
01e59ce
Merge pull request #39 from YunoHost-Apps/testing
Gildas-GH Sep 1, 2025
e165a7c
Update DESCRIPTION.md
Gildas-GH Sep 1, 2025
b6515ba
Always remove service from YunoHost database
Gildas-GH Sep 20, 2025
5f9b9f2
Suggest URL syntax
Gildas-GH Sep 20, 2025
b4a8041
Update manifest.toml
ericgaspar Oct 9, 2025
ba4f782
Add autoupdate configuration for all architectures
CodeShakingSheep Oct 27, 2025
9ba18f8
Update Restic version to 0.18.1
CodeShakingSheep Oct 27, 2025
488f237
Correct armhf asset name
CodeShakingSheep Oct 27, 2025
b0119b4
Merge pull request #42 from CodeShakingSheep/add-autoupdate
Gildas-GH Oct 28, 2025
ea96455
Auto-update READMEs
yunohost-bot Oct 28, 2025
c4985b7
Merge pull request #43 from YunoHost-Apps/Gildas-GH-patch-1
Gildas-GH Oct 28, 2025
462ac40
Merge pull request #44 from YunoHost-Apps/testing
Gildas-GH Oct 30, 2025
2d03048
Edit exclude logic
Gildas-GH Nov 27, 2025
994226d
Added documentation
Gildas-GH Feb 20, 2026
6e8bef8
Custom forget policy
Gildas-GH Feb 20, 2026
66cd802
Better logs & test button
Gildas-GH Feb 20, 2026
917ba5f
Better logs
Gildas-GH Feb 20, 2026
88b7c6e
Backup core only
Gildas-GH Feb 20, 2026
34cb88a
Hide password in logs
Gildas-GH Feb 20, 2026
492edf8
Fix backup core only & fix timers conf
Gildas-GH Feb 20, 2026
be71ed7
Added and translated documentation, better logs
Gildas-GH Feb 20, 2026
b598aa2
Fix typo
Gildas-GH Feb 20, 2026
80078d2
Merge helper functions in one unique file
Gildas-GH Feb 22, 2026
5f16271
Doc for common errors
Gildas-GH Feb 22, 2026
f3a2e98
Remove Ynh helpers from App helpers
Gildas-GH Feb 23, 2026
a7ddbe9
Errors in English
Gildas-GH Feb 23, 2026
a49fbf9
Merge pull request #55 from YunoHost-Apps/exclude-logic
Gildas-GH Feb 23, 2026
4150d86
Update version to 0.18.1~ynh2
Gildas-GH Feb 23, 2026
dd916ba
Auto-update READMEs
yunohost-bot Feb 23, 2026
7d71f9e
Merge pull request #56 from YunoHost-Apps/update-version
Gildas-GH Feb 23, 2026
8fffdca
Upgrade messages (#58)
Gildas-GH Feb 24, 2026
56ccd21
Merge pull request #57 from YunoHost-Apps/testing
Gildas-GH Feb 26, 2026
1a11ecb
Filter out specific messages from error log
Gildas-GH Mar 10, 2026
323b73e
Separate errors and warnings
Gildas-GH Mar 16, 2026
488983a
Stop apps during backup & documentation
Gildas-GH Mar 16, 2026
d74c57b
Use __APP__ instead of hardcoded value
Gildas-GH Mar 16, 2026
1670ad8
Doc & Ynh version
Gildas-GH Mar 16, 2026
f1fffba
Upgrade documentation
Gildas-GH Mar 16, 2026
d7f2b8f
Auto-update READMEs
yunohost-bot Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.sw*
.vagrant
*~
*.sw[op]
.DS_Store
201 changes: 26 additions & 175 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,189 +1,40 @@
# Restic for YunoHost
<!--
N.B.: This README was automatically generated by <https://github.com/YunoHost/apps_tools/blob/main/readme_generator>
It shall NOT be edited by hand.
-->

[![Latest Version](https://img.shields.io/badge/version-0.12.0-green.svg?style=flat)](https://github.com/YunoHost-Apps/restic_ynh/releases)
[![Status](https://img.shields.io/badge/status-testing-yellow.svg?style=flat)](https://github.com/YunoHost-Apps/restic_ynh/milestones)
[![Integration level](https://dash.yunohost.org/integration/restic.svg)](https://dash.yunohost.org/appci/app/restic)
[![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/YunoHost-Apps/restic_ynh/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/YunoHost-Apps/restic_ynh.svg?style=flat)](https://github.com/YunoHost-Apps/restic_ynh/issues)
<h1>
<img src="https://raw.githubusercontent.com/YunoHost/apps/main/logos/restic.png" width="32px" alt="Logo of Restic">
Restic, packaged for YunoHost
</h1>

[![Install Restic with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=restic)
Regularly create encrypted backups sent to another server using Restic

> *This package allows you to install Restic quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
[![🌐 Official app website](https://img.shields.io/badge/Official_app_website-darkgreen?style=for-the-badge)](https://restic.net)
[![Version: 0.18.1~ynh3](https://img.shields.io/badge/Version-0.18.1~ynh3-rgb(18,138,11)?style=for-the-badge)](https://ci-apps.yunohost.org/ci/apps/restic/)

## Overview
<div align="center">
<a href="https://apps.yunohost.org/app/restic"><img height="100px" src="https://github.com/YunoHost/yunohost-artwork/raw/refs/heads/main/badges/neopossum-badges/badge_more_info_on_the_appstore.svg"/></a>
<a href="https://github.com/YunoHost-Apps/restic_ynh/issues"><img height="100px" src="https://github.com/YunoHost/yunohost-artwork/raw/refs/heads/main/badges/neopossum-badges/badge_report_an_issue.svg"/></a>
</div>

A [Restic](https://restic.net/) package for YunoHost (heavily inspired by [the Borg package](https://github.com/YunoHost-Apps/borg_ynh/)).
## 📦 Developer info

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)).
[![Automatic tests level](https://apps.yunohost.org/badge/cilevel/restic)](https://ci-apps.yunohost.org/ci/apps/restic/)

## Usage
🛠️ Upstream Restic repository: <https://github.com/restic/restic>

If you want to backup your server A onto the server B.
Pull request are welcome and should target the [`testing` branch](https://github.com/YunoHost-Apps/restic_ynh/tree/testing).

## 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
The `testing` branch can be tested using:
```
# fresh install:
sudo yunohost app install https://github.com/YunoHost-Apps/restic_ynh/tree/testing

## Edit the apps list to backup

```
yunohost app setting restic apps -v "nextcloud,wordpress"
# upgrade an existing install:
sudo yunohost app upgrade restic -u https://github.com/YunoHost-Apps/restic_ynh/tree/testing
```

## 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.

#### Supported architectures

* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/restic%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/restic/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/restic%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/restic/)

## Links

* Report a bug: https://github.com/YunoHost-Apps/restic_ynh/issues
* App website: https://restic.net/
* Upstream app repository: https://github.com/restic/restic
* YunoHost website: https://yunohost.org/

---

## Developer info

Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/restic_ynh/tree/testing).

To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/restic_ynh/tree/testing --debug
or
sudo yunohost app upgrade restic -u https://github.com/YunoHost-Apps/restic_ynh/tree/testing --debug
```
### 📚 App packaging documentation

Please see <https://doc.yunohost.org/packaging_apps> for more information.
29 changes: 0 additions & 29 deletions check_process

This file was deleted.

135 changes: 135 additions & 0 deletions conf/backup-with-restic
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env bash

errors=""
current_date=$(date +"%y%m%d_%H%M")
log_file="/var/log/__APP__/${current_date}.log"
mkdir -p "/var/log/__APP__"

filter_hooks() {
ls /usr/share/yunohost/hooks/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq 2>&1
}

# Some apps need to be stopped to be backed up
# https://github.com/search?q=org%3AYunoHost-Apps%20recommended%20to%20make%20your%20backup%20when%20the%20service%20is%20stopped&type=code
apps_to_stop=("synapse" "gitea" "seafile" "sogo" "monitorix" "xwiki")
stop_apps=$(sudo yunohost app setting __APP__ stop_apps)

sudo yunohost app setting __APP__ last_run -v "${current_date}"
sudo yunohost app setting __APP__ state -v "ongoing"

BACKUP_CORE_ONLY=$(sudo yunohost app setting __APP__ backup_core_only)

export BACKUP_CORE_ONLY

# Backup system part conf
conf=$(sudo yunohost app setting __APP__ conf)
if [[ "$conf" = "1" ]]; then
if ! sudo yunohost backup create -n auto_conf --method __APP___app --system $(filter_hooks conf) >> "$log_file" 2>&1 ; then
errors+="\nThe backup miserably failed to backup system configurations."
fi
fi

# Backup system data
data=$(sudo yunohost app setting __APP__ data)
if [[ "$data" = "1" ]]; then
if ! sudo yunohost backup create -n auto_data --method __APP___app --system $(filter_hooks data) >> "$log_file" 2>&1 ; then
errors+="\nThe backup miserably failed to backup system data."
fi
fi

# Read and sanitize the app list:
# - Remove spaces after commas
# - Replace commas with spaces
apps=$(sudo yunohost app setting __APP__ apps | sed 's/,[[:space:]]*/,/g')
apps="${apps//,/ }"

# Initialisation
include_all=false
exclude_list=()
explicit_include_list=()

# Parse app list
for item in $apps; do
if [[ "$item" == "all" ]]; then
include_all=true
elif [[ "$item" =~ ^exclude: ]]; then
exclude_list+=("${item#exclude:}")
else
# If you are not in "all" mode, add to the explicit inclusion list
if ! $include_all; then
explicit_include_list+=("$item")
# If you are in "all" mode and the element is not prefixed with "exclude:", it is an implicit exclusion.
else
exclude_list+=("$item")
fi
fi
done

# Loop on applications
for application in $(sudo ls /etc/yunohost/apps/); do
stopped="0"

# Exclude/Include logic
if $include_all; then
# "All" mode: those in exclude_list are excluded.
if printf '%s\n' "${exclude_list[@]}" | grep -q "^${application}\$"; then
continue
fi
else
# Explicit inclusion mode: only those in explicit_include_list are included.
if ! printf '%s\n' "${explicit_include_list[@]}" | grep -q "^${application}\$"; then
continue
fi
fi

# Verify backup script
if sudo test ! -f "/etc/yunohost/apps/$application/scripts/backup"; then
errors+="\nWarning: The application $application has no backup script. This app won't be backed up."
continue
fi

if [[ " ${apps_to_stop[@]} " =~ " ${application} " ]] && [ "$stop_apps" = "1" ]; then
systemctl stop "$application"
stopped="1"
fi

# Execute backup
if ! sudo yunohost backup create -n "auto_$application" --method __APP___app --apps "$application" >> "$log_file" 2>&1; then
errors+="\nThe backup miserably failed to backup $application application."
fi

# Start app if stopped
if [[ "$application" == "1" ]]; then
systemctl start "$application"
stopped="0"
fi
done

#=============================================
# SEND MAIL TO NOTIFY ABOUT FAILED OPERATIONS
#=============================================

# Détection des erreurs critiques
critical_errors="$(grep -iE "Error|Skipped|Fatal|Fail" "$log_file")"

# Détection des warnings
warnings="$(grep -iE "Warning" "$log_file")"

# Send mail on backup (partially) failed
domain=$(hostname)
repository="$(sudo yunohost app setting __APP__ repository)"

# Si des erreurs critiques sont présentes
if [ -n "$critical_errors" ]; then
errors+="\nSome backup partially failed:\n$critical_errors"
sudo yunohost app setting __APP__ state -v "failed"
echo -e "$errors\n\n\n$(cat "$log_file")" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "[__APP__] Backup failed from $domain onto $repository" root
# Si uniquement des warnings sont présents
elif [ -n "$warnings" ]; then
errors+="\nBackup completed with warnings:\n$warnings"
sudo yunohost app setting __APP__ state -v "successful_with_warnings"
echo -e "$errors\n\n\n$(cat "$log_file")" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "[__APP__] Backup completed with warnings from $domain onto $repository" root
# Si tout s'est bien passé
else
sudo yunohost app setting __APP__ state -v "successful"
fi
Loading