LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Backing up file based on it's timestamp? (https://www.linuxquestions.org/questions/linux-general-1/backing-up-file-based-on-its-timestamp-575636/)

GSMD 08-08-2007 09:35 AM

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.

pwc101 08-08-2007 09:41 AM

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...

fudam 08-09-2007 12:50 AM

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;

chrism01 08-09-2007 07:55 PM

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.

colucix 08-10-2007 04:48 AM

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...

GSMD 08-10-2007 09:36 PM

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.


All times are GMT -5. The time now is 12:59 AM.