LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-08-2007, 09:35 AM   #1
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Rep: Reputation: 16
Backing up file based on it's timestamp?


A piece of software generates daily backups named after date/time generated (e.g. daily-backup-2007_07_31.zip).
The thing I need to do is upload the latest backup to a remote server.
Now, I need to get the filename to backup.
My idea is to get the value from a "ls -lht" parsed with awk|sed.

Could there probably be a more elegant solution?

TIA.
 
Old 08-08-2007, 09:41 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Assuming there's only one backup per day, you could use find to search for files modified within the last 24 hours and use the -exec flag to copy the file over. It should be a one-liner...
 
Old 08-09-2007, 12:50 AM   #3
fudam
Member
 
Registered: Feb 2006
Distribution: FC
Posts: 86

Rep: Reputation: 15
i'm sure this is not less elegant... but why not:

Code:
   for i in $(ls -tr); do sleep 0;  done; cp $i /new/location;
 
Old 08-09-2007, 07:55 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
ls -t|head -1| do_file_txfr

BTW, sleep 0 still starts the sleep process for each file it finds, that's (potentially) a fair bit of overhead and unnecessary.
 
Old 08-10-2007, 04:48 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If you have to do this regularly (e.g. on a daily basis, as the backups are being created) I suggest to build the filename you expect to find and look for it on the local server. For example, if you want to upload the last created backup one day before the current day you can easily do
Code:
filename=daily-backup-$(date -d yesterday +%Y_%m_%d).zip
In this way you can take more control on the situation, do some checks and take appropriate actions if something is not as you expected, e.g.
- retrieve the backup of the previous day if the last one has not been crated, yet
- do e-mail notification about something going wrong
and so on...
 
Old 08-10-2007, 09:36 PM   #6
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Original Poster
Rep: Reputation: 16
Guys, thanks for your replies.
Actually I've ended up with
Code:
ls -lhtr /var/opt/confluence/backups | tail -n -1 | cut -d" " -f8
which was then modified to what chrism01 supplied.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Subversion timestamp in file darkarcon2015 Linux - Software 1 05-17-2006 07:45 PM
How to get the timestamp of a file? operand Linux - Newbie 7 01-20-2006 04:14 AM
Insert date and timestamp Into File name petenyce Linux - Newbie 9 10-13-2005 12:16 PM
Timestamp of file/directories Ephracis Linux - Software 1 12-16-2004 09:21 AM
add timestamp to name of file how? supafly Linux - General 3 11-14-2001 11:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:28 PM.

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
Open Source Consulting | Domain Registration