Solved

Rsync problems

Posted on 2010-08-19
8
913 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
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
 
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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
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.

919 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

21 Experts available now in Live!

Get 1:1 Help Now