Difference between revisions of "Rsync"

From ArchWiki
Jump to: navigation, search
(marked as stub)
(Simple Rsync Backup Howto)
Line 1: Line 1:
 
{{stub}}
 
{{stub}}
= Simple Rsync Backup Howto =
+
= Introduction =
 +
The rsync protocol can be used to make quick and easy backups, as it only transfers files that have changed, which means backups are much quicker, than if you just copied all your files over every time.
 +
This tutorial aims to show you how to make a scheduled backup, using rsync, typically to a removable media.
  
'''First:'''
+
= Prerequisites =
Open a terminal and do:
+
Obviously, to use rsync, you need rsync:
 +
# pacman -S rsync
  
sudo vim /etc/cron.daily/rsync.backup
+
= Configuration =
 +
We need to make a script that tells rsync to backup your data.
  
Paste this code there:
+
Open a text editor, for example:
 +
# nano /etc/cron.daily/rsync.backup
 +
In this location, it will be run daily, without any further configuration.
  
<nowiki>#!/bin/bash</nowiki> <br>
+
You need to paste this script into the text editor:
DATE=`date +%Y%m%d%H%M` <br>
+
rsync -avrzhP --log-file=/var/log/backups/$DATE.log --delete /home/ /home.bck/ &> /dev/null
+
  
 +
#!/bin/bash
 +
rsync -ar --delete /folder_to_backup/ /location_to_backup/ &> /dev/null
  
 +
-a means files are archived, -r means files are copied recursively, and --delete means files deleted on the source are deleted on the backup
  
Make it executable:
+
Here, "folder_to_backup" needs to be changed to what you want to backup (/home/ , for example) and "location_to_backup" is where you want to back it up to (/media/disk , for example).
  
sudo chmod +x /etc/cron.daily/rsync.backup
+
We now need to make it executable:
 +
#chmod +x /etc/cron.daily/rsync.backup
  
and that's it... it'll run every day as a cron job (meaning you have to have cron configured and working)
+
And that's it. It'll now run daily, as long as your cron daemon is configured correctly (which is out of the scope of this document).
 
+
NOTES:
+
Watch really good the commands -avrzhP is the main backup options, --log-file well, is the log file created with the backup date --delete means that files that you delete from the source dir will also be deleted from the backup dir. /home/ (you can change it) is the source /home.bck/ is the destination dir (which i have it on another hard drive but it doesn't matter).  
+
 
+
I would suggest you though to look for other backup methods if this one doesn't suit you... it's very simple as you can see but it works for me.
+
 
+
--[[User:Jfgomez86|Jfgomez86]] 13:28, 28 February 2008 (EST)
+

Revision as of 16:23, 14 June 2008

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Rsync#)

Introduction

The rsync protocol can be used to make quick and easy backups, as it only transfers files that have changed, which means backups are much quicker, than if you just copied all your files over every time. This tutorial aims to show you how to make a scheduled backup, using rsync, typically to a removable media.

Prerequisites

Obviously, to use rsync, you need rsync:

# pacman -S rsync

Configuration

We need to make a script that tells rsync to backup your data.

Open a text editor, for example:

# nano /etc/cron.daily/rsync.backup

In this location, it will be run daily, without any further configuration.

You need to paste this script into the text editor:

#!/bin/bash
rsync -ar --delete /folder_to_backup/ /location_to_backup/ &> /dev/null

-a means files are archived, -r means files are copied recursively, and --delete means files deleted on the source are deleted on the backup

Here, "folder_to_backup" needs to be changed to what you want to backup (/home/ , for example) and "location_to_backup" is where you want to back it up to (/media/disk , for example).

We now need to make it executable:

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

And that's it. It'll now run daily, as long as your cron daemon is configured correctly (which is out of the scope of this document).