LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Tags used in this thread
Popular LQ Tags , , ,

Reply
 
Thread Tools
Old 03-04-2009, 10:06 AM   #1
ehlers
LQ Newbie
 
Registered: Mar 2009
Posts: 4
Thanked: 0
Sync files not folders with rsync (non recursive)


[Log in to get rid of this advertisement]
Hello,

okay this sounds really easy but I am having serious problems finding an anwser to this.

I want to sync *.htm and *.html between SOURCE AND DESTINATION. *.htm and
*.html which are not present in DESTINATION to be copied and *.htm and
*.html which are not present in SOURCE to be deleted in DESTINATION. I dont want rsync to touch any folders or their content.

The closest I have gotten is this command:

/usr/bin/rsync -dolptgvze --delete --include='*.htm' --include='*.html' --exclude='*' /SOURCE/ /DESTINATION/

But if I have a /DESTINATION/test.htm file and its not in /SOURCE/ it is not deleted. Of course I want this to happen.

Thanks for your help

ke
ehlers is offline  
Tag This Post , , ,
Reply With Quote
Old 03-04-2009, 10:29 AM   #2
chitambira
Member
 
Registered: Oct 2008
Location: Fife
Distribution: RHEL, Centos
Posts: 364
Blog Entries: 1
Thanked: 38
remove --exclude='*'
chitambira is offline     Reply With Quote
Old 03-04-2009, 10:37 AM   #3
ehlers
LQ Newbie
 
Registered: Mar 2009
Posts: 4
Thanked: 0

Original Poster
Thanks, but this is not helping at all. If I remove --exclude='*' then ALL files AND folders are synced (files with suffix != html oder htm) and still the test.htm from DESTINATION which is not in SOURCE is not deleted.
ehlers is offline     Reply With Quote
Old 03-04-2009, 11:38 AM   #4
ehlers
LQ Newbie
 
Registered: Mar 2009
Posts: 4
Thanked: 0

Original Poster
I got it working like this:

/usr/bin/rsync -ndolptgvze --delete-excluded --delete --include='*.htm' --include='*.html' --exclude='*' /S/ /D/

Can somebody please explain why this is such a big difference to

/usr/bin/rsync -ndolptgvze --delete --delete-excluded --include='*.htm' --include='*.html' --exclude='*' /S/ /D/

If I change the ordering of --delete and --delete-excluded everything in subfolders is deleted

Last edited by ehlers; 03-04-2009 at 11:42 AM..
ehlers is offline     Reply With Quote
Old 03-04-2009, 11:58 AM   #5
chitambira
Member
 
Registered: Oct 2008
Location: Fife
Distribution: RHEL, Centos
Posts: 364
Blog Entries: 1
Thanked: 38
I meant to say, if you use --delete, then you DO NOT have to use --exclude='*', BUT if you use --exclude='*', and --delete-excluded, then you DO NOT have to use --delete to achieve what you want.

In your first case only --delete is being used.
In the second case (working) --delete-excluded is the one now being used hence its combination with --exclude='*' is providing you the functionality that you want, thus deleting all other files on the DST.

Note that --delete acts on the SRC side and --delete-excluded acts on the DST side

Last edited by chitambira; 03-04-2009 at 12:03 PM..
chitambira is offline     Reply With Quote
Old 03-09-2009, 05:46 AM   #6
ehlers
LQ Newbie
 
Registered: Mar 2009
Posts: 4
Thanked: 0

Original Poster
sorry for the late reply but I was on holiday. Still I dont seem to understand rsync.

Quote:
I meant to say, if you use --delete, then you DO NOT have to use --exclude='*', BUT if you use --exclude='*', and --delete-excluded, then you DO NOT have to use --delete to achieve what you want.
I need to use --exclude='*' even when not applying --delete-excluded because if I not use --exclude='*' then rsync deletes stuff on the reciever which I do not want to have deleted.

Sender:

folder: source\
a.htm
b.htm
c.htm
d.htm

Reciever:

folder: destination\
files\folderA\abc.pdf
files\folderA\abcd.pdf
files\folderA\abce.pdf
a.htm
b.htm
c.htm
y.html

Now if I do:

/usr/bin/rsync -ndolptgvze "/usr/bin/ssh -i /var/lib/wwwrun/.ssh/id_dsa" --delete --include='*.htm' --include='*.html' /source/ /destination/

then folder files on destination is deleted (which I dont want)

If I use:

/usr/bin/rsync -ndolptgvze "/usr/bin/ssh -i /var/lib/wwwrun/.ssh/id_dsa" --delete --include='*.htm' --include='*.html' --exclude='*' /source/ /destination/

files folder on destination is not deleted but y.html on reciever is not deleted either.

The solution I found erlier is only working if the reciver path is on the same host so I am back to 0 here. The problem still remains. How do I sync *.htm and *.html files in a folder w/o rsync touching anything else in that folder.

Last edited by ehlers; 03-09-2009 at 05:51 AM..
ehlers is offline     Reply With Quote
Old 03-11-2009, 09:15 AM   #7
chitambira
Member
 
Registered: Oct 2008
Location: Fife
Distribution: RHEL, Centos
Posts: 364
Blog Entries: 1
Thanked: 38
Quote:
/usr/bin/rsync -ndolptgvze "/usr/bin/ssh -i /var/lib/wwwrun/.ssh/id_dsa" --delete --include='*.htm' --include='*.html' /source/ /destination/

then folder files on destination is deleted (which I dont want)
Remember!!!
--delete will delete files that donīt exist on the sending side, so when ever you specify it, be sure to delete some files on the /DST/ if they are not there in /SRC/

Quote:
If I use:

/usr/bin/rsync -ndolptgvze "/usr/bin/ssh -i /var/lib/wwwrun/.ssh/id_dsa" --delete --include='*.htm' --include='*.html' --exclude='*' /source/ /destination/

files folder on destination is not deleted but y.html on reciever is not deleted either.
In this case you are conflicting --delete and --exclude, and of course --exclude="*" wins, so --delete is not being used. y.html is not deleted because there nothing telling rsync to delete it.

Try:
/usr/bin/rsync -ndolptgvze "/usr/bin/ssh -i /var/lib/wwwrun/.ssh/id_dsa" --include='*.htm' --include='*.html' --delete-excluded /source/ /destination/

What you are trying to achieve may not be provided by rsync.
chitambira is offline     Reply With Quote
Old 03-11-2009, 10:53 AM   #8
David the H.
Senior Member
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian Sid/kde3.5
Posts: 2,464
Thanked: 130
You might want to take a look at unison. I'm not sure if it can do exactly what you want ('cause I'm still not clear myself on exactly what you want), but think it has a better chance than rsync.
David the H. is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync keeps backing up same folders over and over Red Squirrel Linux - Server 9 01-05-2009 12:37 AM
How can I use rsync to keep multiple clients in sync? BadTim Linux - Software 17 02-01-2008 05:07 AM
RSYNC Two Folders? Carlwill Debian 3 09-09-2007 01:17 AM
RSYNC Automatic sync script penguinpages Fedora 0 05-01-2007 12:52 PM
Samba can create new files and folders but access denied in any new folders k.king Linux - Networking 2 01-15-2006 07:14 AM


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

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration