Mailinglist Archive: opensuse (2271 mails)

< Previous Next >
Re: [SLE] Help me please
  • From: Martin Mielke <martin.mielke@xxxxxxxxxxxxx>
  • Date: Thu, 01 Apr 2004 11:04:18 +0200
  • Message-id: <406BDB12.4070601@xxxxxxxxxxxxx>
Hi,

handy wrote:

Hi I am a novice in Linux.
I want to do something in my sles with create a script for my database...my question is :

1. How to create a filename with date month year :
For example : my filename -> backup30012004


From 'man date':

%d day of month (01..31)

%m month (01..12)

%Y year (1970...)


it's quite easy to use and implement:

a) you can declare (note the backquotes):

day=`date +"%d"`
month=`date +"%m"`
year=`date +"%"`

full_date=${day}${month}${day}

or

full_date=${day}.${month}.${day}

or

full_date=${year}${month}${day}

so, your file would be:

mv original_filename backup_$fulldate


b) as in a), you declare $day, $month and $year but you don't declare $full_date:

mv original_filename backup_${day}${month}${day}


2. If I want compress with gzip, can I create the filename with date month year directly .
For example : gzip -9 backup30012004
If it is can be... how to make it


IIRC, gzip doesn't feature file renaming...
Taken from 'man gzip':
---
Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.
---

In your case, if you want to have a compressed backupDDMMYYYY file, do the backup on that filename and then compress it. A very general way:

1. tar -cvf mybackup_${full_date}.tar

2. gzip -v mybackup_${full_date}.tar


HTH,
Martin




< Previous Next >
References