Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using rsync to connect and back up to a hard drive on a remote computer that I have ssh access to. rsync is connecting correctly. The code that's working is

rsync -av --progress -e "ssh -p port_number -i key/file/path" \
  "path/on/local/computer/to/back/up" \
  ssh_username@ssh_ip_address:"'path/on/remote/computer/to/back/up/to'"

I'm wondering if there is a way to get rsync to use its --log-file option to generate a log-file on the remote system (I want the file to be on the same remote hard drive that I'm backing up to). Any time I give it a remote path to use for the log-file (for example, with --log-file="path/on/remote/computer"), it seems to be looking for the path on my local system. I even tried --log-file=ssh_username@ssh_ip_address:path/on/remote/system, but it didn't work.

Is this possible, or do I need to make a log-file on the local system and then scp it to the remote system?

Both the local and remote systems are running Ubuntu 12.04.

share|improve this question
    
What OS are you using? It might be relevant. –  terdon Feb 2 '13 at 19:34
    
@ terdon, ha, I edited my post with that information at the same time as you were commenting. I'm using Ubuntu 12.04 on both systems. –  J L Feb 2 '13 at 19:36
add comment

1 Answer

up vote 0 down vote accepted

I would do the rsync to the other machine and then just run a scp command after to put the locally generated log file to the remote system where you'd like it kept.

rsyncing file + log

% rsync -avz -e 'ssh' $HOME/sample.sh remotemach:~ \
                --log-file=$HOME/rsync.log ; scp $HOME/rsync.log remotemach:~

confirming

% ls -l ~/rsync.log ~/sample.sh
-rwxrwxr-x 1 saml saml 10059 Oct 15 15:20 /home/saml/sample.sh
-rw-r--r-- 1 saml saml   192 Feb  2 14:57 /home/saml/rsync.log

% ssh remotemach "ls -l sample.sh rsync.log"
-rwxrwxr-x 1 saml saml 10059 Oct 15 15:20 sample.sh
-rw-r--r-- 1 saml saml   192 Feb  2 14:54 rsync.log

concatating the log to the remote side

If you'd like to concatanate the results from rsync to a remote file you can use a compound command (see bash's man page). Here I'm wrapping rsync with parens, and piping its output to ssh through a pipe, i.e.:

(rsync ...) | ssh ...

1st file copied

% (rsync -avz -e'ssh' $HOME/sample1.sh remotemach:~) \
                    | ssh remotemach "cat >> \$HOME/rsync.log"

confirm 1st copy

% ssh remotemach "ls -l sample*.sh rsync.log"
-rw-r--r-- 1 saml saml   133 Feb  2 19:49 rsync.log
-rwxrwxr-x 1 saml saml 10059 Feb  2 19:25 sample1.sh

2nd file copied

% (rsync -avz -e'ssh' $HOME/sample2.sh remotemach:~) \
                    | ssh remotemach "cat >> \$HOME/rsync.log"

confirm 2nd copy

% ssh remotemach "ls -l sample*.sh rsync.log"
-rw-r--r-- 1 saml saml   266 Feb  2 20:03 rsync.log
-rwxrwxr-x 1 saml saml 10059 Feb  2 19:25 sample1.sh
-rwxrwxr-x 1 saml saml 10059 Feb  2 19:25 sample2.sh

NOTE: Pay special attention to the file on the right side of the ssh. Notice that the $HOME path has a forward slash () in front of the $HOME. This is on purpose. It's necessary to escape the $HOME so that the local host's bash shell does not expand it.

share|improve this answer
    
@ slm, that makes sense. Thank you! What I would like to do is append the log-file to an existing log-file on the remote machine. Can scp append rather than overwrite a file? –  J L Feb 2 '13 at 23:17
    
Following my question to @ slm above, I realized (following the post at linuxquestions.org/questions/linux-newbie-8/append-file-681666/…) that something like cat localfile | ssh user@remoteserver "cat >> remotefile" might work. –  J L Feb 2 '13 at 23:31
    
I've expanded the answer to include a concatenation example as well. –  slm Feb 3 '13 at 1:23
    
Thank you! That's very helpful! –  J L Feb 3 '13 at 1:47
    
The compound command method gives you a way to accomplish what you were originally asking too. I didn't think of it until after. –  slm Feb 3 '13 at 1:49
add comment

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.