Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, and web development on Ubuntu Linux

    

backing up with rsync

Here is a python script using rsync to backup my Users directory in Vista to an external hard drive.

import os

cmd = "rsync -avz --exclude '/AppData/'" + \
      "/cygdrive/c/Users/saltycrane" + \
      "/cygdrive/f/backup/Users"
os.system(cmd)

Why not to use the backup program that comes with your external hard drive:

Do not, whatever you do, feed your valuable data to a program that is going to save it in a file format that can only be read by that program, or by that kind of computer. Because when the program can’t or the computer can’t, you’re out of options. --Tim Bray, Protecting Your Data

Why to use rsync:

rsync -essh -rtpvz rocks. --Mark Pilgrim, Essentials

On trailing slashes

from the rsync man page:

A trailing slash on the source changes this behavior to avoid creating an addi‐ tional directory level at the destination. You can think of a trailing / on a source as meaning “copy the contents of this directory” as opposed to “copy the directory by name”, but in both cases the attributes of the containing directory are transferred to the containing directory on the destination. In other words, each of the following commands copies the files in the same way, including their setting of the attributes of /dest/foo:

rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo

Use rsync with sudo on the remote host (added 2011-09-07)

Use the --rsync-path option. e.g.

$ rsync -avz --delete --rsync-path="sudo rsync" /tmp/something myhost:/some/path 

1 Comment — feed icon Comments feed for this post


#1 Dmitri commented on 2011-08-29:

Yes, indeed – presence of trailing slash on the destination directory did not change rsync behavior

Post a comment

Required
Required, but not displayed
Optional

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django | Hosted by Slicehost