You can now choose from a number of pre-installed themes

rsync a list of files

Started by Keith, May 08, 2018, 08:57:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I've been using rsync in a script one directory at a time, which is fine, but it would be more compact if I can get rsync to read the necessary directories/files from a file and the man pages offer the --files-from=FILE option.  Unfortunately I can't get this to work and the response is:
rsync error: syntax or usage error (code 1) at options.c(2308) [client=3.1.1]

My statement might be something like:  rsync -a  --files-from=dir-list.txt  /media/keith/BACKUP_USB

I would be very grateful for advice.

Thank you


Found it! 
The trick is:  "Note that you still have to specify the directory where the files listed are located, for instance: rsync -av --files-from=file-list . target/ for copying files from the current dir."
Note the dot (" . ") between "-list" and "target".   Not obvious from the man pages! 

Found here: https://stackoverflow.com/questions/16647476/how-to-rsync-only-a-specific-list-of-files


If you want rsync to run on specific directories then (instead of specific files) then you might be better off with --include-from option.
The manpage says:
              This  option  is  a  simplified form of the --filter option that
              defaults to  an  include  rule  and  does  not  allow  the  full
              rule-parsing syntax of normal filter rules.

              See  the  FILTER  RULES section for detailed information on this

              This option is related to the --include option, but it specifies
              a  FILE  that  contains  include patterns (one per line).  Blank
              lines in the file  and  lines  starting  with  ';'  or  '#'  are
              ignored.   If  FILE  is  -,  the list will be read from standard

So your dir-list.txt could contain:

Then you would use(n=dry run):
rsync -an --delete --prune-empty-dirs --include-from= $HOME/dir-list.txt $HOME/ /media/keith/BACKUP_USB
Assuming dir-list.txt is in /home/keith directory
Once you are happy that it is working as intended then remove the n option.


Many thanks for your very detailed reply, SeZo. 
I do struggle to understand the man pages so your example is very helpful.  I shall practice for a while and report on progress. 



Well - tests did not go well. 
After using the -n option without errors, a live test resulted in:

  • all the existing files on the USB being deleted, then
  • the system appeared to be copying all files on the system, not just those in the backup file-list
I had to crash out.  I think I might give this method some serious (and safe) practice before trying it again!  But thank you for the suggestion.