Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 92e4424e authored by Arthur BOUDREAULT's avatar Arthur BOUDREAULT
Browse files

refactor: refactoring of purging system.

parent e568d353
No related branches found
No related tags found
1 merge request!41Resolve "local backups: design purge system"
Pipeline #7437 passed with warnings
......@@ -32,6 +32,8 @@ ynh_backup:
apps: True
src_script: "templates/ynh_backup.sh.j2"
dest_script: "/usr/bin"
number_days_to_keep: "2"
```
- `ynh_backup.scheduled` : active la fonctionnalité de sauvegarde des applications YunoHost, mettez la valeur à `True`.
......@@ -39,6 +41,7 @@ ynh_backup:
- `ynh_backup.scheduled_[hour|minute|weekday|month]`: modifie la planification de la tâche cron. Par défaut, elle se déclenchera tous les jours de l'année à 1 heure du matin. Pour plus d'informations concernant les réglages horaires cron, cet outil peut être utile : <https://crontab.guru/>.
- `ynh_backup.system` : **obligatoire**. Activez la sauvegarde du système YunoHost en mettant la valeur à `True`.
- `ynh_backup.apps` : **obligatoire**. Activez la sauvegarde des applications YunoHost en mettant la valeur à `True`.
- `number_days_to_keep` : **obligatoire**. Détermine le nombre de jours à garder pour le système de purge.
### Sauvegardes distantes avec BorgBackup
......
......@@ -39,6 +39,7 @@ ynh_backup:
- `ynh_backup.scheduled_[hour|minute|weekday|month]`: modifies the scheduling of the cron task. By default, it will run every day of the year at 1am. For more information about cron time settings, this tool can be useful: <https://crontab.guru/>.
- `ynh_backup.system`: **mandatory**. Enables automatic backup of the YunoHost system by setting the value to `True`.
- `ynh_backup.apps`: **mandatory**. Enables automatic backup of YunoHost applications by setting the value to `True`.
- `number_days_to_keep` : **mandatory**. Determines the number of days to keep for the purging system.
### remote backups with YunoHost BorgBackup
......
......@@ -29,6 +29,8 @@ ynh_backup:
# system: True
# apps: True
number_days_to_keep: "2"
# Variables for YunoHost BorgBackup
ynh_borg_backup_scheduled: False
borg_source_directories:
......
#!/bin/sh
#!/bin/bash
today="$(date +%Y%m%d)"
number_to_keep="{{ number_days_to_keep }}"
old_backup_list="$(yunohost backup list --output-as plain | head -n -"$number_to_keep")" # Afficher toutes les lignes de sauvegardes à part les deux dernières.
today=$(date +%Y%m%d_%H%M)
old_backup=$(yunohost backup list --output-as plain | grep "$(date --date="2 days ago" +"%Y%m%d")")
_good() {
echo "SUCCESS: ${1}" && exit 0
}
_check_old_backup() {
if [ -n "$old_backup" ]; then
for i in $old_backup; do
echo "Backup $i is 2 days old or more. Purging it now."
yunohost backup delete "$i"
echo "Purging of old backup is now complete."
done
else
echo "There is no old backup to be purged."
fi
_fail() {
echo "ERROR: ${1}" && exit 1
}
_create_ynh_backup() {
echo "Backing up $today YunoHost data now."
yunohost backup create {% if ynh_backup.system %}--system{% endif %}{% if ynh_backup.apps %} --apps{% endif %}{% if ynh_backup.directory %} --output-directory {{ ynh_backup.directory }}/backup_"$today" {% endif %}
yunohost backup create {% if ynh_backup.system %}--system{% endif %}{% if ynh_backup.apps %} --apps{% endif %}{% if ynh_backup.directory %} --output-directory {{ ynh_backup.directory }}/backup_"$today" {% endif %} || _fail "can't create a backup"
}
_check_old_backup
_prune_old_backup() {
if [ -n "$old_backup_list" ]; then
for backup in $old_backup_list; do
echo "Backup $backup is 2 days old or more. Purging it now."
yunohost backup delete "$backup"
done
_good "Purging of old backups completed."
else
_good "There is no old backup to be purged."
fi
}
_create_ynh_backup
_prune_old_backup
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment