#!/bin/bash LOCK_FILE=/tmp/{{ app }}_backup.lock EXIT_PROPERLY() { echo -e "\e[91m \e[1m" # Shell in light red bold echo -e "!!\n Caught an interruption signal, removing lock file...\n!!" echo -e "\e[22m" # Remove bold rm $LOCK_FILE exit 1 } trap EXIT_PROPERLY 1 2 3 6 15 if [ -f "$LOCK_FILE" ];then echo "Backup already launched by process $(grep '.*' $LOCK_FILE), canceling this one" >&2 exit 1 fi echo $$ > "$LOCK_FILE" if yunohost -v | grep "version: 2." > /dev/null; then ignore_apps="--ignore-apps" ignore_system="--ignore-system" else ignore_apps="" ignore_system="" fi filter_hooks() { ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq } # Backup system part conf conf=$(yunohost app setting {{ app }} conf) if [ $conf -eq 1 ];then yunohost backup create $ignore_apps -n auto_conf --method {{ app }}_app --system $(filter_hooks conf) fi # Backup system data data=$(yunohost app setting {{ app }} data) if [ $data -eq 1 ];then yunohost backup create $ignore_apps -n auto_data --method {{ app }}_app --system $(filter_hooks data) fi # Backup all apps independently apps=$(yunohost app setting {{ app }} apps) for app in $(yunohost app list --installed -b | grep id: | cut -d: -f2); do backup_app=false for selected_app in $(echo $apps | tr "," " ");do if [[ "$selected_app" == "$app" ]] || [ "$apps" = "all" ]; then backup_app=true break fi done if [ "$backup_app" == "true" ];then yunohost backup create $ignore_system -n auto_$app --method {{ app }}_app --apps $app fi done rm "$LOCK_FILE"