Rsync (Backup Files)

What is rsync?

Rsync is a program that can be used to backup your files. Much like Apple’s Time Machine, or syncing an iPod, it can be used to sync your data with a remote server, creating redundancy in your data to help keep it safe. By default rsync comes with Mac’s and most Linux distributions; I don’t know about Windows.

I set up a script to rsync all of my documents, pictures, music, etc to dataDyne (my raid). Rsync will check for differences in the local files (on my laptop) and the remote files (on dataDyne), and automatically sync the two computers. Rsync will transfer files over SSH so it is a secure connection; having SSH keys really helps here so it doesn’t keep asking for a password. Only changes I make on my laptop will affect rsync, so the files on dataDyne will match what files are on my laptop (one-way sync), much like the same way an iPod will match changes made to iTunes, not the other way around.

The music is sent to a Public directory on my raid, because it is shared using daap.

The basics of rsync

rsync -avr --delete -e ssh /home/user/personaldata user@server:/backup/

-a — tells rysnc to use recursion, and preserve the hierarchy of the folder you are backing up.
-v — tells rsync to be verbose, or show you every file that it is processing.
-r — tells rsync to use recursion, I think -a makes this redundant, but I leave it in because it can’t hurt.
–delete — tells rsync, if I delete files on my local machine, those files should be deleted on the remote server on the next sync.
-e — tells rsync to use SSH as opposed to RSH.

/home/user/personaldata — this is the local folder that you would like to backup. I left off the trailing slash on the folder so rsync will copy the root folder (personaldata) as opposed to just the contents of the folder.
user@server:/backup/ — this is the remote location will the folder will be backed up to. User is your username, Server is the remote server, and /backup/ is the directory where the backup (personaldata) will be get stored.

Check the rsync man page for more information and more advanced options http://ss64.com/bash/rsync_options.html.

My Personal Script

#!/bin/bash
#
# rsyncmystuff.sh
# by Dave Eddy
# dave@daveeddy.com
# http://www.daveeddy.com
#
# This script is used to backup my home directory to my server
# I use $USER as the user variable because my user is who calls this
# script, and it's the same name that I use to login to dataDyne

# IP of the computer you would like to rsync to
IP="10.0.1.10"

# rsync just the music folder of my iTunes to the public folder on dataDyne
echo rsyncing iTunes music
rsync -avr --delete -e ssh /Users/$USER/Music/iTunes/iTunes\ Music/ $USER@$IP:/mnt/raid/Entertainment/Music/DavesMusic

# rsync my entire home directory minus the iTunes music folder to a private folder
echo;echo;echo rsyncing home folder
rsync -arv --delete -e ssh /Users/$USER $USER@$IP:/mnt/raid/Dave/backup/ --exclude 'Music/iTunes/iTunes Music'

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>