#!/bin/sh
# This script backs up a set of files and directories incrementally,
# storing only the modified files in a folder-per-day basis. Each time
# you run it, the "current" directory in the backup server gets
# refreshed to the newest copy, and the previous version of a modified
# file is stored in a directory corresponding to "today" (20090905,
# for instance)
# storing only the modified files in a folder-per-day basis. Each time
# you run it, the "current" directory in the backup server gets
# refreshed to the newest copy, and the previous version of a modified
# file is stored in a directory corresponding to "today" (20090905,
# for instance)
# Root to be safeguarded
BDIR=/home/...?
# File and directory patterns, to avoid saving all those useless .dat
# files every day. More on this later.
INCLUDES=Backup.incl
# Backup server
BSERVER=your.backup.server
########################################################################
BACKUPDIR=`date +%Y%m%d`
OPTS="--force --ignore-errors --delete-excluded --include-from=$INCLUDES
--delete --backup --backup-dir=~/DESTINATIONCOPYDIR/$BACKUPDIR/ -az"
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# Generate the "backup dir"
[ -d /home/YOURHOMEDIR/emptydir ] || mkdir /home/YOURHOMEDIR/emptydir
rsync --delete -a /home/YOURHOMEDIR/emptydir/ $BSERVER:DESTINATIONCOPYDIR/$BACKUPDIR/
rmdir /home/YOURHOMEDIR/emptydir
# Copy
rsync $OPTS $BDIR $BSERVER:DESTINATIONCOPYDIR/current
# Uncomment the following line if you have Growl in a Mac
# growlnotify -n 'Backup' -m 'Backup finished correctly' -s
The pattern file should look like this. An exclamation mark as a first line. A minus sign avoids certain directory/files, a plus adds a directory (start by adding the directory), then add the pattern of files. If you want to include all subdirectories, you have to explicitly state so.
!
- DontWantPDFsFromThisDirectory/*.pdf
+ Directory
+ DirectoryWithSubfolders
+ DirectoryWithSubfolders/**/
+ Directory/*.tex
You may also like some Mac/Linux related posts:
- Whistle control your computer (Linux&Mac)
- Calendars & emacs
- Screenshot via command-line in Linux
- How to download YouTube .flv videos
- Extremely useful (mostly free) Mac applications
- MP3 to iPod audiobook: personal reminder
- Two weeks, still loving Fluxbox
- Three dee (3-dimensional file system browsers review)
- Acer Aspire One 8.9' + Ubuntu + Fluxbox
- How to get a local proxy



2 Awesome Comments. Add Yours!:
rsync -avz --iconv=UTF8-MAC,UTF8 -e ssh
to ensure that you have mac / linux compatibility over the UTF8 encoding and -e ssh to pipe it over ssh since I do not expose rsync server over the net.
Thanks! I'll try how it works when on my Mac. I didn't think about encodings, as emacs handles these things automatically.
The pipe through ssh is a good point, thank you!
Post a Comment