help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] A condition to see if a file already exist with date of the


From: Kévin GASPARD - EN
Subject: [Help-bash] A condition to see if a file already exist with date of the day (if yes add hour and minute) doesn't works
Date: Mon, 03 Sep 2012 20:41:25 +0200
User-agent: KMail/4.9 (Linux/3.4.6-1-CHAKRA; KDE/4.9.0; x86_64; ; )

Hello bash peoples,

I'm writing a backup bash script (and my first to be honnest) with tar to 
archive data.

In my idea, I want to make a backup named "backup-" plus the date of the day 
with variable plus extension. 

First I create these variable :


DATE=$(date +%d\%m\%Y)
DATE_SEC=$(date +%0k\%M-\%d\%m\%Y)


Then, this is the problematic piece of code :
(where $AUTO_NAME is a variable to attribute the name of the archive in the 
tar command, it's redundant I guess but it seems more clear for me, if you've 
a best way...)


if [ -e $DESTINATION/backup-$DATE.tar.xz ]; then
  AUTO_NAME=$DATE_SEC
  echo "A file was already created this day. Changing date to avoid conflit." 
elif [ -e $DESTINATION/backup-$DATE.tar.bz2 ]; then
  AUTO_NAME=$DATE_SEC
  echo "A file was already created this day. Changing date to avoid conflit."
elif [ -e $DESTINATION/backup-$DATE.tar.gz ]; then
  AUTO_NAME=$DATE_SEC
  echo "A file was already created this day. Changing date to avoid conflit."
else
  AUTO_NAME=$DATE
fi


As you can see, I want to check if a file is already named like "backup-" plus 
date of the day plus extension, depending to an option in my script to choose 
the way to compress the archive (xz, bz2 and gz). Not writed here because I 
think it's not important. Tell me if I'm wrong. I can also paste all the 
script.

Normally, if there is a file already named with the date of the day with one of 
these extension the script is using $DATE_SEC instead of $DATE to avoid name 
conflict.

But in reality what happens : If a file is already named, for example with the 
date of this day : backup-03092012.tar.xz the scripts overwrite it. I've 
constated it with a 'du -sh *' during the archive creation. I see the size file 
increase from scratch.

I hope someone can guide me so I can understand where I'm wrong.

PS : Sorry if I doesn't seems correct for your habits, I'm not very regular 
with mailing-list. Also I'm not english and I don't considered myself 
bilingual. I'm trying the best and do not hesitate to correct me if you think 
it's necessary.

-- 
Cordially, GASPARD Kévin

~~~~~~~~~~~~~~~~~~
Mobile phone : 0629612909
Jabber account : address@hidden
Web site : www.koshie.fr
~~~~~~~~~~~~~~~~~~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]