个人工具

“UbuntuHelp:Rsync”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
 
(未显示3个用户的7个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/rsync}}
 
{{From|https://help.ubuntu.com/community/rsync}}
 
{{Languages|UbuntuHelp:rsync}}
 
{{Languages|UbuntuHelp:rsync}}
== 简介 ==
+
This article is part of the [[UbuntuHelp:BackupYourSystem|BackupYourSystem]] series. More introductory information can be found there.
 +
== Introduction ==
 +
''From the man page:''
 +
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.
 +
In other words, rsync is a tool for efficiently copying and backing up data from one location (the ''source'') to another (the ''destination''). It is efficient because it only transfers files which are different between the source and destination directories.
 +
== Rsync ==
 +
Rsync is a command line utility. Users attempting to use it should be familiar with the command line (see [[UbuntuHelp:UsingTheTerminal|Using the Terminal]]). If you prefer a graphical interface, see the [[UbuntuHelp:rsync#Grsync|Grsync]] section of this page.
 +
=== Installation ===
 +
Rsync is installed in Ubuntu by default. Be sure to check whether the following packages are installed before starting (see [[UbuntuHelp:InstallingSoftware#installing-a-package|Installing a Package]]): [[UbuntuHelp:apt:rsync,xinetd,ssh|rsync, xinetd, ssh]].
 +
=== Perform a Simple Backup ===
 +
The simplest method for backing up over a network is to use rsync via SSH (using the <code><nowiki>-e ssh</nowiki></code> option). Alternatively, you can use the rsync daemon (see [[UbuntuHelp:rsync#Rsync Daemon|Rsync Daemon]] which requires much more configuration. Local backup only requires rsync and read/write access to the folders being synchronized. Below you will find examples of commands that can be used to backup in either case. It should be noted, that a network sync can be performed locally so long as the folder is shared (say by [[UbuntuHelp:SettingUpSamba|Samba]]) and then mounted to the machine with folder1. This process gets around having to use ssh but is less secure and should only be used in secure private networks, like at your home.
 +
'''Local Backup'''
 +
<pre><nowiki>
 +
sudo rsync -azvv /home/path/folder1/ /home/path/folder2
 +
</nowiki></pre>
 +
'''Backup Over Network'''
 +
<pre><nowiki>
 +
sudo rsync --delete -azvv -e ssh /home/path/folder1/ [email protected]:/home/path/folder2
 +
</nowiki></pre>
 +
An explanation of above options to commands:
 +
*<code><nowiki>--delete</nowiki></code> deletes files that don't exist on the system being backed up.(Optional)
 +
*<code><nowiki>-a</nowiki></code> preserves the date and times, and permissions of the files (same as <code><nowiki>-rlptgoD</nowiki></code>).
 +
. With this option rsync will:
 +
. Descend recursively into all directories (<code><nowiki>-r</nowiki></code>),
 +
. copy symlinks as symlinks (<code><nowiki>-l</nowiki></code>),
 +
. preserve file permissions (<code><nowiki>-p</nowiki></code>),
 +
. preserve modification times (<code><nowiki>-t</nowiki></code>),
 +
. preserve groups (<code><nowiki>-g</nowiki></code>),
 +
. preserve file ownership (<code><nowiki>-o</nowiki></code>), and
 +
. preserve devices as devices (<code><nowiki>-D</nowiki></code>).
 +
*<code><nowiki>-z</nowiki></code> compresses the data
 +
*<code><nowiki>-vv</nowiki></code> increases the verbosity of the reporting process
 +
*<code><nowiki>-e</nowiki></code> specifies remote shell to use
 +
*<code><nowiki>/folder1 and folder2</nowiki></code> In the examples above, folder1 and 2 are placeholders for the directories to be synchronized. Folder1 is the original folder, and 2 is the new folder, or existing one to be brought in sync with the first. Replace them with the folders you'd like. A / was added after folder1 so that only the contents, rather than whole folder, would be moved into the second.
 +
A complete synopsis of all the options with the rsync command can be found in the man pages under "Options Summary". The man page for rsync can also be found on [http://linux.die.net/man/1/rsync linux.die.net]
 +
== Grsync ==
 +
Grsync is a GUI frontend for the rsync utility. The simple interface of the GUI exposes many of the basic options available with rsync. It is useful for those who prefer not to use the command line.
 +
=== Installation ===
 +
The program grsync does not come installed by default on Ubuntu or any other distrubtion but it is easily available from the main [[UbuntuHelp:Repositories]]. To get grsync ensure '''Universe''' section of the Ubuntu repositories is enabled in your [[UbuntuHelp:Repositories/Ubuntu|Software Sources|Repositories/Ubuntu|Software Sources]]. Then to install this software in Ubuntu, [[UbuntuHelp:InstallingSoftware#installing-a-package|install the following package]]: '''''[[UbuntuHelp:apt:grsync|grsync]]'''''.
 +
=== Configuration ===
 +
To start up grsync go through the following menus: Applications --> System Tools --> grsync. Upon start up you'll be presented with the main window, where all the configuration takes place.
 +
https://help.ubuntu.com/community/rsync?action=AttachFile&do=get&target=grsyn1.png
 +
On this window are all of the options most users will ever need. To explain, the options will be listed and their effects mentioned.
 +
* '''Sessions''' - This function is the same as profiles in others. Each session will store a different set of source and destination directories, as well as the configuration options associated with the folder pair. This allows for the synchronization of different sets of folders according to different options.
 +
* Management of sessions is simple, simply push the '''Add''' button to add a new one. To delete, select the session you no longer want from the drop down and push '''Delete'''.
 +
* '''Source and Destination''' - These two boxes list the two folders (technically referred to as directories) that will be synchronized. The top one is the '''Source''' and the bottom the '''Destination'''. So when you '''Execute''' the synchronization, the files from Source will be copied over to the Destination according to the options a user selects.
 +
* To specify the directories either '''Browse''' for them from the GUI or type them in according to the standard path conventions.
 +
* '''Switch''' - The universal reload sign located to the right of the '''Browse''' buttons is a handy button. It will instantly switch the '''Source''' with the '''Destination'''.
 +
* '''Import''' and '''Export''' - After having configured sessions, a user may want to back them up for storage. To do so, simply go to the Sessions Menu at the top and select either '''Import''' or '''Export'''. The former will restore a session from a backup previously made, the latter will make a backup of the current session.
 +
* Note: This backup function works on a <u>per session</u> basis. This means, each session you want to back up must be selected from the drop down and then backed up. If you have 3 different sessions, select each in turn and '''Export''' them. Same when importing sessions.
 +
* '''Basic Options''' - Most users will find most of the options they will ever need here. The first four will preserve the properties of the files transferred. The others will modify how the files are copied. For more information on what each does specifically, hover your stationary cursor over the option and it will display a small explanation. The options checked are of course the ones that will be applied during the session.
 +
https://help.ubuntu.com/community/rsync?action=AttachFile&do=get&target=grsyn2.png
 +
* '''Advanced Options''' - This tab holds more options, many are useful and self-explanitory. For those not understood, tooltips will be displayed when the mouse remains over an option long enough.
 +
* '''Additional Options''' - This entry box allows the input of additional options not presented in the GUI but known to the user. Use is suggested only for experienced users, inputting malformed options may have unexpected consequences.
 +
=== Simulation and Execution ===
 +
The last two buttons on the window are '''Simulation''' and '''Execute'''. The button for simulation is very useful when uncertain what will happen based on the options selected. The normal transfer dialog screen will pop up and in the main pane, a list of files that would have been copied over is listed. The user can then verify if this is as desired or make changes. Once the session is initiated with the '''Execute''' button, the dialog will appear again but this time it will actually process the folders accordingly. Ensure before pushing '''Execute''' that you are happy with the simulation.
 +
=== Remote Backup ===
 +
Backup over a network is possible, preferably the user should mount the network share to be backed up to prior to launching the program. The share would then be listed in the Browse GUI and could easily be added. There is no separate section for network, if more advanced features are required the user is encouraged to look at alternatives, of which there are many.
 +
=== Alternatives ===
 +
There are many alternatives, in various stages of development. For an incomplete list, see [http://www.debianadmin.com/rsync-backup-web-interfacefrontend-or-gui-tools.html here].
 +
== Rsync Daemon ==
 +
The rsync daemon is an alternative to SSH for remote backups. Although more difficult to configure, it does provide some benefits. For example, using SSH to make a remote backup of an entire system requires that the SSH daemon allow root login, which is considered a security risk. Using the rsync daemon allows for root login via SSH to be disabled.
 +
=== Configuration of the rsync Daemon ===
 +
1. Edit the file <code><nowiki>/etc/default/rsync</nowiki></code> to start rsync as daemon using xinetd. The entry listed below, should be changed from false to inetd.
  
RSYNC的简单配置
+
<pre><nowiki>
 +
RSYNC_ENABLE=inetd
 +
</nowiki></pre>
 +
2. Install xinetd because it's not installed by default.
  
== 导言  ==
+
<pre><nowiki>
 +
$ sudo apt-get -y install xinetd
 +
</nowiki></pre>
 +
2. Create the file <code><nowiki>/etc/xinetd.d/rsync</nowiki></code> to launch rsync via xinetd. It should contain the following lines of text.
  
 +
<pre><nowiki>
 +
service rsync
 +
{
 +
    disable = no
 +
    socket_type = stream
 +
    wait = no
 +
    user = root
 +
    server = /usr/bin/rsync
 +
    server_args = --daemon
 +
    log_on_failure += USERID
 +
}
 +
</nowiki></pre>
 +
3. Create the file <code><nowiki>/etc/rsyncd.conf</nowiki></code> configuration for rsync in daemon mode. The file should contain the following. In the file, '''user''' should be replaced with the name of user on the remote machine being logged into.
  
rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync。它的特性如下:<br>可以镜像保存整个目录树和文件系统。<br>可以很容易做到保持原来文件的权限、时间、软硬链接等等。<br>无须特殊权限即可安装。<br>优化的流程,文件传输效率高。<br>可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。<br>支持匿名传输,以方便进行网站镜象。<br>软件下载<br>rysnc的主页地址为:<br>http://rsync.samba.org/
+
<pre><nowiki>
 +
max connections = 2
 +
log file = /var/log/rsync.log
 +
timeout = 300
  
<br>
+
[share]
 +
comment = Public Share
 +
path = /home/share
 +
read only = no
 +
list = yes
 +
uid = nobody
 +
gid = nogroup
 +
auth users = user
 +
secrets file = /etc/rsyncd.secrets
 +
</nowiki></pre>
 +
4. Create ''/etc/rsyncd.secrets'' for user's password. User should be the same as above, with password the one used to log into the remote machine as the indicated user.
  
== 安装  ==
+
<pre><nowiki>
 +
$ sudo vim /etc/rsyncd.secrets
 +
user:password
 +
</nowiki></pre>
 +
5. This step sets the file permissions for rsyncd.secrets.
  
在UBUNTU下安装RSYNC通过以下步骤可以实现:
+
<pre><nowiki>
<pre>$ sudo apt-get install rsync xinetd
+
$ sudo chmod 600 /etc/rsyncd.secrets
</pre>
+
</nowiki></pre>
 +
6. Start/Restart xinetd
  
== 配置  ==
 
 
1. 编辑/etc/default/rsync 启动rsync作为使用xinetd的守护进程
 
<pre>$ sudo vim /etc/default/rsync
 
  RSYNC_ENABLE=inetd
 
</pre>
 
2. 创建 /etc/xinetd.d/rsync 通过xinetd使rsync开始工作<br>
 
<pre>$ sudo vim /etc/xinetd.d/rsync
 
  service rsync
 
    {
 
        disable        = no
 
        socket_type    = stream
 
        wait            = no
 
        user            = root
 
        server          = /usr/bin/rsync
 
        server_args    = --daemon
 
        log_on_failure  += USERID
 
    }
 
 
</pre>
 
3. 创建 ''/etc/rsyncd.conf''&nbsp; 配置rsync使其在.
 
<pre>$ sudo vim /etc/rsyncd.conf
 
  max connections = 2
 
  log file = /var/log/rsync.log
 
  timeout = 300
 
 
  [share]
 
  comment = Public Share
 
  path = /home/share
 
  read only = no
 
  list = yes
 
  uid = nobody
 
  gid = nogroup
 
  auth users = user
 
  secrets file = /etc/rsyncd.secrets
 
</pre>
 
4. 创建 ''/etc/rsyncd.secrets''&nbsp; 配置用户名和密码.
 
<pre>$ sudo vim /etc/rsyncd.secrets
 
  user:password
 
</pre>
 
4.a
 
<pre>$ sudo chmod 600 /etc/rsyncd.secrets
 
</pre>
 
5. 启动/重启 xinetd
 
<pre>$ sudo /etc/init.d/xinetd restart
 
</pre>
 
 
== Testing ==
 
Run the following command to check if everything is ok.
 
 
<pre><nowiki>
 
<pre><nowiki>
$ sudo rsync user@192.168.0.1::share
+
$ sudo /etc/init.d/xinetd restart
 +
</nowiki></pre>
 +
=== Testing ===
 +
Run the following command to check if everything is ok. The output listed is just a sample, should be what is on your shared remote machine. Hostname can be replaced by the IP address of the machine.
 +
<pre><nowiki>
 +
$ sudo rsync user@hostname::share
 
   Password:  
 
   Password:  
 
   drwxr-xr-x        4096 2006/12/13 09:41:59 .
 
   drwxr-xr-x        4096 2006/12/13 09:41:59 .
第74行: 第130行:
 
</nowiki></pre>
 
</nowiki></pre>
 
----
 
----
[[category:CategoryDocumentation]]
+
[[category:CategoryBackupRecovery]] [[category:CategoryCommandLine]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月20日 (四) 00:06的最新版本


This article is part of the BackupYourSystem series. More introductory information can be found there.

Introduction

From the man page: Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use. In other words, rsync is a tool for efficiently copying and backing up data from one location (the source) to another (the destination). It is efficient because it only transfers files which are different between the source and destination directories.

Rsync

Rsync is a command line utility. Users attempting to use it should be familiar with the command line (see Using the Terminal). If you prefer a graphical interface, see the Grsync section of this page.

Installation

Rsync is installed in Ubuntu by default. Be sure to check whether the following packages are installed before starting (see Installing a Package): rsync, xinetd, ssh.

Perform a Simple Backup

The simplest method for backing up over a network is to use rsync via SSH (using the -e ssh option). Alternatively, you can use the rsync daemon (see Rsync Daemon which requires much more configuration. Local backup only requires rsync and read/write access to the folders being synchronized. Below you will find examples of commands that can be used to backup in either case. It should be noted, that a network sync can be performed locally so long as the folder is shared (say by Samba) and then mounted to the machine with folder1. This process gets around having to use ssh but is less secure and should only be used in secure private networks, like at your home. Local Backup

sudo rsync -azvv /home/path/folder1/ /home/path/folder2

Backup Over Network

sudo rsync --delete -azvv -e ssh /home/path/folder1/ [email protected]:/home/path/folder2

An explanation of above options to commands:

  • --delete deletes files that don't exist on the system being backed up.(Optional)
  • -a preserves the date and times, and permissions of the files (same as -rlptgoD).

. With this option rsync will: . Descend recursively into all directories (-r), . copy symlinks as symlinks (-l), . preserve file permissions (-p), . preserve modification times (-t), . preserve groups (-g), . preserve file ownership (-o), and . preserve devices as devices (-D).

  • -z compresses the data
  • -vv increases the verbosity of the reporting process
  • -e specifies remote shell to use
  • /folder1 and folder2 In the examples above, folder1 and 2 are placeholders for the directories to be synchronized. Folder1 is the original folder, and 2 is the new folder, or existing one to be brought in sync with the first. Replace them with the folders you'd like. A / was added after folder1 so that only the contents, rather than whole folder, would be moved into the second.

A complete synopsis of all the options with the rsync command can be found in the man pages under "Options Summary". The man page for rsync can also be found on linux.die.net

Grsync

Grsync is a GUI frontend for the rsync utility. The simple interface of the GUI exposes many of the basic options available with rsync. It is useful for those who prefer not to use the command line.

Installation

The program grsync does not come installed by default on Ubuntu or any other distrubtion but it is easily available from the main UbuntuHelp:Repositories. To get grsync ensure Universe section of the Ubuntu repositories is enabled in your Software Sources|Repositories/Ubuntu|Software Sources. Then to install this software in Ubuntu, install the following package: grsync.

Configuration

To start up grsync go through the following menus: Applications --> System Tools --> grsync. Upon start up you'll be presented with the main window, where all the configuration takes place. rsync?action=AttachFile&do=get&target=grsyn1.png On this window are all of the options most users will ever need. To explain, the options will be listed and their effects mentioned.

  • Sessions - This function is the same as profiles in others. Each session will store a different set of source and destination directories, as well as the configuration options associated with the folder pair. This allows for the synchronization of different sets of folders according to different options.
  • Management of sessions is simple, simply push the Add button to add a new one. To delete, select the session you no longer want from the drop down and push Delete.
  • Source and Destination - These two boxes list the two folders (technically referred to as directories) that will be synchronized. The top one is the Source and the bottom the Destination. So when you Execute the synchronization, the files from Source will be copied over to the Destination according to the options a user selects.
  • To specify the directories either Browse for them from the GUI or type them in according to the standard path conventions.
  • Switch - The universal reload sign located to the right of the Browse buttons is a handy button. It will instantly switch the Source with the Destination.
  • Import and Export - After having configured sessions, a user may want to back them up for storage. To do so, simply go to the Sessions Menu at the top and select either Import or Export. The former will restore a session from a backup previously made, the latter will make a backup of the current session.
  • Note: This backup function works on a per session basis. This means, each session you want to back up must be selected from the drop down and then backed up. If you have 3 different sessions, select each in turn and Export them. Same when importing sessions.
  • Basic Options - Most users will find most of the options they will ever need here. The first four will preserve the properties of the files transferred. The others will modify how the files are copied. For more information on what each does specifically, hover your stationary cursor over the option and it will display a small explanation. The options checked are of course the ones that will be applied during the session.

rsync?action=AttachFile&do=get&target=grsyn2.png

  • Advanced Options - This tab holds more options, many are useful and self-explanitory. For those not understood, tooltips will be displayed when the mouse remains over an option long enough.
  • Additional Options - This entry box allows the input of additional options not presented in the GUI but known to the user. Use is suggested only for experienced users, inputting malformed options may have unexpected consequences.

Simulation and Execution

The last two buttons on the window are Simulation and Execute. The button for simulation is very useful when uncertain what will happen based on the options selected. The normal transfer dialog screen will pop up and in the main pane, a list of files that would have been copied over is listed. The user can then verify if this is as desired or make changes. Once the session is initiated with the Execute button, the dialog will appear again but this time it will actually process the folders accordingly. Ensure before pushing Execute that you are happy with the simulation.

Remote Backup

Backup over a network is possible, preferably the user should mount the network share to be backed up to prior to launching the program. The share would then be listed in the Browse GUI and could easily be added. There is no separate section for network, if more advanced features are required the user is encouraged to look at alternatives, of which there are many.

Alternatives

There are many alternatives, in various stages of development. For an incomplete list, see here.

Rsync Daemon

The rsync daemon is an alternative to SSH for remote backups. Although more difficult to configure, it does provide some benefits. For example, using SSH to make a remote backup of an entire system requires that the SSH daemon allow root login, which is considered a security risk. Using the rsync daemon allows for root login via SSH to be disabled.

Configuration of the rsync Daemon

1. Edit the file /etc/default/rsync to start rsync as daemon using xinetd. The entry listed below, should be changed from false to inetd.

RSYNC_ENABLE=inetd

2. Install xinetd because it's not installed by default.

$ sudo apt-get -y install xinetd

2. Create the file /etc/xinetd.d/rsync to launch rsync via xinetd. It should contain the following lines of text.

service rsync
{
    disable = no
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = --daemon
    log_on_failure += USERID
}

3. Create the file /etc/rsyncd.conf configuration for rsync in daemon mode. The file should contain the following. In the file, user should be replaced with the name of user on the remote machine being logged into.

max connections = 2
log file = /var/log/rsync.log
timeout = 300

[share]
comment = Public Share
path = /home/share
read only = no
list = yes
uid = nobody
gid = nogroup
auth users = user
secrets file = /etc/rsyncd.secrets

4. Create /etc/rsyncd.secrets for user's password. User should be the same as above, with password the one used to log into the remote machine as the indicated user.

$ sudo vim /etc/rsyncd.secrets 
user:password

5. This step sets the file permissions for rsyncd.secrets.

$ sudo chmod 600 /etc/rsyncd.secrets

6. Start/Restart xinetd

$ sudo /etc/init.d/xinetd restart

Testing

Run the following command to check if everything is ok. The output listed is just a sample, should be what is on your shared remote machine. Hostname can be replaced by the IP address of the machine.

$ sudo rsync user@hostname::share
  Password: 
  drwxr-xr-x        4096 2006/12/13 09:41:59 .
  drwxr-xr-x        4096 2006/11/23 18:00:03 folders