Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 108 lines (80 sloc) 2.46 KB
#! /bin/sh
SS_NAME="lvm_dump"
if [ ! "$BLOCKSIZE" ] ; then
export BLOCKSIZE=1048576
fi
# check args
if [ "$1" = "-z" -o "$1" = "--gzip" -o "$1" = "--lzop" ] ; then
SSH_BLOCKDIFF_ARGS=$1
shift
fi
SSH_ARGS="$1"
LV_PATH="$2"
if [ ! "$LV_PATH" ] ; then
echo "Usage: $0 root@host lv_path [5< prev_digest_file] 6> digest_file > backup_file" >&2
exit 1
fi
# setup variables
SS_PATH="`dirname $LV_PATH`/$SS_NAME"
SSH_BLOCKDIFF_DUMP=`dirname $0`
if [ "$SSH_BLOCKDIFF_DUMP" ] ; then
SSH_BLOCKDIFF_DUMP="$SSH_BLOCKDIFF_DUMP/"
fi
SSH_BLOCKDIFF_DUMP="${SSH_BLOCKDIFF_DUMP}ssh_blockdiff_dump"
if [ "$SSH_BLOCKDIFF_ARGS" ] ; then
SSH_BLOCKDIFF_DUMP="$SSH_BLOCKDIFF_DUMP $SSH_BLOCKDIFF_ARGS"
fi
if [ ! "$SNAPSHOT_SIZE" ] ; then
SNAPSHOT_SIZE="10G"
fi
EXIT_CODE=0
# create snapshot
if [ "$EXIT_CODE" -eq 0 ] ; then
echo "creating snapshot..." >&2
ssh $SSH_ARGS "sync; sync"
$LVCREATE_PREFIX ssh $SSH_ARGS "sync && lvcreate --snapshot -L \"$SNAPSHOT_SIZE\" -n \"$SS_NAME\" \"$LV_PATH\"" >&2
EXIT_CODE=$?
fi
# dump
if [ "$EXIT_CODE" -eq 0 ] ; then
echo "running: $SSH_BLOCKDIFF_DUMP \"$SSH_ARGS\" \"$SS_PATH\"..." >&2
$SSH_BLOCKDIFF_DUMP "$SSH_ARGS" "$SS_PATH"
EXIT_CODE=$?
if [ "$EXIT_CODE" -ne 0 ] ; then
echo " error: $SSH_BLOCKDIFF_DUMP exitted with code:$EXIT_CODE" >&2
fi
fi
# remove snapshot
echo "removing snapshot $SS_PATH..." >&2
ssh $SSH_ARGS "lvremove -f \"$SS_PATH\"" >&2
EXIT_CODE2=$?
if [ "$EXIT_CODE" -eq 0 ] ; then
EXIT_CODE=$EXIT_CODE2
fi
exit $EXIT_CODE
=head1 NAME
ssh_lvm_dump - dumps a logical volume using LVM snapshot
=head1 SYNOPSIS
take full backup
% ssh_lvm_dump user@host /dev/pv/lv 6> backup_md5.1 > backup.1
take inrcemental backups
% ssh_lvm_dump user@host /dev/pv/lv 5< backup_md5.1 6> backup_md5.2 \
> backup.2
% ssh_lvm_dump user@host /dev/pv/lv 5< backup_md5.2 6> backup_md5.3 \
> backup.3
...
=head1 DESCRIPTION
Ssh_lvm_dump is a wrapper script that uses L<ssh_blockdiff_dump> to take backups of LVM logical volumes (using snapshots) of a remote machine.
=head1 OPTIONS
=head2 -z
compress output using L<gzip>
=head2 --lzop
compress output using L<lzop>
=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