DasKraut
DasKraut

Reputation: 113

RSYNC: Sync all files from a list of folders on a text file?

As part of a file management script I'm working on, I want to use rsync to read a list of POSIX paths to folders on a text file. Then I want it to move all those folders and their contents to another location. I tried the following:

rsync -avPh --no-R --files-from="/source/folders.txt" /  /destination/folders --remove-source-files

I even added --include="*" to the end, but it still only copies all the folders to the new location. It ignores all their contents, and also doesn't --remove-source-files. So I just end up with a bunch of folders in two places, with the source files ignored.

Both the source and destination live on the same volume. How do I make this work?

EDIT -- Someone asked for an example of what the contents of the folders.txt file looks like:

/volume1/Music/Media/Thee Milkshakes/Sing and Play 20 Rock and Roll Hits of the 50's and 60's (1991)
/volume1/Music/Media/Tony Bennett/Playin' With My Friends- Bennett Sings the Blues (2001)
/volume1/Music/Media/Thee Headcoats/The Kids Are All Square- This Is Hip! (1990)
/volume1/Music/Media/Tiger Army/II- Power of Moonlite (2001)
/volume1/Music/Media/T. Rex/Prophets, Seers & Sages- The Angels of the Ages (1968)
/volume1/Music/Media/Ted Leo and the Pharmacists/Mo' Living (2007)
/volume1/Music/Media/Ted Leo and the Pharmacists/tej leo(!), Rx + pharmacists (1999)
/volume1/Music/Media/Ted Leo and the Pharmacists/Tell Balgeary, Balgury Is Dead (Plus Solo!) (2003)
/volume1/Music/Media/Teenage Fanclub/Sparky's Dream (1995)
/volume1/Music/Media/Teenage Fanclub/Words of Wisdom & Hope (2002)
/volume1/Music/Media/Teenage Fanclub/God Knows It's True (1990)

Upvotes: 1

Views: 419

Answers (1)

Unamata Sanatarai
Unamata Sanatarai

Reputation: 6647

The --remove-source-files does not remove FOLDERS. It removes files. You would need to write an additional script to cleanup after the rsync, or use mv instead.

I would even go as far as to say that mv might be better since you are not transfering files across a network.

Here's an approximation (as I do not know the folders.txt contents) of the script to be appended to the rsync.

rsync -avPh --no-R --files-from="/source/folders.txt" /  /destination/folders --remove-source-files

while IFS= read -r src; do
  find $src -type d -empty -delete
done < source/folders.txt

here's an mv example:

while IFS= read -r src; do
  mv "$src" "destination/folders/$src"
done < source/folders.txt

Upvotes: 1

Related Questions