andyleonard.com – zfs-snapshot.sh

Here’s a nice script found on thinking sysadmin. I slightly modified it to use the real mount point instead of assuming “/”, my changes are highlighted below:

#!/usr/local/bin/bash

# FROM: http://andyleonard.com/2010/04/07/automatic-zfs-snapshot-rotation-on-freebsd/

# Path to ZFS executable:
ZFS=/sbin/zfs

# Parse arguments:
TARGET=$1
SNAP=$2
COUNT=$3

# Function to display usage:
usage() {
    scriptname=`/usr/bin/basename $0`
    echo "$scriptname: Take and rotate snapshots on a ZFS file system"
    echo
    echo "  Usage:"
    echo "  $scriptname target snap_name count"
    echo
    echo "  target:    ZFS file system to act on"
    echo "  snap_name: Base name for snapshots, to be followed by a '.' and"
    echo "             an integer indicating relative age of the snapshot"
    echo "  count:     Number of snapshots in the snap_name.number format to"
    echo "             keep at one time.  Newest snapshot ends in '.0'."
    echo
    exit
}

# Basic argument checks:
if [ -z $COUNT ] ; then
    usage
fi

if [ ! -z $4 ] ; then
    usage
fi

# Get the TARGET mountpoint
TARGET_MOUNT=$($ZFS get -H -o value mountpoint $TARGET)

# Snapshots are number starting at 0; $max_snap is the highest numbered
# snapshot that will be kept.
max_snap=$(($COUNT -1))

# Clean up oldest snapshot:
if [ -d ${TARGET_MOUNT}/.zfs/snapshot/${SNAP}.${max_snap} ] ; then
    $ZFS destroy -r ${TARGET}@${SNAP}.${max_snap}
fi

# Rename existing snapshots:
dest=$max_snap
while [ $dest -gt 0 ] ; do
    src=$(($dest - 1))
    if [ -d ${TARGET_MOUNT}/.zfs/snapshot/${SNAP}.${src} ] ; then
        $ZFS rename -r ${TARGET}@${SNAP}.${src} ${TARGET}@${SNAP}.${dest}
    fi
    dest=$(($dest - 1))
done

# Create new snapshot:
$ZFS snapshot -r ${TARGET}@${SNAP}.0

Thanks Andy!

Fork me on GitHub

Steam: Install a single game on a different hard drive

I have a small ssd (c:\) so I installed my Steam client on my hdd (d:\). But there is a game I wanted to be on my ssd (c:\), here are the steps to do it:

  1. Close Steam
  2. Move the game to the new location
    e.g.: from “d:\Steam\steamapps\common\fallout new vegas” to “c:\Program Files (x86)\Steam\steamapps\common\fallout new vegas”
  3. Open a command prompt
    go in –> “Start Menu” –> “Run..” –> type “cmd”
  4. Create a Windows symlink
    type: mklink /J “d:\Steam\steamapps\common\fallout new vegas” “c:\Program Files (x86)\Steam\steamapps\common\fallout new vegas”
    output: Junction created for d:\Steam\steamapps\common\fallout new vegas <==> c:\Program Files (x86)\Steam\steamapps\common\fallout new vegas

Now start your Steam client and the game will run from its new location.

NOTE: Dead Money DLC didn’t install while using a symlink, I had to move the game back in its original location to download and install the DLC.

How to Install Virtualbox 3.1.6 on NexentaStor 3.0.4

Get: VirtualBox-3.1.6-59338-SunOS.tar.gz
Get: VBoz.zip

Unzip and RENAME python-lib-3.1.8.tar.bz2 TO python-lib.tar.bz2

Put everything in the same dir.

VirtualBox-3.1.6-59338-SunOS.tar.gz
solaris-lib.tar.bz2
sunwvbox-1.0-20100217.diff.gz
python-lib.tar.bz2

And now:

# add required packages
aptitude install alien g11n-minimal-uiu8 lib64gcc1 lib64stdc++6 lib64z1 libfontconfig1 libfreetype6 libgcc1 libice6 libpng12-0 libsm6 libstdc++6 libxau6 libxdmcp6 libxmuu1 libxrender1 python python-dev sunwcsl sunwcslr sunwlibm zlib1g

# untar & prepare VirtualBox
tar -xzf VirtualBox-3.1.6-59338-SunOS.tar.gz
alien -d -s -c --reloc_root=/ VirtualBox-3.1.6-SunOS-r59338.pkg

# patch it
gzip -d -c sunwvbox-1.0-20100217.diff.gz | patch -p0

# build it
cd sunwvbox-1.0
./debian/rules binary

# install the .deb package
cd ..
dpkg -i sunwvbox_1.0-1_solaris-i386.deb

That’s it! Many thanks to Ernst Gill!

SOURCES:
http://www.nexenta.org/boards/1/topics/142

VirtualBox useful commands (VBoxManage/VBoxHeadless)

# change VirtualBox disk and machine default location
VBoxManage setproperty hdfolder /volumes/data/vbox
VBoxManage setproperty machinefolder /volumes/data/vbox

# create a VM
VBoxManage createvm --name "U10.4-base" --ostype Ubuntu --register
# add some ram, network card, DVD-ROM
VBoxManage modifyvm "U10.4-base" --memory 128 --acpi on --boot1 dvd --nic1 bridged
# create a HDD
VBoxManage createhd --filename U10.4-base.vdi --size 10000 --register

# attach storage controllers to it
VBoxManage storagectl "U10.4-base" --name "IDE Controller" --add ide
VBoxManage storageattach "U10.4-base" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium none

# remove .iso
VBoxManage closemedium dvd /volumes/data/exchange/mini-ubuntu-10.04-server-i386.iso

# start VM
VBoxHeadless --startvm "U10.4-base"

# stop VM (requires package acpid)
VBoxManage controlvm "U10.4-base" acpipowerbutton

# view VM information
VBoxManage showvminfo "U10.4-base"

How to Install Transmission 2.01 on NexentaStor 3.0.3

Install required packages

aptitude install libssl-dev libcurl4-openssl-dev intltool

Install libevent

wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar -xzf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure
make && make install

Install Transmission

wget http://mirrors.m0k.org/transmission/files/transmission-2.01.tar.bz2
tar -xjf transmission-2.01.tar.bz2
cd transmission-2.01
./configure LIBEVENT_LIBS="-L/usr/local/lib -levent"
make && make install

Continue reading