Author Topic: rsync a list of files  (Read 1337 times)

0 Members and 1 Guest are viewing this topic.

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
rsync a list of files
« on: May 08, 2018, 08:57:18 pm »
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
« Last Edit: May 08, 2018, 09:32:55 pm by Keith »

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: rsync a list of files
« Reply #1 on: May 08, 2018, 10:08:59 pm »
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


Offline SeZo

  • Hero Member
  • *****
  • Posts: 1821
  • Karma: 139
  • Gender: Male
    • View Profile
    • Awards
Re: rsync a list of files
« Reply #2 on: May 15, 2018, 07:30:37 pm »
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:
--include=PATTERN
              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
              option.

--include-from=FILE
              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
              input.

So your dir-list.txt could contain:
/Desktop
/Documents
/Pictures
/Misc
/play
/Programming
/Radio

Then you would use(n=dry run):
Code: [Select]
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.

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: rsync a list of files
« Reply #3 on: May 15, 2018, 10:56:57 pm »
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. 

Cheers.

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: rsync a list of files
« Reply #4 on: May 25, 2018, 06:35:26 pm »
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. 

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal