4

I am trying to find out if there is ways to convert a long list of rsync exclude patterns, that I am maintaining for the purpose of making sensible backups, to an explicit list of file and directory names.

The application is that I am trying to use the same list (whenever I update it by adding or removing a pattern) for a different application (mksquashfs). Both tools allow explicit file lists with one entry per line to be specified as exlude list, but the syntax for the patterns differs in details.

You may assume that the list to be converted consists of all kinds patterns, possibly including wildcards, allowed by rsync.

Two approaches are conceivable:

  1. Find out what rsync uses under the hook (it seems to be neither simple shell globbing nor find)
  2. Use rsync to produce the list by doing a --dry-run dummy transfer with verbose output (here I am not sure how to have it print the names of the excluded files)
  • Depending on the glob, there could be a very large number of files the exclude (many of which don’t exist yet) – Jeff Schaller Mar 31 '18 at 17:26
  • @JeffSchaller Sure. I would run the conversion just before I run the concerned backup scripts. – highsciguy Mar 31 '18 at 17:30
0

Something like this: where "${other_opts[@]}" indocates your normal rsync arguments.

rsync --dry-run --debug=FILTER  "${other_opts[@]}" /proc/$$/no-such-dir/

Should print out all the excluded files.

[sender] hiding file .bash_history-27611.tmp because of pattern *.tmp
[sender] hiding file .bash_history-21217.tmp because of pattern *.tmp
[sender] hiding file .bash_history-29735.tmp because of pattern *.tmp
[sender] hiding file .bash_history-20437.tmp because of pattern *.tmp

you can chop that up using sed.

sed '/^\[sender\] hiding file .* because of / {
  s/^\[sender\] hiding file \(.*\) because of .*/\1/
  p
  }
d '

but this might break if you encounter filenames that contain control characters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.