Skip to content

Instantly share code, notes, and snippets.

@trentster
Last active May 25, 2016 22:46

Revisions

  1. trentster revised this gist Jan 16, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions do-smartmachine-dataset.sh
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,10 @@ sed -e "s/#DNAMABBR/$DNAMABBR/g" > $DNAME.$VERSION.dsmanifest
    #lets delete the snapshot
    zfs destroy zones/$UUID@prepare

    ##optional

    #echo "Installing New Dataset ($DNAME.$VERSION uuid: $GENUUID)..."
    #imgadm install -m $DNAME.$VERSION.dsmanifest -f $GENUUID.$DNAME.$VERSION.zfs.gz

    exit 0

  2. trentster created this gist Jan 16, 2013.
    59 changes: 59 additions & 0 deletions do-smartmachine-dataset.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    #!/bin/bash
    #
    # SCRIPT: do-smartmachine-dataset.sh
    # AUTHOR: Mark Slatem
    # DATE: 16 January 2013
    # REV: 1.0
    #
    # PLATFORM: SmartOS
    # REQUIREMENTS: SmartOS
    #
    # PURPOSE: turn a zone vm into a dataset
    # USAGE: do-smartmachine-dataset.sh UUID TARGET

    UUID="$1"
    GENUUID=`uuid`
    CLOUDNAME="smartos"
    DATE=`date +%FT%H:%M:%S.0Z`

    echo -n "What do you want to call the new dataset: "
    read -e DNAME
    echo -n "Enter a 3 letter abbreviation for the dataset name: "
    read -e DNAMABBR
    echo -n "What is the version number you want to use: "
    read -e VERSION
    echo -n "Enter a short description for the dataset: "
    read -e DESCR
    echo -n "creator name: "
    read -e CREATOR

    #lets do the actual snapshots
    zfs snapshot zones/$UUID@prepare

    echo "Creating zfs archive ($GENUUID.$DNAME.$VERSION.zfs.gz)..."
    #lets do the actual zfs send
    zfs send zones/$UUID@prepare | gzip > $GENUUID.$DNAME.$VERSION.zfs.gz

    SIZE=`ls -l $GENUUID.$DNAME.$VERSION.zfs.gz | awk '{ print $5 }'`
    CHKSUM=`cksum -xsha1 $GENUUID.$DNAME.$VERSION.zfs.gz | awk '{ print $1 }'`

    echo "Creating manifest ($DNAME.$VERSION.dsmanifest)..."
    cat smartmachine.tpl |\
    sed -e "s/#DNAME/$DNAME/g" |\
    sed -e "s/#VERSION/$VERSION/g" |\
    sed -e "s/#DESCR/$DESCR/g" |\
    sed -e "s/#DATE/$DATE/g" |\
    sed -e "s/#GENUUID/$GENUUID/g" |\
    sed -e "s/#CHKSUM/$CHKSUM/g" |\
    sed -e "s/#SIZE/$SIZE/g" |\
    sed -e "s/#CLOUDNAME/$CLOUDNAME/g" |\
    sed -e "s/#CREATOR/$CREATOR/g" |\
    sed -e "s/#DNAMABBR/$DNAMABBR/g" > $DNAME.$VERSION.dsmanifest

    #lets delete the snapshot
    zfs destroy zones/$UUID@prepare


    exit 0


    34 changes: 34 additions & 0 deletions smartmachine.tpl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    {
    "name": "#DNAME",
    "version": "#VERSION",
    "type": "zone-dataset",
    "description": "#DESCR",
    "published_at": "#DATE",
    "os": "smartos",
    "files": [
    {
    "path": "#GENUUID.#DNAME.#VERSION.zfs.gz",
    "sha1": "#CHKSUM",
    "size": #SIZE,
    "url": "#GENUUID.#DNAME.#VERSION.zfs.gz"
    }
    ],
    "requirements": {
    "networks": [
    {
    "name": "net0",
    "description": "public"
    }
    ]
    },
    "uuid": "#GENUUID",
    "creator_uuid": "3952e6b6-b61a-11e1-9a8a-2f58dc6d1291",
    "cloud_name": "#CLOUDNAME",
    "creator_name": "#CREATOR",
    "platform_type": "smartos",
    "urn": "smartos:mts:#DNAMABBR:#VERSION",
    "created_at": "#DATE",
    "updated_at": "#DATE"
    }