I have a text file with all the folder names in date order which I'm trying to call in a script to rsync to once backup folder, basically merging all the incremental backups.

while read filename
$ for f in ls -t /var/user-test/ | grep $filename; rsync -aL /var/user-test/$f /var/u-backup/secure/;
done < temp.txt

This script is meant to run through the different backup folders and sync them into one folder. My issue is one this script doesn't work and two is this the best way to merge incremental backups


Here's a better approach at what you're trying to do:

# Copy data from a number of directories specified by $file (and located in $source) into a single directory specified by $target


cat $file | while read directory; do

  rsync -aL "${source}${directory}/" "${target}"

  • Thanks, the script seems to copy all the folders to that directory but not merge them all into one folder. What im trying to do with the script is merge all the backups together and replace any old files with newer ones – Grimlockz Jul 8 '11 at 16:37
  • So you want all the files placed in the same directory, not directories for each source? I've updated the script to reflect that. The trailing slash on the source tells rsync to sync the files in the directory, not the directory itself. – Kyle Smith Jul 8 '11 at 17:01

You have many errors in your script, some are syntax errors, which the most obvious is that you have forgotten to add a do/done in your for loop; also there is a "$" sign at the beginning of the 5th line

however I can see also conceptual errors; like using the filename variable name in different contexts.

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.