LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-05-2005, 07:36 PM   #1
obelxi
LQ Newbie
 
Registered: Feb 2005
Posts: 28

Rep: Reputation: 15
How does rsync work?


I'm just looking into using rsync to do some backups here and I have a few questions.

1. Do both the server and the client need to have rsync installed?
2. Is it possible to use rsync in conjunction with regular ftp to access a remote server?

I think I'm just a little confused as to how rsync works at this point and I have the feeling i'm looking at it a bit like ftp, curl, or wget... but it seems a little different. Can someone iron this out in my muddy little mind?

Many thanks,
Stuart
 
Old 03-05-2005, 09:06 PM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
rsync is a replacement for rcp, as far as I know you need rsync on both machines. You can't rsync to a ftp server unless that server has rsync. rsync can't directly communicate with a ftp daemon.
 
Old 03-06-2005, 12:50 AM   #3
KWTm
Member
 
Registered: Jan 2004
Distribution: Kubuntu 10.04 (Dell Linux-preinstalled laptop + a desktop); Maemo 5 (N900 phone computer)
Posts: 116

Rep: Reputation: 21
rsync: a great tool! Here's a short summary

"rsync" is a very handy command that I use all the time to back up my files to another computer on my home network. (Of course, you can back it up to the same local machine, on the same drive even, if you want.) Apparently it will check to see what part of which files have changed, and only transmit the changed portions.

I'm not sure if you need rsync on both the local and the remote machine, since I have the same setup on both machines. It shouldn't be too hard to install, though, so why not just install on both machines?

I ask my rsync command to transfer files via ssh. (Other options are FTP, rsync daemon, etc. Hmm, I guess that means you DON'T need rsync on the remote machine if you're transferring by ssh.) If I wanted to backup my files from the machine at 192.168.0.111 to my current machine, the rsync command I would use is:


rsync -ab --backup-dir=/my/local/trash/dir -e ssh 192.168.0.111:/source/dir/ /dest/dir/


You can replace the "192.168.0.111:" with "my_machine_name:" if you've got it defined in /etc/hosts, or of course you can omit it if you're backing up onto the same machine. Of course, the remote machine has to have the SSH daemon running. The "--backup-dir" option will move into the specified directory any files that would otherwise have been overwritten; you can then check this directory and delete it manually.

I learned this use of "rsync" from "Linux Server Hacks", a book by Rob Flickenger published by O'Reilly.
 
Old 03-06-2005, 03:42 AM   #4
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
Just to add to what was said above I use it on my own system in cron to backup my /home on an hourly basis ;

rsync --delete-after -avH /home/ /mnt/backup/home > /var/log/backup.log

explanation is to sync the files /home and /mnt/backup/home, delete the files on the destination which no longer exist on the source and record the events in a log file.

Also use it over ssh to backup my internet server;

rsync -ave ssh --delete webserver:/var/www/ /home/user_name/www/

note here I have the address of webserver in /etc/hosts so it resolves automatically and rsync is installed on both systems and is issued from the destination terminal.
 
Old 03-06-2005, 04:21 PM   #5
obelxi
LQ Newbie
 
Registered: Feb 2005
Posts: 28

Original Poster
Rep: Reputation: 15
Ok so say I have the following setup:

A webserver with the ip address of 192.168.1.111 which has ssh access.

The machine I am on has the ip of 192.168.1.112 and I have access to a linux terminal.

So now what I want to do is connect to the webserver, download a file located in /home/user/public_html/1.txt

After 1.txt has been downloaded it should be deleted from the server. Once this is done I would like to be able to make changes to 1.txt and then upload it again back to the server. I realize I could just leave it on the server, but this is a small part of a complex script that I am working on and it is necessary to remove the file from the server. How can I do this?
 
Old 03-06-2005, 05:14 PM   #6
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally posted by obelxi
Ok so say I have the following setup:

A webserver with the ip address of 192.168.1.111 which has ssh access.

The machine I am on has the ip of 192.168.1.112 and I have access to a linux terminal.

So now what I want to do is connect to the webserver, download a file located in /home/user/public_html/1.txt

After 1.txt has been downloaded it should be deleted from the server. Once this is done I would like to be able to make changes to 1.txt and then upload it again back to the server. I realize I could just leave it on the server, but this is a small part of a complex script that I am working on and it is necessary to remove the file from the server. How can I do this?
Write a script that uses ssh and scp.. since your only copying 1 file, scp will do the job. rsync is better when using multiple files and such...

A sample script that might get you going to launch from client A to connect to client B, copy the file back and then remove it:

Code:
#!/bin/bash

cd /path/you/want/to/place/your/remote/file
scp user@machineB:/home/user/public_html/1.txt .
sleep1
for machine in <your-remote-machine>
do
   ssh $machine rm /home/user/public_html/1.txt
done
You'll want to add some echo's in there to tell what's going on and such. And you'll probably want to make it so it uses ssh keys so it doesn't prompt for your password for each step. man ssh and scp for more details.
 
Old 03-07-2005, 01:49 AM   #7
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
If you are just wanting to edit files on the server then if you use kde I can recommend KBear as it gives sftp (ftp via ssh) and the login is automated once setup and you can then edit files on the server directly as well as examine files. If you are using the latest kde 3.3 you also use the command fish://webserver or previous versions will accept sft://webserver. This is the system I use on a daily basis. I only use rsync to backup the files on the server.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync help! slack66 Linux - Newbie 1 10-27-2005 07:40 AM
Rsync sant25 Linux - General 2 09-02-2005 03:34 PM
rsync -R didn't work Niceman2005 Linux - Networking 4 03-30-2005 08:30 PM
Windows Rsync Upload to Linux Rsync - permissions inspleak Linux - Software 0 10-12-2004 02:49 PM
Rsync buttersoft Linux - Software 4 11-05-2003 11:37 AM


All times are GMT -5. The time now is 03:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration