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
Solved

Remote RSYNC using SSH?

Posted on 2004-08-23
7
446 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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux VM 6 101
cannot rename datastore 3 70
Quickest way to query Windows Event ID from a Linux Device 3 51
Upgrade BIOS / EUFI at Scale 4 55
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

840 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