Difference between revisions of "Rsync"

From ArchWiki
Jump to: navigation, search
m (As a backup utility)
Line 1: Line 1:
 
[[Category:Utilities (English)]]
 
[[Category:Utilities (English)]]
 +
[[Category:System recovery (English)]]
 
[[Category:HOWTOs (English)]]
 
[[Category:HOWTOs (English)]]
''[http://samba.anu.edu.au/rsync/ rsync] is an open source utility that provides fast incremental file transfer.''
+
[http://samba.anu.edu.au/rsync/ rsync] is an open source utility that provides fast incremental file transfer.
  
 
==Installation==
 
==Installation==
 
+
Install the {{package Official|rsync}} package using [[pacman]]:
 
  # pacman -S rsync
 
  # pacman -S rsync
  
 
==Usage==
 
==Usage==
 +
For more examples, search the [http://bbs.archlinux.org/viewforum.php?id=27 Community Contributions] and [http://bbs.archlinux.org/viewforum.php?id=33 General Programming] forums.
  
 
===As a cp alternative===
 
===As a cp alternative===
 
+
rsync can readily be used as an advanced cp alternative, specially useful for copying larger files:
rsync can readily be used as an advanced cp alternative, specifically useful for copying larger files:
+
 
+
 
  $ rsync -P src dest
 
  $ rsync -P src dest
  
Line 18: Line 18:
  
 
===As a backup utility===
 
===As a backup utility===
 +
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media. For a more thorough example, see [[Full system backup with rsync]].
  
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically to some removable media.
+
====Automated backup====
 +
For the sake of this example, the script is created in the {{Filename|/etc/cron.daily}} directory, and will be run on a daily basis if a [[cron]] [[daemon]] is installed and properly configured. Configuring/using cron is outside the scope of this article.
  
 
First, create a script containing the appropriate command options:
 
First, create a script containing the appropriate command options:
 
{{Note|For the sake of this example, the script is created in the {{Filename|/etc/cron.daily}} directory, and will be run once daily if a cron daemon is installed and properly configured. Configuring/using cron is outside the scope of this article.}}
 
 
 
{{File|name=/etc/cron.daily/backup|content=
 
{{File|name=/etc/cron.daily/backup|content=
 
#!/bin/bash
 
#!/bin/bash
 
rsync -a --delete /folder/to/backup /location/to/backup &> /dev/null}}
 
rsync -a --delete /folder/to/backup /location/to/backup &> /dev/null}}
  
; {{Codeline|-a}} : means files are archived
+
; {{Codeline|-a}} : indicates that files should be archived, meaning that all of their attributes are preserved
; {{Codeline|--delete}} : means files deleted on the source are deleted on the backup
+
; {{Codeline|--delete}} : means files deleted on the source are to be deleted on the backup aswell
  
 
Here, {{Filename|/folder/to/backup}} should to be changed to what needs to be backed-up ({{Filename|/home}}, for example) and {{Filename|/location/to/backup}} is where the backup should be saved ({{Filename|/media/disk}}, for example).
 
Here, {{Filename|/folder/to/backup}} should to be changed to what needs to be backed-up ({{Filename|/home}}, for example) and {{Filename|/location/to/backup}} is where the backup should be saved ({{Filename|/media/disk}}, for example).
  
 +
====Automated backup with SSH====
 
If backing-up to a remote host using [[SSH]], use this script instead:
 
If backing-up to a remote host using [[SSH]], use this script instead:
 
 
{{File|name=/etc/cron.daily/backup|content=
 
{{File|name=/etc/cron.daily/backup|content=
 
#!/bin/bash
 
#!/bin/bash
Line 44: Line 43:
  
 
Finally, the script must be executable:
 
Finally, the script must be executable:
 
 
  # chmod +x /etc/cron.daily/rsync.backup
 
  # chmod +x /etc/cron.daily/rsync.backup
 
For more examples, search Google for 'rsync backup script' or search the [http://bbs.archlinux.org/viewforum.php?id=27 Community Contributions] and [http://bbs.archlinux.org/viewforum.php?id=33 General Programming Forum] forums.
 

Revision as of 02:23, 12 December 2009

rsync is an open source utility that provides fast incremental file transfer.

Installation

Install the Template:Package Official package using pacman:

# pacman -S rsync

Usage

For more examples, search the Community Contributions and General Programming forums.

As a cp alternative

rsync can readily be used as an advanced cp alternative, specially useful for copying larger files:

$ rsync -P src dest

The Template:Codeline option is the same as Template:Codeline, which keeps partially transferred files and shows a progress bar during transfer.

As a backup utility

The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media. For a more thorough example, see Full system backup with rsync.

Automated backup

For the sake of this example, the script is created in the Template:Filename directory, and will be run on a daily basis if a cron daemon is installed and properly configured. Configuring/using cron is outside the scope of this article.

First, create a script containing the appropriate command options: Template:File

Template:Codeline 
indicates that files should be archived, meaning that all of their attributes are preserved
Template:Codeline 
means files deleted on the source are to be deleted on the backup aswell

Here, Template:Filename should to be changed to what needs to be backed-up (Template:Filename, for example) and Template:Filename is where the backup should be saved (Template:Filename, for example).

Automated backup with SSH

If backing-up to a remote host using SSH, use this script instead: Template:File

Template:Codeline 
tells rsync to use SSH
Template:Codeline 
is the user on the host Template:Codeline

Finally, the script must be executable:

# chmod +x /etc/cron.daily/rsync.backup