Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

#!/bin/bash
filename=/home/user/Scripts/Testing/temp.txt
while read filename
do
$ 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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

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

file=/home/user/Scripts/Testing/temp.txt
source=/var/user-test/
target=/var/u-backup/secure/

cat $file | while read directory; do

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

done
share|improve this answer
    
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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