Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 100 lines (76 sloc) 2.14 KB
#! /bin/sh
# usage: $0 backup_name ssh_lvm_dump -z volume_path
# check args
BACKUP_NAME="$1"
shift
if [ "$#" -eq "0" ] ; then
echo "Usage: $0 backup_name backup_cmd cmd_args..." >&2
exit 1
fi
BACKUP_CMD="\"$1\""
FILE_EXT=
shift
while [ "$#" -ne "0" ] ; do
# nasty way to detect gzip usage
if [ "$1" = "-z" -o "$1" = "--gzip" ] ; then
FILE_EXT=.gz
elif [ "$1" = "--lzop" ] ; then
FILE_EXT=.lzop
fi
BACKUP_CMD="$BACKUP_CMD \"$1\""
shift
done
# get backup version
NEXT_VER=1
if [ -e "$BACKUP_NAME.ver" ] ; then
LAST_VER=`cat "$BACKUP_NAME.ver"`
EXIT_CODE=$?
if [ "$EXIT_CODE" -ne "0" ] ; then
exit $EXIT_CODE
fi
NEXT_VER=`expr $LAST_VER + 1`
EXIT_CODE=$?
if [ "$EXIT_CODE" -ne "0" ] ; then
exit $EXIT_CODE
fi
fi
BACKUP_FILE="$BACKUP_NAME.$NEXT_VER$FILE_EXT"
# backup
if [ "$NEXT_VER" -ne "1" ] ; then
BACKUP_CMD="$BACKUP_CMD 5< \"$BACKUP_NAME.$LAST_VER.md5\""
fi
BACKUP_CMD="$BACKUP_CMD 6> \"$BACKUP_NAME.$NEXT_VER.md5\" > \"$BACKUP_FILE\""
if [ "$VERBOSE" ] ; then
echo "running: $BACKUP_CMD" >&2
fi
echo $BACKUP_CMD | sh
EXIT_CODE=$?
if [ "$EXIT_CODE" -ne "0" ] ; then
rm -f "$BACKUP_FILE" "$BACKUP_NAME.$NEXT_VER.md5"
exit $EXIT_CODE
fi
# increment version
echo $NEXT_VER > "$BACKUP_NAME.ver"
EXIT_CODE=$?
if [ "$EXIT_CODE" -ne "0" ] ; then
exit $EXIT_CODE
fi
echo "backup completed successfully" >&2
exit 0
=head1 NAME
blockdiff_backup - a wrapper script for taking multi-generational backups
=head1 SYNOPSIS
take a lvm snapshot-based backup
% blockdiff_backup backup_name ssh_lvm_dump root@host /dev/pv/lv
backup a remote file
% blockdiff_backup backup_name ssh_blockdiff_dump root@host file
=head1 DESCRIPTION
Blockdiff_backup is a wrapper script, for taking multi-generational, incremental backups using L<ssh_lvm_dump> or L<ssh_blockdiff_dump>.
=head1 SEE ALSO
L<App::Blockdiff> - for general information
=head1 AUTHOR
Copyright (C) 2009 Cybozu Labs, Inc., written by Kazuho Oku
=head1 LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
=cut