LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Only overwrite larger files (https://www.linuxquestions.org/questions/linux-general-1/only-overwrite-larger-files-4175705172/)

DynV 12-19-2021 11:24 PM

Only overwrite larger files
 
How does one copy files and in doing so only overwrite larger files? Date is to be ignored, only if names match and destination is smaller there's overwriting (and of course if the file doesn't exist in destination it's copied).

Thank you kindly

syg00 12-19-2021 11:34 PM

man rsync

DynV 12-20-2021 06:54 AM

Quote:

Originally Posted by syg00 (Post 6311036)
man rsync

I couldn't find out how to do what I wanted exactly and neither could find an example for this case. Would you provide an example?

TB0ne 12-20-2021 07:41 AM

Quote:

Originally Posted by DynV (Post 6311089)
I couldn't find out how to do what I wanted exactly and neither could find an example for this case. Would you provide an example?

Why don't you post and tell us what you DID find/try, then??

Because putting "rsync only copy larger files" into Google pulls up more than 265,000 hits with examples, and the man page on rsync also has several things that will let you dictate what to copy, under what conditions.

DynV 12-20-2021 09:43 AM

Quote:

Originally Posted by TB0ne (Post 6311095)
Why don't you post and tell us what you DID find/try, then??

Because putting "rsync only copy larger files" into Google pulls up more than 265,000 hits with examples, and the man page on rsync also has several things that will let you dictate what to copy, under what conditions.

https://unix.stackexchange.com/quest...er-using-rsync
https://unix.stackexchange.com/quest...rite-if-larger
amongst many others, still with nothing to help with my issue.

Will you actually help with the OP?

Turbocapitalist 12-20-2021 09:54 AM

Rsync won't check the size, but it will check for changes in content and transfer the differences. So if the file gets smaller it will get updated just like if the file gets larger or if it changes content but stays the same size. The options to look for there are --archive, --hard-links, and --verbose. See the reference manual "man rsync" for details on those. There are other options which might be relevant depending on the quantity, size, and sparseness of the files to be transferred. Please write more about the characteristics of what you are transferring.

If you absolutely have to go by size then you'll have to script something, probably with find and stat in shell, if not Perl or Python.

Either way, show us what you've tried and where you are stuck so we can see 1) what's going on and 2) which tools you are familiar with and your approximate skill level with them. That way you can get an answer more suited to your situation.

TB0ne 12-20-2021 03:52 PM

Quote:

Originally Posted by DynV (Post 6311122)
https://unix.stackexchange.com/quest...er-using-rsync
https://unix.stackexchange.com/quest...rite-if-larger
amongst many others, still with nothing to help with my issue. Will you actually help with the OP?

Sorry, but you've been given a search term that has, as the VERY FIRST HIT, an example script that uses rsync just for this. You were advised to read the man page for rsync, which will give you options to pass to let rsync do what you want.

As turbocapitalist says, show us what you've done/tried first and we can assist from there. I would suggest reading the "Question Guidelines".

pan64 12-21-2021 03:39 AM

what about --min-size ?

shruggy 12-21-2021 04:03 AM

@pan64. This is not what the OP wants. Check the SE links discussed above.

pan64 12-21-2021 05:10 AM

Quote:

Originally Posted by shruggy (Post 6311320)
@pan64. This is not what the OP wants. Check the SE links discussed above.

I don't really understand what OP wants, and obviously the SE links were not really suitable. Would be nice to explain why.

SlowCoder 12-21-2021 08:05 AM

Quote:

Originally Posted by DynV (Post 6311035)
How does one copy files and in doing so only overwrite larger files? Date is to be ignored, only if names match and destination is smaller there's overwriting (and of course if the file doesn't exist in destination it's copied).

Please allow me to be curious. For what reasons would you want to change only larger files?

You could probably find all files matching your requirements using the 'find' command, then delete them, then run your backup to replace the "missing" files. I imagine that would net you the same effect.

The possible downside of that is that the deleted files will no longer be backed up until your backup operation is completed. But that probably isn't a problem, since you're wanting to replace them anyway.

DynV 12-21-2021 08:13 AM

Quote:

Originally Posted by SlowCoder (Post 6311351)
For what reasons would you want to change only larger files?

Beside starting & stopping, I cannot control the program that makes the files and I only want to keep the largest versions.

Quote:

Originally Posted by SlowCoder (Post 6311351)
You could probably find all files matching your requirements using the 'find' command, then delete them, then run your backup to replace the "missing" files. I imagine that would net you the same effect.

Indeed, with the difference if there's an issue it wouldn't affect only the file being worked on, but all the ones down the line; it's unlikely and wouldn't be much of an issue anyway. How would you do such a command?

SlowCoder 12-21-2021 08:21 AM

Quote:

Originally Posted by DynV (Post 6311353)
How would you do such a command?

Simple explanation on the find command that you could adapt: https://tecadmin.net/find-all-files-...size-in-linux/

Then you can pipe the output to rm. Then you can backup your newest file.

Take this constructively: I don't want to do it all for you; I'm a big proponent of "teach a man to fish".

pan64 12-21-2021 08:34 AM

Quote:

Originally Posted by DynV (Post 6311353)
I only want to keep the largest versions.

You need to implement it yourself, there is no tool which work that way. So you need to compare files one by one (source and destination) and act upon the result. The link you posted contains a solution to this problem. What's wrong with that?

Turbocapitalist 12-21-2021 08:47 AM

Quote:

Originally Posted by DynV (Post 6311353)
How would you do such a command?

I would make a shell script which uses stat to find the sizes of the two files, compare the results, and then copy if the one is larger. For that you'll probably need command substitution, depending on how you approach it.

You posted two links which almost do that in #5 above. Please say what is wrong with the second link, I mean in addition to it parsing of ls output.


All times are GMT -5. The time now is 10:31 PM.