Solved

Remote RSYNC using SSH?

Posted on 2004-08-23
7
469 Views
Last Modified: 2013-12-15
Hello All,

I am currently working with one server with a fixed ip address, and a backup server with a dynamic ip address.

The objective is to automize the backup process by running a cron job from the backup server.

I am using rsync for syncronizing the servers, however and since the ip is changing, the command need to be issued from the backup server so I may pass the new ip with it.

This is the script I first tried:

#!/bin/bash
ipaddr=`ifconfig ppp0 | grep "inet addr:" | cut -d ":" -f 2 | cut -d " " -f 1`;

ssh -l webserver "rsync -e ssh -aRvvz / backup@$ipaddr:/srv/backup --exclude=maillog --exclude=ftp.log --exclude=access.log --exclude=core --exclude=/var/lib/mysql --exclude=/dev --exclude=/proc --exclude=/mnt --exclude=/tmp --exclude=/var/spool/mail --exclude=/var/log --exclude=/var/www --exclude=/var/spool/MailScanner;";




I
0
Comment
Question by:kandresen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 36

Expert Comment

by:grblades
ID: 11873409
I normally just use rsync as in the following example to do it over ssh

rsync -a --delete -e ssh / backup@$ipaddr:/srv/backup --exclude=maillog --exclude=ftp.log --exclude=access.log --exclude=core --exclude=/var/lib/mysql --exclude=/dev --exclude=/proc --exclude=/mnt --exclude=/tmp --exclude=/var/spool/mail --exclude=/var/log --exclude=/var/www --exclude=/var/spool/MailScanner
0
 
LVL 36

Expert Comment

by:grblades
ID: 11873428
Sorry I have just realised what you are doing.

Cant you run a ddns client on the backup server and then just refer to it by its name?
http://www.dyndns.org/services/dyndns/
0
 

Author Comment

by:kandresen
ID: 11875198
Thanks for your comments, unfortunately I am not allowed to add such a service on the backupserver...

I will thus still be looking for a solution for passing the information through ssh, then have the server rsync'ing back again.

Kenneth
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:kandresen
ID: 11875445
I am realizing that my command was mostly correct all the time - the problem was that when the ip changes, the ssh connection asks me if I am sure I want to add the new ip to the list... It seems to be failing as the script I initialized cannot confirm the question...  I believe it will get fixed as I add the -f parameter to tell ssh to run in background.

Anyway thanks for all comments!
0
 
LVL 40

Accepted Solution

by:
jlevie earned 50 total points
ID: 11875769
Why not run the rsync on the backup server? That way you don't need to deal with a changing IP. Something along the lines of:

rsync -e ssh -Cav --delete backup@fixed-ip.dom.tld:/ /srv/backup ...
0
 
LVL 1

Expert Comment

by:magicMush
ID: 11888335
to automatically add the fingerprint to the known hosts
if you have an access to ssh configuation on backup machine

edit your ssh configuration file

usually located at

/etc/ssh/ssh_config

uncomment the line
#      StrictHostKeyChecking ask

and change it to
   StrictHostKeyChecking no

this might solve your problem.
0
 

Author Comment

by:kandresen
ID: 11893729
Hello all,

I got it to work already using ssh and rsyncing back again, however I an noticing that the rsync method jlevie is mentioning removes a lot of the security risks I am seeing with my current approach - I had to put a certificate on the backupserver for making it work thus letting anyone with access to the mainserver also easy get access to the backup server. By making jlevie's approach I can remove the certificate again.

Best regards,
Kenneth
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question