Backing Up Only Recent Files

backup-tape-keanu

Gnarly Backup School Series

Getting backups done is important. Sometimes what you have to backup and what you want to backup make quite the contrast. Consider I never want to back up my .mozilla/firefox//cache directory. Let’s cover how to avoid that. Because if you don’t, things get really bunk, little dude.

Before you freak out man, prepare for some regular expressions. More regular than, huh and eh. “Everthing” separated by the gnarly pipe | is a pattern that will be matched by egrep.

IGNORE="$LOGNAME/(\\.mozilla/firefox/aq0d3bz0xy/cache|\\.gvfs|\\.cache|\\.Trash)'
cd $HOME/..
find $HOME -type f \
| egrep -v $IGNORE \
> /tmp/backup_list
tar cf /mnt/backups/backup.tgz --use-compress-program lbzip2 -T /tmp/backup_list

That will backup your whole home directory except anything you slap into IGNORE. If that includes a whole git tree or two, well, you might be waiting for a long time.
Therefore, let’s concentrate on things that just changed since the last backup.

cd $HOME/..
if [ ! -f $HOME/.recent ]; then
   find $HOME -type f \
   | egrep -v $IGNORE \
   > /tmp/backup_list
else
   find $HOME -type f \
   -newer $HOME/.recent \
   | egrep -v $IGNORE \
   > /tmp/backup_list
fi
touch $HOME/.recent
tar cf /mnt/backups/backup.tgz --use-compress-program lbzip2 -T /tmp/backup_list

Now we have a way to backup only recent things. Using all our cores, courtesy of lbzip2.

Also check out...

Jed Reynolds
Jed Reynolds has been known to void warranties and super glue his fingers together. When he is not doing photography or fixing his bike, he can be found being a grey beard programmer analyst for Candela Technologies. Start stalking him at https://about.me/jed_reynolds.