Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
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.
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.
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.
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)
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.