Last active
October 20, 2016 20:07
-
-
Save deinarson/bf42631cf23e3bd7b1ea910244473ed0 to your computer and use it in GitHub Desktop.
I was asked to investigate snapshots on lvm. I still prefer ZFS over LVM, but if you only have LVM you at least have lvmsync ( Thanks to Matt for his fine work on https://github.com/mpalmer/lvmsync )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this must exit on any error | |
set -e | |
initiate_pull_snapshots(){ | |
ssh ${DEST_HOST} lvcreate --size 10 --snapshot --name ${LOGICAL_VOL}-current ${VOL_NAME}/${LOGICAL_VOL} | |
ssh ${DEST_HOST} dd if=/dev/${VOL_NAME}/${LOGICAL_VOL}-current bs=1M | dd of=/dev/${CLOUD_VOLUME}/${LOGICAL_VOL} bs=1M | |
} | |
# NB: The disk must have ${CHANGE_SIZE} space free to store all of the changes untill the next snapshot | |
# *** If the changes are greater than ${CHANGE_SIZE}, the snapshot becomes corrupt, thus loosing all changes since. | |
loop_in_cron_pull(){ | |
ssh ${DEST_HOST} lvcreate --size ${CHANGE_SIZE} --snapshot --name ${LOGICAL_VOL}-new ${VOL_NAME}/${LOGICAL_VOL} | |
ssh ${DEST_HOST} lvmsync --stdout /dev/${CLOUD_VOLUME}/${LOGICAL_VOL}-current | lvmsync --apply - /dev/${VOL_NAME}/${LOGICAL_VOL} | |
# THE FOLLOWING MUST NOT RUN UNTILL ${VOL_NAME}/${LOGICAL_VOL}-current has succefully transfered! | |
# | |
ssh ${DEST_HOST} lvremove -f ${VOL_NAME}/${LOGICAL_VOL}-current | |
ssh ${DEST_HOST} lvrename ${VOL_NAME}/${LOGICAL_VOL}-new ${VOL_NAME}/${LOGICAL_VOL}-current | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment