Solved

Remote RSYNC using SSH?

Posted on 2004-08-23
7
424 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
7 Comments
 
LVL 36

Expert Comment

by:grblades
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:kandresen
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now