Article 6HM65 Problem with script to make copies of directories/files

Problem with script to make copies of directories/files

by
darek
from LinuxQuestions.org on (#6HM65)
Hello,
I have a script that makes copies of specific folders. The script is executed once a day creating a folder with the current date (dd.mm.yyyy). The next day the situation is similar, but of course a folder with the next date is created. On the third day, the oldest directory is deleted and the next one is created.
Everything works well during the month. When there is a change of month, the script often ignores the older directories and does not delete them. Is it possible to correct this, where is the error? Here is the script:

#!/bin/bash
katalog1="/home/a/"
katalog2="/home/b/"
katalog3="/home/c/"
katalog4="/home/d/"
katalog5="/home/e/"
katalog6="/home/f/"
katalog7="/home/g/"
katalog8="/home/h/"

sciezka="/home/elicki"
current_date=$(date +"%d.%m.%Y")
backup_dir="/home/alamakota/$current_date"
data_minus_jeden=$(date -d "1 days ago" +"%d.%m.%Y")

for katalog in "$sciezka"/*; do
if [ -d "$katalog" ]; then
nazwa_katalogu=$(basename "$katalog")

if [[ $nazwa_katalogu < $data_minus_jeden ]]; then
rm -r "$katalog"
fi
fi
done
sleep 420
mkdir -p "$backup_dir"
cp $katalog1 $katalog2 $katalog3 $katalog5 $katalog6 $katalog7 $katalog8 -r "$backup_dir"/
chmod -R 755 $sciezka

thank you
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments