Solved

Rsync problems

Posted on 2010-08-19
8
916 Views
Last Modified: 2013-12-16
Hi,

I have this script to run rsync and avoid prompt passwod.

This is my script:

#!/usr/bin/expect

spawn rsync --progress -av user@server:/var/www/vhosts/ /backups/vhosts/
expect \"*?assword:*\"
send -- "mypass\r"
expect eof

The problem is, when rsync strart download the files, after a minute crash, but if I run the rsync command "rsync --progress -av user@server:/var/www/vhosts/ /backups/vhosts/" out of script is work very well

Can you help me ?

Best regards

André Bolinhas
0
Comment
Question by:abolinhas
[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
8 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 33477458
An alternative to this would be to use rsync over ssh, and use a ssh key.  1.  avoid requirement for password, 2. more secure as connection is secured and no password is stored in a script.  3. no need for expect scripting.

i.e. rsync --progress -avz -e "ssh -i /path/to/key/id_dsa" user@server:/path/to/files/ /path/to/files/

I imagine the issue in the script is the 'expect eof' the rsync will send output to both stderr and stdout, so its probably mucking up the last line of the script.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33482795
Could also be a timeout problem.
Try "set timeout nnn" as the first line of your script (above "spawn ...").
Set nnn to a suitable value (in seconds), e.g. 900.
wmp
0
 
LVL 9

Author Comment

by:abolinhas
ID: 33483279
Hi,

@jeremycrussell - How can I do this ? Just generate new public key on remote server and copy the id_dsa.pub to ~/.ssh/ on other server?


@woolmilkporc - Like this ?
#!/usr/bin/expect

set timeout nnn
spawn rsync --progress -av user@server:/var/www/vhosts/ /backups/vhosts/
expect \"*?assword:*\"
send -- "mypass\r"
expect eof
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 2

Expert Comment

by:arunkeerthan
ID: 33483400
generate a public key in the server

# ssh-keygen -t rsa

it will tell you the location where is stores the key. copy that files content  from the server to your local machine /userhome/.ssh/authorized_keys

Then takeout your password storing script from your script file put the rsync commands set command alone and execute the script.

Thanks
arunkeerthan
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33483462
>> Like this ? <<
Yes. Don't forget to replace nnn with a "real" value.
0
 
LVL 9

Author Comment

by:abolinhas
ID: 33483477
Hi arunkeerthan,

I try this, but not work, still ask me for password.

I have generated the key on remote server and then I copied the id_rsa.pub to ~/.ssh/ on local server.
The I add the id_rsa.pub into authorized_keys file by this command "cat id_rsa.pub >> authorized_keys"

But still don't work.

Best
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 33483705
1) Nope if you already have a key pair on the local server e.g. ~/.ssh/id_rsa  and d_rsa.pub   or   ~/.ssh/id_dsa  and d_dsa.pub  simply transfer the PUBLIC (id_*sa.pub) file to your $HOME directory on the remote server, do a:

mkdir -p $HOME/.ssh
chmod go-w  $HOME
chmod 700  $HOME/.ssh
cat $HOME/id_*sa.pub >> $HOME/.ssh/authorized_keys
chmod 600  authorized_keys

Then on the local server, test the access:

ssh user@remote.ip 'uname -a'

2) On the expect front, change  nnn   to 100000
0
 
LVL 9

Author Closing Comment

by:abolinhas
ID: 33484334
Hi arober11,

This solution solve my problem.
"mkdir -p $HOME/.ssh
chmod go-w  $HOME
chmod 700  $HOME/.ssh
cat $HOME/id_*sa.pub >> $HOME/.ssh/authorized_keys
chmod 600  authorized_keys"

Many thanks for your help.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Microsoft will be releasing the Windows 10 Creators Update in just a matter of weeks. Are you prepared? Follow these steps to ensure everything goes smoothly and you don't lose valuable data on your PC.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

738 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