0

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

Grimlockz
  • 325
  • 1
  • 2
  • 11

2 Answers2

1

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
Kyle Smith
  • 9,683
  • 1
  • 31
  • 32
  • 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 08 '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 08 '11 at 17:01
0

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.

hmontoliu
  • 3,753
  • 3
  • 23
  • 24