Productivity

Backups! Yep, that thing you’re ought to do regularly. Today’s the day for me to do it. As being not quite content with the available solutions out there I tend to do it all by hand. This involves some tedious repetitions like packing directories. So here’s a little script that might be handy:

#!/bin/sh
#
# Create a packed tarball of a directory or file in the
# current working directory with an optional filename prefix.
#
DATE=`date +%Y%m%d-%H%M%S`
case “$#” in
“1”)
NAME=`echo $1-$DATE | sed “{s/ /_/g;s/\/$//}”`
;;
“2”)
NAME=`echo $2-$1-$DATE | sed “{s/ /_/g;s/\/$//}”`
;;
* )
echo “Usage: pack FILE [PREFIX]”
echo “Create a packed tarball of FILE with an optional filename PREFIX.”
exit 1
;;
esac
tar -cf “$NAME.tar” “$1” && bzip2 “$NAME.tar”

Just paste that into for example /usr/local/bin/pack and set the executable bit. Afterwards, if you want to pack a directory test you can do a simple pack test or provide a prefix to the resulting file with a more complex pack test $HOST-$USER which results in something like festor-saschpe-test- 20091120-122101.tar.bz2 on my machine. And don’t forget to listen to classy music like this while backing up your stuff:

That’s it, have a nice weekend.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s