Although hdup isn't really maintained anymore, a lot of people keep on using it (which is fine of course). Also it's all opensource, so if somebody wants to fix what needs to be fixed this can also be done.

The reason I consider rdup a better tool is that I can rewrite it with rdup. Incidentally the oneliners I'm describing here are a shorthand for the actual algorithm implemented in hdup.

Core of the algorithm

  1. Let rdup generate the files
  2. tar the file into a tarfile
  3. mcrypt the archive - or whatever
  4. scp it somewhere else

This boils down to:

rdup | tar && mcrypt <tar-ball> && scp <tar-ball> user@remotehost:

Note: I know that is not all hdup can do, but its the core of hdup's functionality.

Note2: we only need the filenames from rdup, hence the -F'%n\n' flag.

Note3: all temp. config files are stored in the directory ~/.hdup.

Note4: I'm assuming bash as the shell here, important for the $HOSTNAME variable for instance (I don't have that one in zsh...)

Full Dump, ie monthly

We want to dump /home and /var for starters:

We use the normal way to do this with rdup:

rm -f ~/.hdup/filelist
rdup -F'%n\n' ~/.hdup/filelist /home /var | \
tar -T - --create --no-recursion --gzip --file \
/tmp/$HOSTNAME.$(date +'%Y-%m-%d').monthly.tar.gz

I'm using some shell foo to create the correct archive name.

Incrementals, weekly and daily

Because of how rdup works in contrast to hdup you can create unlimited incremental dump against the filelist used by the previous rdup run, in this case ~/.hdup/filelist. I'm cutting a corner here as I'm only implementing daily-backups. The script is almost identical, 'cept for the naming and keeping the filelist:

rdup -F'%n\n' ~/.hdup/filelist /home /var | \
tar -T - --create --no-recursion --gzip --file \
/tmp/$HOSTNAME.$(date +'%Y-%m-%d').daily.tar.gz

Encryption

Just as with hdup encryption is a second step, first the archive is created then it is encrypted. First create a file with your secret key:

echo "my secret key" > ~/.hdup/key

Then encrypt our archive:

cat /tmp/$HOSTNAME.$(date +'%Y-%m-%d').daily.tar.gz | \
mcrypt -f ~/.hdup/key -F - > \
/tmp/$HOSTNAME.$(date +'%Y-%m-%d').daily.tar.gz.mc
rm -f /tmp/$HOSTNAME.$(date +'%Y-%m-%d').daily.tar.gz

Remote storage

This was the whole point of hdup, putting your encrypted tar-file on somebody else's computer. In hdup I'm using scp, so why not here?

scp /tmp/$HOSTNAME.$(date +'%Y-%m-%d').daily.tar.gz.mc \ 
user@remotehost

Putting it all together

This is an untested shell script fragment, just to convey the idea! It should be trivial to write your own script, based on the above information. (I you do, please let me know).

case $TYPE in
monthly)
    ARCH_NAME=/tmp/$HOSTNAME.$(date +'%Y-%m-%d').monthly.tar.gz
    rm -f ~/.hdup/filelist
    ;;
daily)
    ARCH_NAME=/tmp/$HOSTNAME.$(date +'%Y-%m-%d').daily.tar.gz
    ;;
esac
# $DIRS holds all the dirs to be backed up
rdup -F'%n\n' ~/.hdup/filelist $DIRS | \
tar -T - --create --no-recursion --gzip $ARCH_NAME

if $encryption; then
cat $ARCH_NAME | mcrypt -f ~/.hdup/key -F - > $ARCH_NAME.mc && \
rm -f $ARCH_NAME
ARCH_NAME=$ARCH_NAME.mc
fi

if $remote; then
scp $ARCH_NAME user@remote:/tmp
fi
echo $ARCH_NAME

So with a few lines and rdup I can make hdup, agreed not all feature are there, but this can be easily helped by extending the script.


0 comments

Comments are closed

If you really, really want to comment, please mail miek@miek.nl.

0 comments in moderator queue