Operating System - HP-UX
1752413 Members
5915 Online
108788 Solutions
New Discussion юеВ

Re: How to set actual date in filename

 
SOLVED
Go to solution
Daniel Schneider_3
Frequent Advisor

How to set actual date in filename

I want to backup an entire folder with tar. The name of the tar file should contain the actual date and time.
For example: backup-29072003-1434.tar.

I tried to use an environment variable:
export ACTDATE=date +%d%m%Y, but there was an error:
ksh: +%d%m%Y: is not an identifier

Is there anybody with a tip for me?

Thanks very much in advance

Best regards
Daniel
6 REPLIES 6
Andreas Voss
Honored Contributor
Solution

Re: How to set actual date in filename

Hi,

try this one:

ACTDATE=$(date +%d%m%Y)

Regards
Michael Kelly_5
Valued Contributor

Re: How to set actual date in filename

Daniel,
you need to enclose the date ... command in backticks like this:
export ACTDATE=`date +%d%m%Y`

This tells the shell to execute the string between the backticks as a command and return the result.

HTH,
Michael.
The nice thing about computers is that they do exactly what you tell them. The problem with computers is that they do EXACTLY what you tell them.
Alexander M. Ermes
Honored Contributor

Re: How to set actual date in filename

Hi there.
Try this in a script :

DATUM=`date '+%y-%m-%d.%H:%M'`
export DATUM
#
mv oldfile oldfile_${DATUM}
#

Rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Daniel Schneider_3
Frequent Advisor

Re: How to set actual date in filename

Tahnk you all Guys for your fast help. Now it works!

Best Regards
Daniel
RolandH
Honored Contributor

Re: How to set actual date in filename

Hey Daniel,

I want like to give you another tip. If you tar you backup first in a diretory you will get a file that is called in your case

backup-29072003-1434.tar

Then you backup this dir with your backup sw on tape. But what happens after couple of month and you want delete the backups from the first two weeks in this directory? You go in the directory and you do an ll
# ll ( I know ll shows more - short form )
...
backup-01042003-1434.tar
backup-01052003-1434.tar
backup-01062003-1434.tar
...
backup-07042003-1434.tar
...
backup-07072003-1434.tar
...
backup-29072003-1434.tar
backup-30072003-1434.tar
backup-31072003-1434.tar

You see for a month it is O.K but if you have backups for more than a month in this directory the sorting order of your LC_NUMERIC will sort in not very logical.

But if you sort first YEAR-MONTH-DAY_TIME
you get first the oldest and the the youngest backups showed by ll command.
# ll
...
backup-20030401-1434.tar
backup-20030402-1434.tar
backup-20030403-1434.tar
...
backup-20030501-1434.tar
backup-20030502-1434.tar
backup-20030503-1434.tar
...
backup-20030729-1434.tar
backup-20030730-1434.tar
backup-20030731-1434.tar
...

So sometimes it could be better to change you time variable to
ACTDATE=`date +%Y%m%d`

Does that make sense to you?

Roland
Sometimes you lose and sometimes the others win
Cheryl Griffin
Honored Contributor

Re: How to set actual date in filename

Roland, That's a very good tip.

Cheryl
(Feedback only: no points please.)
"Downtime is a Crime."