-
Notifications
You must be signed in to change notification settings - Fork 3
/
ssh_lvm_dump
executable file
·99 lines (74 loc) · 2.23 KB
/
ssh_lvm_dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/sh
SS_NAME="lvm_dump"
if [ ! "$BLOCKSIZE" ] ; then
export BLOCKSIZE=1048576
fi
# check args
if [ "$1" = "-z" ] ; then
SSH_BLOCKDIFF_ARGS="-z"
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
$LVCREATE_PREFIX ssh $SSH_ARGS "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=$?
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>
=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