Skip to content

Instantly share code, notes, and snippets.

@sandersch
Last active May 18, 2022 16:30
Show Gist options
  • Save sandersch/3e8de3c7b1806273264b to your computer and use it in GitHub Desktop.
Save sandersch/3e8de3c7b1806273264b to your computer and use it in GitHub Desktop.
Back up an lvm partition using Clonezilla
# Mount image desintion to /home/partimag as desired
# No wizards from here. Use the Clonezilla command line
# Abort script on any failures, print out commands for debugging
set -e
set -x
# Partition to clone
[ -n "$VG_NAME" ] || VG_NAME="systemvg"
[ -n "$LV_NAME" ] || LV_NAME="rootlv"
# Determine source/destination paths
[ -n "$DEVICE_PATH" ] || DEVICE_PATH="/dev/$VG_NAME/$LV_NAME"
[ -n "$FS_TYPE" ] || FS_TYPE=`blkid -o value -s TYPE "$DEVICE_PATH" | tr -d '\r\n'`
[ -n "$IMAGE_DIR" ] || IMAGE_DIR="/home/partimag/"
[ -n "$ARCHIVE_NAME" ] || ARCHIVE_NAME="${VG_NAME}-${LV_NAME}.pcl.gz"
# Activate LVM volume group
vgchange -a y "$VG_NAME"
# Check volume file system integrity
fsck.$FS_TYPE "$DEVICE_PATH"
# Clone compressed partition image
partclone.$FS_TYPE -c -s "$DEVICE_PATH" | pigz -c > "${IMAGE_DIR}/${ARCHIVE_NAME}"
# Generate checksums for partition image
cd "$IMAGE_DIR"
for hash in sha1 md5; do
${hash}sum "$ARCHIVE_NAME" > "${ARCHIVE_NAME}.${hash}"
done
@sandersch
Copy link
Author

# Use wizard to enable networking, mount image destination to /home/partimag as desired.
wget https://gist.github.com/sandersch/3e8de3c7b1806273264b/raw -O clone_lvm_part.sh
chmod +x clone_lvm_part.sh
# export VG_NAME, LV_NAME, FS_TYPE if desired
./clone_lvm_part.sh

@will-code-for-pizza
Copy link

Hi

# Use wizard to enable networking, mount image destination to /home/partimag as desired.
wget https://gist.github.com/sandersch/3e8de3c7b1806273264b/raw -O clone_lvm_part.sh
chmod +x clone_lvm_part.sh
# export VG_NAME, LV_NAME, FS_TYPE if desired
./clone_lvm_part.sh

Thanks for that.
Could you please give a hint how to restore the backuped LVs safely ?

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment