Rsync

From ArchWiki
Revision as of 16:43, 11 December 2011 by Strcat (Talk | contribs) (codeline -> ic)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

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 be used as an advanced cp alternative, especially for copying larger files:

$ rsync -P src dest

The -P option is the same as --partial --progress, which keeps partially transferred files and shows a progress bar during transfer.

You may want to use the -r --recursive option to recurse into directories, or the -R option for using relative path names (recreating entire folder hierarchy on the destination folder).

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 and using cron is outside the scope of this article.

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

-a 
indicates that files should be archived, meaning that all of their attributes are preserved
--delete 
means files deleted on the source are to be deleted on the backup aswell

Here, Template:Filename should 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 instance).

Finally, the script must be executable:

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

Automated backup with SSH

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

-e ssh 
tells rsync to use SSH
remoteuser 
is the user on the host remotehost
-a 
groups all these options -rlptgoD (recursive, links, perms, times, group, owner, devices)


Automated backup with NetworkManager

This script starts a backup when you plugin your wire.

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

-a 
group all this options -rlptgoD recursive, links, perms, times, group, owner, devices
--files-from 
read the relative path of /folder/to/backup from this file
--bwlimit 
limit I/O bandwidth; KBytes per second

Differential backup on a week

This is a useful option of rsync, creating a full backup and a differential backup for each day of a week.

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

--inplace 
implies --partial update destination files in-place

Snapshot backup

The same idea can be used to maintain a tree of snapshots of your files. In other words, a directory with date-ordered copies of the files. The copies are made using hardlinks, which means that only files that did change will occupy space. Generally speaking, this is the idea behind Apple's TimeMachine.

This script implements a simple version of it:

Template:File

To make things really, really simple this script can be run out of /etc/rc.local (this is how i run it myself).