Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 33327  / 1 Year ago, tue, april 4, 2023, 9:09:40

I'm using ubuntu server 12.04, now I want to backup some files using rsync, here is a try:



rsync -aAX $HOME/Documents/* $HOME/Backups/TEST --exclude={$HOME/Documents/another/*,$HOME/Documents/temp/*} 


As you can see, I want to backup all files in the folder $HOME/Documents to folder $HOME/Backups/TEST, but exclude files in folder another and temp. But I failed, rsync still copied the files in both excluded folders:



ls $HOME/Backups/TEST/another
test


test is a file in the folder another, and it is also copied though I exclude the file in rsync, why? How to let those files be actually excluded?


More From » server

 Answers
4

There are several issues with your rsync command (also see manpage for rsync for detailed explanation of filter rules).




  • we need an --exclude command each for any given pattern.

  • paths given need to be relative to the source path (no absolute paths).

  • options need to be given before we state source and destination.



For your example the following syntax will work:



rsync -avAX --exclude=another/ --exclude=temp/ ~/Documents/ ~/Backups/TEST


Note that if an exlude pattern ends with / it refers to a directory. If you omit it both, files and directories with that name will be excluded. Replace it with a wildcard * to exclude all files or directories with that string in their names.


[#31360] Thursday, April 6, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
vigorousom

Total Points: 394
Total Questions: 96
Total Answers: 110

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;