LinuxQuestions.org
Visit Jeremy's Blog.
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-11-2019, 11:10 AM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Rep: Reputation: 110Reputation: 110
How can I achieve this with rsync (or some other way)?


If I run rsync with the --delete-before option, it will delete from the destination everything that is not present in the source.

If I run sync with the -n option, it will tell me what it would have done and won't really do it.

What happens if I combine both? I get a report (mixed with other data) of everything that is present in the source and not in the destination.

Now, I want to use that report to actually copy those files present in the source and absent in the destination into a THIRD location.

Does rsync do that? I can't find it in the manual.
 
Old 08-11-2019, 07:00 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,613

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
rsync does not do that itself, but you can certainly log that ooutput, filter it for a source list, and then copy those specific files to that third location.

If I may ask, why is it that you want to do this?
 
Old 08-13-2019, 12:03 AM   #3
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
I don't see how the logic of --delete-before (or more simply --delete) applies to the task as you eventually described it.

Quote:
copy those files present in the source and absent in the destination into a THIRD location.
However, rsync can do what you want in one easy step. Use the --compare-dest option:

Code:
rsync -a FIRST --compare-dest=SECOND THIRD
 
1 members found this post helpful.
Old 08-13-2019, 03:35 AM   #4
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Sorry, the rsync command I wrote in the previous post may result in the creation of some empty directories in THIRD. The --compare-dest=SECOND option compares and excludes files only.

Why is that? To compare and exclude directories would require comparison of the entire directory hierarchy, that is, the contents of the directory with all its subdirectories. This is possible in principle, but apparently rsync does not attempt it.
 
1 members found this post helpful.
Old 08-13-2019, 06:34 AM   #5
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,613

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
Quote:
Originally Posted by Beryllos View Post
Sorry, the rsync command I wrote in the previous post may result in the creation of some empty directories in THIRD. The --compare-dest=SECOND option compares and excludes files only.

Why is that? To compare and exclude directories would require comparison of the entire directory hierarchy, that is, the contents of the directory with all its subdirectories. This is possible in principle, but apparently rsync does not attempt it.
Wait. Are you saying that you think that rsync only compares one level of the source and destination path?
What makes you think that? Have you examined the rsync man page?
 
Old 08-13-2019, 11:05 AM   #6
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by wpeckham View Post
Are you saying that you think that rsync only compares one level of the source and destination path?
No, I am not saying that, but my wording was perhaps ambiguous enough to suggest it.

What I meant to say is that rsync with compare-dest does all of its comparing, matching, and excluding at the level of individual files. The compare-dest option does not try to compare, match, or exclude deep structures such as whole directory trees with their contents.

The typical case where such a deep comparison would be desirable is a sparse backup of just the files and directories that have changed since a previous backup. Suppose that the user requires that the sparse backup contains only those directories which have changed at any subdirectory level, and within each subdirectory, only the files that have changed. Accordingly, if a whole directory and all of its contents are unchanged since the previous backup, the whole directory should be excluded from the sparse backup.

This is what I am saying rsync can't do, or at least I haven't figured out how to do it in a single rsync command. When a whole directory and all of its contents are unchanged since the previous backup, rsync with compare-dest will create the full directory tree containing no files at any level.

If one wishes to eliminate unnecessary empty directories, it can surely be done by other means, but before we go there, the Original Poster should clarify the requirements.
 
1 members found this post helpful.
Old 08-14-2019, 12:22 AM   #7
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Original Poster
Rep: Reputation: 110Reputation: 110
The problem is that I am working with a relatively small file system that cannot hold everything, and I want to create the sparse backup somewhere else where it is isolated so I have a better view of the content and can delete files, reorganize it, etc.
 
  


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
[SOLVED] best way to periodically rsync to clients from rsync server j1renicus Linux - General 2 09-19-2012 03:38 AM
Best way to achieve mailstore redundancy in Linux linux_linux Linux - Newbie 2 03-15-2008 08:53 PM
Can Qmail achieve the notice at the end of a letter? yoursmile Linux - Server 0 11-21-2006 09:19 PM
Something i'am trying to achieve using udev :: need some help small_boy22 Linux - Hardware 1 06-01-2005 10:19 AM
Can I achieve this? Xiangbuilder Linux - Newbie 20 10-25-2003 08:11 AM

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

All times are GMT -5. The time now is 04:11 AM.

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