#!/bin/bash




# https://chatgpt.com/c/68945eed-5b98-832a-9af0-cb965ba48d49

dirFolderBackup="/docker/Dockerfiles/backup"
pathToBackup="/docker"

test(){
    backupName="$1"

    if [ -z "$2" ]; then
        dirFolderToBackup="$pathToBackup"/"$1"  #че быкапить
        echo "empty"
    else
        dirFolderToBackup="$2" #че быкапить
        echo "noempty"
    fi

    dirBackup=file://"$dirFolderBackup"/"$1" #куда быкапить
    dirArchive="$dirFolderBackup"/archive
    dirTemp="$dirFolderBackup"/temp 
    dirLog="$dirFolderBackup"/log.log 

    mkdir -p $dirArchive $dirTemp

        # --dry-run \
    duplicity \
        "$dirFolderToBackup" \
        "$dirBackup" \
        --archive-dir "$dirArchive" \
        --tempdir "$dirTemp" \
        --log-file "$dirLog" \
        --name "$backupName" \
        --file-prefix "$backupName"_ \
        --log-timestamp \
        --progress \
        --no-encryption \
        --volsize 2000 \
        --full-if-older-than 2W \
        --gpg-options "--compress-level 9" \
        --exclude "$dirFolderBackup" \
        --exclude "/docker/http-server/private" \
        --exclude "/docker/http-server/public" \
        --exclude "/docker/bandersnatch/www/private" \
        --exclude "/docker/bandersnatch/www/public"

}

test1(){
    for name in "${containers[@]}"; do
        # docker stop $name
        echo $name
    done
    
    test "$1" "$2"
    
    for name in "${containers[@]}"; do
        # docker start $name
        echo $name
    done
}

# test "Dockerfiles" 


containers=("blackmirror-nginx"
)
test "bandersnatch"


# containers=("eclipse-mosquitto"
# "grafana"
# "influxdb"
# "mqtt-explorer"
# "node-red"
# )
# test1
# # test "home" 

# containers=("qbittorrent"
# "cobalt"
# "changedetection"
# )
# test1
# # test "apps" 

# containers=("dynmap_db"
# "dynmap_nginx"
# "dynmap_php"
# )
# test1
# # test "dynmap" 


# containers=("homepage-global"
# "homepage-local"
# )
# test1
# # test "homepage" 


# containers=("adguard"
# "nginx-proxy"
# )
# test1
# # test "network-local" 


# containers=("openvpn-as"
# "outline-proxy-pac"
# )
# test1
# # test "network-outside" 

# containers=("port-container"
# "registry-cont"
# )
# test1
# # test "portainer" 

# containers=("python-http-server-1"
# )
# test1
# # test "http-server" 


# containers=("python-supervisor-1"
# )
# test1
# # test "python" 

# containers=("blackmirror-nginx"
# )
# test1
# # test "bandersnatch" 

