Last active
November 28, 2016 16:41
-
-
Save pcgeek86/79cbc230e0478eaf9ad5157867bd1f64 to your computer and use it in GitHub Desktop.
This Bash script is a simple end-to-end example of ClusterHQ Fli + FlockerHub.
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 | |
### Visit http://ui.dev.voluminous.io/user-tokens to get a user token | |
### NOTE: This file should contain a function definition called 'fli' | |
source ~/.bash-fli | |
set -e | |
shopt -s expand_aliases | |
### 1. Create AWS EC2 instance | |
### 2. Create EBS volume (eg. 300 GB) and attach to instance | |
function Prereq { | |
### Install the ZFS Utilities for Linux | |
sudo apt install httpie zfsutils-linux -y | |
echo "Installed ZFS Linux utilities" | |
} | |
Prereq | |
### Set the name of the hardware device that will be used for the ZFS Pool | |
device_name='/dev/xvdf' | |
### The ZFS Pool name can be defined by the user / customer | |
zpool_name='denver' | |
### The VolumeSet name and Volume can be defined by the user | |
volumeset_name='videos' | |
volume_name='ch9trevor' | |
### Set up the FlockerHub URL and Token File | |
flockerhub_url='https://data.flockerhub.clusterhq.com' | |
flockerhub_tokenfile='/root/token-prod.txt' | |
### Configure the FlockerHub URL and the | |
fli config --url ${flockerhub_url} | |
fli config --token ${flockerhub_tokenfile} | |
echo "Set FlockerHub URL to ${flockerhub_url}" | |
echo "Set FlockerHub token to ${flockerhub_tokenfile}" | |
read -p 'Press {ENTER} to proceed with ZFS Pool configuration: ' | |
### Show me the ZFS Pools on the system | |
sudo zpool list | |
### Configure Fli to use a ZFS Pool | |
fli setup --zpool ${zpool_name} --force | |
echo "Configured Fli with ZFS Pool named ${zpool_name}" | |
### Initialize a new VolumeSet | |
volumeset_id=`fli init ${volumeset_name} | tr -d '\r'` | |
echo "Created new VolumeSet on zpool ${zpool_name} named ${volumeset_name}" | |
### Create a new Volume (mount point) in the VolumeSet | |
volume_dir=`fli create ${volumeset_name} ${volume_name} | tr -d '\r'` | |
echo "Created a new Volume named ${volume_name} under VolumeSet ${volumeset_name}" | |
#sudo cd ${volume_dir} | |
echo "Volume mount point is: ${volume_dir}" | |
### Download some data to the Volume | |
file1="${volume_dir}/file1.mp4" | |
echo "Downloading file to: ${file1}" | |
sudo http --output $file1 http://video.ch9.ms/ch9/f9f1/8aff785c-f799-47fd-97c2-0d4f79f9f9f1/PowerShellLinuxDockerNETCoreIntro.mp4 | |
fli snapshot ${volumeset_name}:${volume_name} onefile | |
file2="${volume_dir}/file2.mp4" | |
echo "Downloading file to: ${file2}" | |
sudo http --output $file2 http://video.ch9.ms/ch9/f9f1/8aff785c-f799-47fd-97c2-0d4f79f9f9f1/PowerShellLinuxDockerNETCoreIntro_high.mp4 | |
fli snapshot ${volumeset_name}:${volume_name} twofile | |
file3="${volume_dir}/file3.mp4" | |
echo "Downloading file to: ${file3}$(tput setaf 7)" | |
sudo http --output $file3 http://video.ch9.ms/ch9/ecc5/8403d27e-a01b-4a62-8b73-8e4916f3ecc5/LearnPowerShell5UsingStatement_high.mp4 | |
fli snapshot ${volumeset_name}:${volume_name} threefile | |
file4="${volume_dir}/file4.mp4" | |
echo "$(tput setaf 6)Downloading file to: ${file4}$(tput setaf 7)" | |
sudo http --output ${file4} http://video.ch9.ms/ch9/7778/51420d07-ee0d-46e1-b0ca-d09350ac7778/MicrosoftAzurePowerShellExtensions20160508_high.mp4 | |
fli snapshot ${volumeset_name}:${volume_name} fourfile | |
### List out snapshots for the VolumeSet | |
fli show --snapshot ${volumeset_id}: | |
echo | |
read -p 'Continue? (y/n): ' continue | |
if [ $continue == 'n' ] | |
then | |
exit 0 | |
fi | |
### Sync metadata for VolumeSet with FlockerHub | |
echo "$(tput setaf 6)Syncing metadata for VolumeSet ${volumeset_id}$(tput setaf 7)" | |
fli sync ${volumeset_id} | |
### Push the VolumeSet to FlockerHub | |
echo "$(tput setaf 6)Pushing VolumeSet to FlockerHub with ID ${volumeset_id}$(tput setaf 7)" | |
fli push ${volumeset_id} | |
### Remove the VolumeSet from the local system | |
echo "$(tput setaf 6)Removing VolumeSet from the local system: ${volumeset_id}$(tput setaf 7)" | |
fli remove ${volumeset_id} | |
### Sync VolumeSet Metadata from FlockerHub | |
echo "$(tput setaf 6)Syncing metadata from FlockerHub for VolumeSet ${volumeset_id}$(tput setaf 7)" | |
fli sync ${volumeset_id} | |
### Download the entire VolumeSet onto the local system | |
echo "$(tput setaf 6)Downloading (pulling) VolumeSet with ID: ${volumeset_id}$(tput setaf 7)" | |
fli pull ${volumeset_id} | |
### Clone one of the snapshots into a new Volume | |
fli show --snapshot ${volumeset_id}: | |
echo "Now we will clone a snapshot into a new volume." | |
read -p 'Please enter a snapshot ID or name: ' snapshot_id | |
echo "$(tput setaf 6)Cloning snapshot ${snapshot_id} into a new volume$(tput setaf 7)" | |
cloned_volume=`fli clone ${volumeset_id}:${snapshot_id}` | |
echo "The snapshot (${snapshot_id}) was successfully cloned into ${cloned_volume}" | |
echo "Test script has completed successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment