The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
Noob on Unix. bobtheb UNIX for Dummies Questions & Answers 7 07-10-2008 07:56 AM
how to copy a file to a directory ,where file and dir are sent as args to a function? wrapster Shell Programming and Scripting 0 06-08-2008 08:37 AM
Script to capture new lines in a file and copy it to new file fara_aris Shell Programming and Scripting 0 05-27-2008 11:11 PM
complete noob avdrummerboy UNIX for Dummies Questions & Answers 3 12-04-2006 12:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2008
wildside wildside is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Help. noob needs help with file copy!

So I have a very simple question that has come to be a huge headache.

I need to copy files from FolderA into FolderB replacing all files that already exist in FolderB UNLESS the date of the file in FolderB is newer than the date from the same file in FolderA. In the case that file is newer in the destination, I need to skip copy of that file and move on.

I have tried so many different things and nothing has been able to do what I need.

I have tried a simple cp -i but i need to filter by date and choose "don't overwrite" if file being copied is older, but owverwite is file date is same.

there is a long story to go along with this as well.

Thanks in advance
  #2 (permalink)  
Old 07-16-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,439
Check the man page for rsync and unison.
  #3 (permalink)  
Old 07-16-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
man cp

-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
  #4 (permalink)  
Old 07-17-2008
wildside wildside is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Thank you danmero for the rsync pointer.
cp -u does not work in OS 10.5 for some reason. I haad looked at that before.

So rsync looks like what i need. I ran some "dry-runs" with it and also some test runs.

using this convention:
$ rsync -vru --progress FolderA/ FolderB/

It only copies files from FolderA that are newer than files in FolderB.
It skips files that are the same size or date.
This is an expect from the rsync man page:

-u, --update This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file's, it will be updated if the sizes are different.)
So what i need to do is force rsync to use update to copy a file if it is equal or newer. NOT if it is ONLY newer.


Any ideas here?
  #5 (permalink)  
Old 07-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
If the destination file is equal in size and date, then surely its contents will be identical, and there won't be any need to copy it?
  #6 (permalink)  
Old 07-17-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
I think they are saying its not overwriting if the file size is the same even if the date is newer.
  #7 (permalink)  
Old 07-17-2008
wildside wildside is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Quote:
Originally Posted by Annihilannic View Post
If the destination file is equal in size and date, then surely its contents will be identical, and there won't be any need to copy it?

Not so. Now for the long story.

Ok a really short version of the long story.

We have a San Server with 43TB of user data. We backed said san server using some software to a backup san drive. We wiped the orginal san drive. Used the same software to restore the backup san drive contents to the live san drive.

Months later after users had been using the directoires on the san server, they start complaining of random files being corrupt when they open them. After manualy draging and droping the old backup file form the backup san over the (same exact date and size) file in the live san, the file works for them.

The files are random that are corrupt so we need to copy all the files that exist in the backup drive into the live drive overwriting the files if they exist but ONLY if the file date is equal of older than what is there as users have been updating files and adding to the directories.

whew. and that was the short version.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0