Моя шпаргалка :)

Мануалы и настройки => Настройки *nix (почта, web, система etc) => Тема начата: George от Фев. 17, 2023, 09:56

Название: Скрипт архивации вложенных папок c указанием пути откуда и куда
Отправлено: George от Фев. 17, 2023, 09:56
#!/bin/bash
DATE=$(date +%Y-%m-%d-t-%H-%M-%S)

if [[ $1 = --help ]]; then
echo USAGE:
echo './zip.sh /<fromdir> <to-subdir> - subdir will be not zipped'
echo './zip.sh /<fromdir> /<to-dir> - zipping <fromdir> to /<full_path_to_dir>'
else
arch_fld=$1
#if [$arch_fld = '--help']; then

if ! [ -z $1 ] && ! [ -z $2 ] ; then
for folder in $arch_fld/*
do
    if [[ $2 = /* ]]; then
      if ! `file $folder  | grep -i  -P $2'|'$RECYCLE.BIN'|System' > /dev/null 2>&1`; then
                save_path=${folder//$arch_fld/$2"/"$DATE}
                echo -'*Achiving folder - ' $folder ' to '$save_path'.zip *-'
                7z a -tzip -ssw -mx7 "$save_path.zip" "$folder"
              fi

    else
      if ! `file $folder  | grep -i  -P $2'|'$RECYCLE.BIN'|System' > /dev/null 2>&1`; then
save_path=${folder//$arch_fld/$arch_fld"/"$2"/"$DATE}
echo -'*Achiving folder - ' $folder ' to '$save_path'.zip *-'
7z a -tzip -ssw -mx7 "$save_path.zip" "$folder"
      fi
    fi
done
else
echo Not enouth parametrs! Try --help
fi