LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2010, 02:41 PM   #1
msmith88
LQ Newbie
 
Registered: Sep 2010
Posts: 1

Rep: Reputation: 0
Adding a files creation date to it's file name?


Hi all,

New to the forums here and fairly green when it comes to Linux. I have some basic experiencing creating simple scripts/making directories/changing permissions/etc. but I'm stumped on this one.

I have two linux boxes. I have a script set up on box 'A' to SCP into box 'B', grab a copy of a database backup and store it on box 'A'. It looks like this:

scp root@X.X.X.X:/blah/blah/blah/dump.23.gz /home/blah/DB_Backups/

I have generated a public key on box 'A' and placed it into the authorized_keys file on box 'B', so a password is not required and the file copies over successfully when the script is run. On to my problem...

I need to know what date the 'dump.23.gz' file was originally created when I'm viewing it after it's been copied to box 'A'. If I ls -l on box 'A' it only shows me the date it was created on box 'A' when it was copied.

What would I need to add to my script to append the backup's original creation date on box 'B' to the filename so that when it gets copied to box 'A' I know when the backup was created on box 'B'. I'm sure this is probably confusing. I've done lots of searching and can only find information on how to append the current date and time to a file name. I need to append it's original creation timestamp to the filename when it copies over. Any help is appreciated.

Thanks,
Matt
 
Old 09-17-2010, 03:03 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Would scp's -p option help?

Quote:
-p Preserves modification times, access times, and modes from the original file.
scp -p root@X.X.X.X:/blah/blah/blah/dump.23.gz /home/blah/DB_Backups/

Hope this helps.

Last edited by druuna; 09-17-2010 at 04:07 PM. Reason: fixed typo
 
Old 09-17-2010, 03:13 PM   #3
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
Take a look at the date command. It has the possibillity to format its output.
Example:
Code:
$ date +%a-%d-%b
Fri-17-Sep
Combine this with your copy command
Code:
scp root@X.X.X.X:/blah/blah/blah/dump.23.gz /home/blah/DB_Backups/`date +%a-%d-%b`-dump.23.gz
Notice the backquotes around the date command. The will make sure that the date command will be executed and the output from it will be used as text in the scp command.

____________________
Gerrard
 
Old 09-17-2010, 03:34 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@gdejonge: That will add the current date to the file, not the original date of the scp'ed file.
 
Old 09-18-2010, 12:44 AM   #5
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
Quote:
Originally Posted by msmith88 View Post
I need to append it's original creation timestamp to the filename when it copies over.
As i under stand your question you want original file creation time stamp.

just say example you create one file on 1st September and this file modify many time after creation. now you want to creation time (1st September) am i right ?

As i know linux filesystem do not store file creation date and time.

BTW you can find last access modify time by stat command.
Code:
[root@localhost ~]# stat test
File: `test'
  Size: 9703            Blocks: 24         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 1558337     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2010-09-18 10:21:01.000000000 +0530
Modify: 2010-09-18 10:21:15.000000000 +0530
Change: 2010-09-18 10:21:15.000000000 +0530
or you can preserve time -p option as suggest by druuna.

HTH

Regards,

Last edited by sem007; 09-18-2010 at 12:46 AM. Reason: add command
 
Old 09-18-2010, 01:03 AM   #6
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,138
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
scp -p
 
Old 09-18-2010, 07:51 AM   #7
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 813

Rep: Reputation: 195Reputation: 195
ls -l <filename> | awk '{get the date column'} | mv filename filename_output_of_awk.

What did you try so far?
 
0 members found this post helpful.
Old 09-18-2010, 07:56 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Did you read the question?

Quote:
Originally Posted by AnanthaP View Post
ls -l <filename> | awk '{get the date column'} | mv filename filename_output_of_awk.
How would you implement this when the file is on box A, you copy it to box B (time-stamp is now current time on box B, not creation time as mentioned on box A)???

As mentioned by me and other later on: use scp -p ........ Problem solved.
 
Old 09-19-2010, 01:07 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
As said by sem007
Quote:
linux filesystem do not store file creation date and time.
You need to have the original creation of the dump file include the date/time as part of the name...
 
Old 01-20-2011, 12:23 PM   #10
reg360
LQ Newbie
 
Registered: Jan 2011
Distribution: jaunty
Posts: 2

Rep: Reputation: 0
I submitted a script at this other thread because I had the same task as the original poster there:
http://www.linuxquestions.org/questi...lename-800333/

As already suggested on this thread, preserve the original dump file date with "scp -p". Then maybe use "stat" or something else to get file metadata. Then script something like I did to add that info back into your filename on box "A" (or on whatever box/filename you want the timestamp to be stored)
 
Old 01-20-2011, 09:16 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
The problem with that is if you want/need to copy or access that file again, or even the original on box B via another cmd etc.
It really is best to amend the actual backup script to insert the date (& optionally time) in the backup filename. Then you never need to worry.
Think about what would happen if you back it up to external storage eg tape, DVD. You'd always have to remember (& be able) to find a cmd that does the -p feature. This may not always be the case...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File creation date of vfat / fat32 files on linux snail Linux - Newbie 3 06-03-2009 06:56 PM
Listing of files on creation date ZAMO Linux - General 1 01-25-2008 07:45 AM
file creation date prashantbhushan Linux - General 2 05-29-2007 09:32 AM
Finding out the creation date for files/folders... darkarcon2015 Linux - Software 1 03-24-2005 06:59 PM
ls -al file creation date blackzone Linux - Newbie 2 08-23-2004 02:31 AM


All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration