#!/bin/bash

#  TEST !

# standard rsync
# copies all noticed DIRs to "/media/DATA-4T/SIK/SIK-Android-DATA-A40"
#
# 260815,260817,260819,260821,260831
#
# to do: invoked by root?, mount A40, 
#        links zu letztem BkUp (Dateiname des letzten BkUps in Datei)

# linked or full backup ?    full bkup = new backup without links
# standard is link backup

if test -e $src$mark  ; then
   echo "    $src$mark does exist"
   echo
else
   echo
   echo "    $src$mark does not exist !!!   not mounted ?"
   echo
   echo "       E X I T"
   echo
   echo 
   exit
fi

echo
echo "linked or full backup (standard: linked bkup)?   TEST only , query not implemented"
echo "    answer     f or F   "
#echo "( for  full   backup, otherwise linked backup will be created )"
echo
read bkup_type
if ! test  $bkup_type; then
   bkup_type="link"
fi
if test  $bkup_type = "f" -o  $bkup_type = "F"; then
   bkup_type="full"
else 
   bkup_type="link"
fi

DATUM=`/bin/date '+%y%m%d-%H%M'`
prg_path="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
#echo "  prg_path: $prg_path"

src="/media/Android/"
# writes the scr-data "/media/DATA-4T/DATA*" directly into dest-DIR
dest_dir="/media/DATA-4T/SIK/SIK-Android-DATA-A40/"
dest_dir_name="BkUp-$DATUM-$bkup_type"
dest="$dest_dir$dest_dir_name"
link_dest=""
if test $bkup_type = "link" ; then
   link_dest_dir=$dest_dir
   #link_dest="/media/DATA-4T/SIK/SIK-Android-DATA-A40/BkUp-20260817-1954/"
   #echo $link_dest
   link_dest_dir_name="BkUp-20260817-1954/"
   link_dest="$link_dest_dir$link_dest_dir_name"
   #echo "link_DIR_name: $link_DIR_name"
   #link_DIR_name=${link_DIR_name##*/}
fi
echo "link-dir-name: $link_dest_dir$link_dest_dir_name"; echo

#opts_1="-rltgovzpH"
opts_1="-avzpH"
# --archive, -a  archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
# rsync_options in long: " --recursive --links --perms --times --group --owner --devices --specials  --verbose --compress --progress --hard-links
# here not used: --delete --delete-excluded --itemize-changes " # in long

#opts_2=" --delete"
#opts_3=" --partial"

# "exclude-from" beinhalted auch "include files"
excl="/media/DATA-4T/SIK/SIK-Android-DATA-A40/BkUp-scripts/A40-bkup-dirs-excludes-lst"
#log=" --log-file=A40-rsync-log-DATA-$DATUM.txt"
log="${dest_dir}A40-rsync-log-DATA-$DATUM.txt"
#log="/media/DATA-4T/SIK/SIK-Android-DATA-A40/BkUp-scripts/A40-rsync-log-DATA-$DATUM.txt"
#dry_run=" --dry-run"
#verbose="-vv"
#verbose="-vvv"
# mark is file in SD as marker for recognition if smartphone is mouted
mark="Card/in-A40"

echo "TEST sudo nice --adjustment=19 rsync $opts_1 $opts_2 $opts_3 --log-file=$log  $verbose --exclude-from=$excl --link-dest=$link_dest $dry_run $src $dest"
exit

if test ! -e $dest ; then
   mkdir $dest 
fi 

if test ! -e $dest ; then
   echo "$dest does not exist !!! \n\n\n"
   echo "coudn't be generated"
   echo
   exit
fi ;

sudo nice --adjustment=19 rsync $opts_1 $opts_2 $opts_3 --log-file=$log  $verbose --exclude-from=$excl --link-dest=$link_dest $dry_run $src $dest

