Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Shutdown the VM
- # Cleanup existing files
- STARTING_DIR=$(pwd)
- rm -rf /mnt/test_backup/*
- rm -rf /mnt/test_restore/*
- ssh rb@192.168.1.2 "rm -rf /mnt/remote_backup/*"
- echo "*********************"
- echo "($(date +%s)) Starting"
- echo "*********************"
- #Variables
- VBOXUSER="vboxuser"
- VGROUP="jobVMHost-vg"
- LVOLUME="vm_images"
- SNAPSHOT_MNT="/mnt/snap_$LVOLUME"
- BACKUP_DIR="sftp://rb@192.168.1.2///mnt/remote_backup/jobVMHost_${LVOLUME}"
- RESTORE_DIR="/mnt/test_restore/restored_jobVMHost_vm_images"
- #Create the snapshot
- echo "******************************"
- echo "($(date +%s)) Creating Snapshot"
- echo "******************************"
- lvcreate -L 20G -s -n snap_$LVOLUME /dev/$VGROUP/$LVOLUME
- mkdir $SNAPSHOT_MNT
- echo "******************************"
- echo "($(date +%s)) Mounting Snapshot"
- echo "******************************"
- mount -o ro /dev/$VGROUP/snap_$LVOLUME $SNAPSHOT_MNT
- df -h $SNAPSHOT_MNT
- echo "**************************************"
- echo "($(date +%s)) Creating Initial Checksum"
- echo "**************************************"
- cd $SNAPSHOT_MNT
- hashdeep -rlc md5 * > $STARTING_DIR/checksums.txt
- echo "*****************************************"
- echo "($(date +%s)) Running Duplicity for Backup"
- echo "*****************************************"
- echo "Checking space on remote server:"
- ssh rb@192.168.1.2 "df -h"
- export PASSPHRASE="testphrase"
- duplicity --tempdir /mnt/temp_storage --asynchronous-upload --volsize 256 -v8 $SNAPSHOT_MNT $BACKUP_DIR
- echo "**********************"
- echo "($(date +%s)) Verifying"
- echo "**********************"
- df -h
- duplicity verify --tempdir /mnt/temp_storage --ignore-errors --num-retries 100 -v8 $BACKUP_DIR $SNAPSHOT_MNT
- echo "*************************"
- echo "($(date +%s)) Test Restore"
- echo "*************************"
- echo "Check space:"
- df -h
- duplicity restore --tempdir /mnt/temp_storage --num-retries 100 --ignore-errors -v8 $BACKUP_DIR $RESTORE_DIR
- unset PASSPHRASE
- echo "************************************"
- echo "($(date +%s)) Check Restore Checksums"
- echo "************************************"
- cd $RESTORE_DIR
- hashdeep -ravvl -k $STARTING_DIR/checksums.txt *
- echo "**********************************************"
- echo "($(date +%s)) Check Original Snapshot Checksums"
- echo "**********************************************"
- cd $SNAPSHOT_MNT
- hashdeep -ravvl -k $STARTING_DIR/checksums.txt *
- echo "**************************************************"
- echo "($(date +%s)) Unmount and remove snapshot mnt point"
- echo "**************************************************"
- umount -lfv $SNAPSHOT_MNT
- rm -rf $SNAPSHOT_MNT
- echo "*******************************************"
- echo "($(date +%s)) Remove snapshot logical volume"
- echo "*******************************************"
- lvremove -f /dev/$VGROUP/$LVOLUME
- echo "*************************"
- echo "($(date +%s)) All Complete"
- echo "*************************"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement