Greytree

TamWiki

For a mouse who is a packrat

Technology » Rsync Backups
how to effectively do rsync backups excluding and including certain files and directories

Summary:this is what goes at the top of the site

(redirected from Main.RsyncBackups)

<< Prev: Pm Wiki

Up: ^Tools^

The following is taken from a write-up I made at the PmWiki site discussing how to use rsync to effectively back up only the portions of the wiki you are interested in using the --exclude-from tag and an exclude file.

Using rsync

rsync is an extremely useful solution to backing up files to or from a remote location, provided you have ssh access to the remote machine. The rsync man page lists tons of options and examples for doing this well.

A simple example of using rsync to replicate your wiki:

$ rsync -av user@server:path/to/wiki/ local/path/to/backup

This will bring over everything, including the pmwiki software and such, which you probably don't really need in a backup situation.

Inclusions and Exclusions: rsync filtering

Luckily, rsync let's you include and exclude things by using an --exclude-from parameter that you can drop file glob patterns into.

It's a bit arcane, and the man page is less than helpful, but I've come up with a set of filter rules that seem to work for backing up the important content of your wiki.

Create a file called, say, exclusions, and fill it with:

    # Exclude stuff from pmwiki except some
    + /cookbook/
    + /wiki.d/
    - /wiki.d/.flock
    - /wiki.d/.pageindex
    - /wiki.d/.lastmod
    - /wiki.d/*,del-*
    - /wiki.d/*/*,del-*
    + /pub/
    + /local/
    + /uploads/
    - /*
    - **~
    - **,v
    - **.bak
    - **.tgz
    - **.zip
    - **.gz
    - **.Z

This will allow the files matching include patters (prefix "+") and prevent the files matching exclude patterns (prefix "-") from being included in the rsync. Note well that the include patterns need to come before the exclude patterns. Here's what's going on above:

+ /cookbook/include the cookbook directory at the top level of the directory tree (i.e. if cookbook reappears in a subdirectory).
+ /wiki.d/include the wiki.d directory, again at the top level only
- /wiki.d/.flockexclude the .flock file under wiki.d
- /wiki.d/.pageindexexclude the .pageindex
- /wiki.d/.lastmodexclude .lastmod
- /wiki.d/*,del-*exclude deleted pages
- /wiki.d/*/*,del-*exclude deleted pages in a Group direcotry setting
+ /pub/include the pub directory
+ /local/include the local directory
+ /uploads/include the uploads directory
- /*exclude all other directories and files in root.

This last line here is really the key to the whole thing. If you don't have this line, you'll still get most everything in the installation. It basically says "exclude everything else from here".

What follows are more miscelaneous matching patterns for various kinds of files that may appear in the included directories up above.

- **~typical editor backupt file, such as emacs. the double star means match everything.
- **,vRCS vault file
- **.bakanother type of backup file, usually from filters
- **.tgztarballs, generally don't want to include those in your personal arvhive.
- **.zipzip files, similar to tarballs
- **.gzgzipped files, frequently tarballs are ended .tar.gz
- **.Zcompressed files

(Note: you may have good reason not to exclude some of the types of files I've shown above. Feel free to modify the above list; add and subtract entries as needed.)

Once you have your exclude file set up, then run the following command:

$ rsync -av --exclude-from=exclusions user@server:path/to/wiki local/path/to/backup

Testing your download before doing it

Rsync has a nice parameter, --dry-run, which lets you see what it's going to do before you commit to the download. This is great for checking yout inclusions and exclusions to make sure nothing comes over that you don't want.

Further

There are many more options to rsync that can make it the ideal backup solution, including making incremental and full backups, etc.

Important to remember

Just keep in mind the 3 most important things:

  1. BACKUP!
  2. BACKUP!
  3. BACKUP!


Tags: Categories: HowTos

Recent Changes | Printable View | Page History | Edit Page
Page last modified on April 17, 2012, at 08:59 PM by ImportText?