![](https://seccdn.libravatar.org/avatar/b72f250a4f5b7bc95f1e9b00f684ecc1.jpg?s=120&d=mm&r=g)
I have a shell script that I use to backup my main computer to hard drives connected to it. I edited it today to backup another computer over my Lan. This is the script: #!/bin/sh # backup.sh -- backup to a local drive using rsync # Directories to backup. Separate with a space. Exclude trailing slash! SOURCES="apollo@Linux:Test/" # Directory to backup to. This is where your backup(s) will be stored. TARGET="/data1/LinuxBackup" EXCLUDE_FILE="/home/apollo/rsync_exclude_file" # Comment out the following line to disable verbose output VERBOSE="-v" ########################### if [ -f $EXCLUDE_FILE ]; then EXCLUDE="--exclude-from=$EXCLUDE_FILE" fi for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi rsync $VERBOSE $EXCLUDE -avz -e ssh --delete $source/ $TARGET/ done This works. It puts a copy of the test file in /data1/LinuxBackup. It also produces a directory called: 'LinuxBackupapollo@Linux:Test' in /data1 that I don't want. When I run the script with: for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi commented out, it doesn't work so well. I get output like this: # sh backup2_remote3.sh building file list ... [sender] expand file_list to 131072 bytes, did move [sender] excluding directory dev because of pattern /dev/ [sender] excluding directory mnt because of pattern /mnt/ [sender] expand file_list to 262144 bytes, did move [sender] expand file_list to 524288 bytes, did move [4]+ Stopped sh backup2_remote3.sh How should I modify this script to not produce the 'LinuxBackupapollo@Linux:Test' folder in /data1? Thanks, Jerome
![](https://seccdn.libravatar.org/avatar/41ed85ec60b719fa1654d12375dd9bd6.jpg?s=120&d=mm&r=g)
On Wed, 2005-02-16 at 20:38, Susemail wrote:
I have a shell script that I use to backup my main computer to hard drives connected to it. I edited it today to backup another computer over my Lan. This is the script:
#!/bin/sh # backup.sh -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash! SOURCES="apollo@Linux:Test/"
# Directory to backup to. This is where your backup(s) will be stored. TARGET="/data1/LinuxBackup"
EXCLUDE_FILE="/home/apollo/rsync_exclude_file"
# Comment out the following line to disable verbose output VERBOSE="-v" ###########################
if [ -f $EXCLUDE_FILE ]; then EXCLUDE="--exclude-from=$EXCLUDE_FILE" fi
for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi rsync $VERBOSE $EXCLUDE -avz -e ssh --delete $source/ $TARGET/ done
This works. It puts a copy of the test file in /data1/LinuxBackup. It also produces a directory called: 'LinuxBackupapollo@Linux:Test' in /data1 that I don't want.
But that is what you are telling it to create with "mkdir -p $TARGET$source" $TARGET=/data1/LinuxBackup and $source=(actually it is not defined, $SOURCES is and ="apollo@Linux:Test/"). It appears you left out the "/" between $TARGET and $source so you are getting what you defined. If you want to further trouble shoot your source include echo statements for your variables to see if what you want is what you are going to get. I.E. echo $TARGET $source -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 * Only reply to the list please* "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
![](https://seccdn.libravatar.org/avatar/b72f250a4f5b7bc95f1e9b00f684ecc1.jpg?s=120&d=mm&r=g)
On Wednesday 16 February 2005 17:20, Ken Schneider wrote:
On Wed, 2005-02-16 at 20:38, Susemail wrote:
I have a shell script that I use to backup my main computer to hard drives connected to it. I edited it today to backup another computer over my Lan. This is the script:
#!/bin/sh # backup.sh -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash! SOURCES="apollo@Linux:Test/"
# Directory to backup to. This is where your backup(s) will be stored. TARGET="/data1/LinuxBackup"
EXCLUDE_FILE="/home/apollo/rsync_exclude_file"
# Comment out the following line to disable verbose output VERBOSE="-v" ###########################
if [ -f $EXCLUDE_FILE ]; then EXCLUDE="--exclude-from=$EXCLUDE_FILE" fi
for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi rsync $VERBOSE $EXCLUDE -avz -e ssh --delete $source/ $TARGET/ done
This works. It puts a copy of the test file in /data1/LinuxBackup. It also produces a directory called: 'LinuxBackupapollo@Linux:Test' in /data1 that I don't want.
But that is what you are telling it to create with "mkdir -p
for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi but just commenting out this section doesn't work well. I would like to know how to eliminate this section because that would eliminate the creation of
I know. That is why I commented out: the useless directory. But as I stated in my original email just commenting it out leaves a script that doesn't seem to work as well. As a work around I changed mkdir to touch. Even though there's nothing to touch, rsync backs up the test file and doesn't create the unwanted folder. This works, but there must be a better, more standard way to do this. Jerome
$TARGET$source" $TARGET=/data1/LinuxBackup and $source=(actually it is not defined, $SOURCES is and ="apollo@Linux:Test/"). It appears you left out the "/" between $TARGET and $source so you are getting what you defined.
If you want to further trouble shoot your source include echo statements for your variables to see if what you want is what you are going to get. I.E. echo $TARGET $source
-- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998
* Only reply to the list please*
"The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
![](https://seccdn.libravatar.org/avatar/a9970bdbb04154a18b3513cd397f49eb.jpg?s=120&d=mm&r=g)
Hi,
If you want to further trouble shoot your source include echo statements for your variables to see if what you want is what you are going to get. I.E. echo $TARGET $source
If you want to test, i would rather suggest to examine the result of file $TARGET and file $SOURCE It should yield a directory, or symbolic link To check wether they are existing directories. With the "echo" you only check if the variables are defined... Hans
![](https://seccdn.libravatar.org/avatar/41ed85ec60b719fa1654d12375dd9bd6.jpg?s=120&d=mm&r=g)
On Thu, 2005-02-17 at 03:12, Hans Witvliet wrote:
Hi,
If you want to further trouble shoot your source include echo statements for your variables to see if what you want is what you are going to get. I.E. echo $TARGET $source
If you want to test, i would rather suggest to examine the result of file $TARGET and file $SOURCE It should yield a directory, or symbolic link To check wether they are existing directories.
With the "echo" you only check if the variables are defined...
Hans
This is not my script, I was only offering some advise to the OP. And I don't need TWO copies of your reply which is why I state in my sig "* Only reply to the list please*" If you MUST do a reply to all because of your email client please have the courtesy to edit the To: or Cc: line. People on this list get a copy from the list and don't need two copies. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 * Only reply to the list please* "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
![](https://seccdn.libravatar.org/avatar/b72f250a4f5b7bc95f1e9b00f684ecc1.jpg?s=120&d=mm&r=g)
On Wednesday 16 February 2005 17:20, Ken Schneider wrote:
On Wed, 2005-02-16 at 20:38, Susemail wrote:
I have a shell script that I use to backup my main computer to hard drives connected to it. I edited it today to backup another computer over my Lan. This is the script:
#!/bin/sh # backup.sh -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash! SOURCES="apollo@Linux:Test/"
# Directory to backup to. This is where your backup(s) will be stored. TARGET="/data1/LinuxBackup"
EXCLUDE_FILE="/home/apollo/rsync_exclude_file"
# Comment out the following line to disable verbose output VERBOSE="-v" ###########################
if [ -f $EXCLUDE_FILE ]; then EXCLUDE="--exclude-from=$EXCLUDE_FILE" fi
for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi rsync $VERBOSE $EXCLUDE -avz -e ssh --delete $source/ $TARGET/ done
This works. It puts a copy of the test file in /data1/LinuxBackup. It also produces a directory called: 'LinuxBackupapollo@Linux:Test' in /data1 that I don't want.
But that is what you are telling it to create with "mkdir -p
for source in $SOURCES; do if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET$source fi but just commenting out this section doesn't work well. I would like to know how to eliminate this section because that would eliminate the creation of
I know. That is why I commented out: the useless directory. But as I stated in my original email just commenting it out leaves a script that doesn't seem to work as well. As a work around I changed mkdir to touch. Even though there's nothing to touch, rsync backs up the test file and doesn't create the unwanted folder. This works, but there must be a better, more standard way to do this. Jerome ps When I change SOURCES="apollo@Linux:Test/" to SOURCES="root@Linux:/" the script doesn't work using the root password for the 'Linux' computer: # sh backup2_remote2.sh touch: invalid option -- p Try `touch --help' for more information. opening connection using ssh -l root Linux rsync --server --sender -vvlogDtprz --delete . // Password: Password: Password: Permission denied (publickey,keyboard-interactive). rsync: connection unexpectedly closed (0 bytes read so far) rsync error: error in rsync protocol data stream (code 12) at io.c(342) How do I do this so I can backup the root directory? Thanks, Jerome
$TARGET$source" $TARGET=/data1/LinuxBackup and $source=(actually it is not defined, $SOURCES is and ="apollo@Linux:Test/"). It appears you left out the "/" between $TARGET and $source so you are getting what you defined.
If you want to further trouble shoot your source include echo statements for your variables to see if what you want is what you are going to get. I.E. echo $TARGET $source
-- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998
* Only reply to the list please*
"The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
![](https://seccdn.libravatar.org/avatar/41ed85ec60b719fa1654d12375dd9bd6.jpg?s=120&d=mm&r=g)
On Thu, 2005-02-17 at 03:14, Susemail wrote:
On Wed, 2005-02-16 at 20:38, Susemail wrote: <snip> but just commenting out this section doesn't work well. I would like to know how to eliminate this section because that would eliminate the creation of
On Wednesday 16 February 2005 17:20, Ken Schneider wrote: the useless directory. But as I stated in my original email just commenting it out leaves a script that doesn't seem to work as well.
As a work around I changed mkdir to touch. Even though there's nothing to touch, rsync backs up the test file and doesn't create the unwanted folder. This works, but there must be a better, more standard way to do this. Jerome
ps When I change SOURCES="apollo@Linux:Test/" to SOURCES="root@Linux:/" the script doesn't work using the root password for the 'Linux' computer:
Then define a different variable for the directory creation on the destination. Set up ssh keys on both machines and you won't need to supply a password in your script. Check the docs for info on doing this, I don't recall how to as it has been a while. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 * Only reply to the list please* "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
participants (3)
-
Hans Witvliet
-
Ken Schneider
-
Susemail