Help. noob needs help with file copy!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help. noob needs help with file copy!
# 1  
Old 07-16-2008
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  
Old 07-16-2008
Check the man page for rsync and unison.
# 3  
Old 07-16-2008
man cp

-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
# 4  
Old 07-17-2008
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  
Old 07-17-2008
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  
Old 07-17-2008
I think they are saying its not overwriting if the file size is the same even if the date is newer.
# 7  
Old 07-17-2008
Quote:
Originally Posted by Annihilannic
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh CSV to XML file (noob tier)

Hey all, I'm very new to shell scripting and would love some help. I have been messing around with KSH at my job, and have been tasked with generating an XML file from multiple CSV files. However, I barely even understand the syntax for for loops! Output should be something along the lines of ... (2 Replies)
Discussion started by: Parrakarry
2 Replies

2. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

3. UNIX for Dummies Questions & Answers

Noob questions.. Append output to a file in different directory

Noob question! I know almost nothing so far, and I'm trying to teach myself from books, on a typical command line without using scripts how would I append output from a sort to a file in a completely different directory? example: If I'm sorting a file in my documents directory but I... (2 Replies)
Discussion started by: Byrang
2 Replies

4. Shell Programming and Scripting

Noob's 1st...bash-script for copying one file into many

I have one file "file.a.b.c-d.r" that I would like to use to spawn 4 other files: "file.a.b.1-A.r" "file.a.b.1-B.r" "file.a.b.1-C.r" "file.a.b.1-D.r" where the field "c-d" changes into my 1 and A-D. I was doing this manually at the prompt with > cp "file.a.b.c-d.r" "file.a.b.1-A.r" >... (13 Replies)
Discussion started by: WSUToad
13 Replies

5. UNIX for Dummies Questions & Answers

I'm a noob at Lynx...

So... I'm using lynx on a Mac... I didn't know that the whole dang thing is in Terminal? I rarely use terminal. I can't even figure out how to start the thing up. I type in lynx into it and press enter... And the cursor just goes down. Nothing happens like the FAQ websites describe. I feel so... (6 Replies)
Discussion started by: yennster
6 Replies

6. UNIX for Dummies Questions & Answers

Noob on Unix.

This may seem really easy to alot of you but i am a real noob on unix. I have been set the task to make a script which will answer a query. Basically I will have made files for people and i want to be able to search for a persons file and then select certain variables from the files. e.g... (7 Replies)
Discussion started by: bobtheb
7 Replies

7. Linux

noob help needed

i'm having trouble putting together a program :( any help would be much appreciated! Write a Shell Program to automate the process of collecting assignments from the directories of students of any specified class. The person running the program should be able to pass a parameter to the... (1 Reply)
Discussion started by: ace_face
1 Replies

8. UNIX for Dummies Questions & Answers

complete noob

Hi all, This is my first post. I am a complete noobie to the UNIX OS, I have an iMac G5 with the unix shell built in and am interested in learning how to use it to do things useful with it, but have no idea where to start. I have read over the basic commands but they haven't helped me much yet.... (3 Replies)
Discussion started by: avdrummerboy
3 Replies

9. UNIX for Dummies Questions & Answers

I am a unix noob

Hello i am new to this forum. I signed up here really to ask one question. I recentaly got a old unix server from my work and i never really understood what unix is or what is does. Dont get me wrong i and very smart with computers as long as its windows, mac, or linux i can use them all but i... (4 Replies)
Discussion started by: alt+f4
4 Replies
Login or Register to Ask a Question