Skip to content

Instantly share code, notes, and snippets.

@shimarin
Created December 16, 2008 05:34
Show Gist options
  • Save shimarin/36291 to your computer and use it in GitHub Desktop.
Save shimarin/36291 to your computer and use it in GitHub Desktop.
#!/bin/sh
#LVMのボリュームをバックアップするスクリプト
TYPE=$1
VG=$2
SNAPSHOT_SIZE=$3
BACKUP_TARGETS=$4
BACKUP_DIR=$5
usage()
{
echo "$0 <xfs|bin> VG SNAPSHOT_SIZE BACKUP_TARGETS BACKUP_DIR"
}
backup_xfs()
{
xfs_copy $SNAPSHOT_NAME $BACKUP_DIR/$lv.xfs~
mv $BACKUP_DIR/$lv.xfs~ $BACKUP_DIR/$lv.xfs
}
backup_bin()
{
dd if=$SNAPSHOT_NAME of=$BACKUP_DIR/$lv.img~ bs=1M
mv $BACKUP_DIR/$lv.img~ $BACKUP_DIR/$lv.img
}
backup_ext()
{
dump -0 -z9 -f $BACKUP_DIR/$lv.ext~ $SNAPSHOT_NAME
mv $BACKUP_DIR/$lv.ext~ $BACKUP_DIR/$lv.ext
}
if [[ $# -lt 5 ]] ; then
usage
exit
fi
for lv in $BACKUP_TARGETS
do
SNAPSHOT_NAME=/dev/$VG/$lv-snap4backup
if [ -b $SNAPSHOT_NAME ]; then
lvremove -f $SNAPSHOT_NAME
fi
lvcreate --snapshot --size=$SNAPSHOT_SIZE --name $lv-snap4backup /dev/$VG/$lv || exit
sleep 3
backup_$TYPE
lvremove -f $SNAPSHOT_NAME
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment