hype-o-thetic?com

my notes

Archive for the ‘FreeNAS’ tag

andyleonard.com – zfs-snapshot.sh

leave a comment

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

Written by gimpe

March 22nd, 2011 at 10:16 pm

Posted in bash,FreeBSD,FreeNAS

Tagged with , , ,

FreeNAS: Services|UPS –> what to use as “Port”

leave a comment

I’m writing a note to myself as I don’t have a UPS yet :)

The Port value can be set to “auto” as metionned here: http://jonathanbrown.me/my-freenas-project-part-5-the-config

Found another rerefence that confirms this:
- For newhidups: “auto” or whatever value as newhidups automagically probe for USB UPS.

SOURCE: http://people.freebsd.org/~thierry/nut_FreeBSD_HowTo.txt

Written by gimpe

October 13th, 2009 at 11:29 am

Posted in FreeNAS

Tagged with

Diskless HTPC using DD-WRT (PXE), Ubuntu/XBMC and FreeNAS (TFTP, NFS)

6 comments

Given that I spent time and money on my FeeNAS node, I want to maximize its usage, so when a friend told me that I can use PXE and NFS to boot a diskless computer from the network, I thought it was the perfect opportunity to try somehing new and activate some more services under FreeNAS!

Read the rest of this entry »

Written by gimpe

September 20th, 2009 at 2:46 pm

Posted in FreeNAS,htpc,hype,linux,network

Tagged with , , ,

FreeNAS Bash script to start a ZFS scrub on each pool (scrub.sh)

7 comments

This script will start a scrub on each ZFS pool (one at a time) and will send an e-mail or display the result when everyting is completed. I wrote this script to launch each scrub one after the other and a summary by e-mail that can tell me how much time it took to each ZFS scrub.

Read the rest of this entry »

Written by gimpe

August 28th, 2009 at 9:48 am

Posted in bash,FreeNAS

Tagged with ,

Useful tools in an “embedded” FreeNAS: wget and bash

one comment

wget

To install wget on a “data” parition:

export PKG_TMPDIR=/mnt/usb-data/temp
pkg_add -r wget -P /mnt/usb-data/pkg

Now we need a script to create the symlinks to the wget binaries in the “pkg” directory:

nano /mnt/usb-data/hooks.sh

Here’s the content:

#!/bin/sh

ln -s /mnt/usb-data/pkg/bin/wget /bin/wget

Now make it run at boot time, go in System —> Advanced —> Command scripts and enter:

/mnt/usb-data/hooks.sh

Select PostInit and that’s it! Everytime you reboot your FreeNAS server the symlinks will be re-created!

bash

For bash, add this in the “hooks.sh” script:

# .bashrc for root
ln -s /mnt/usb-data/bashrc /root/.bashrc

# .bashrc for regular user
ln -s /mnt/usb-data/bashrc /mnt/.bashrc

# automatically load bash for root on login (not clean but works)
echo "bash --init-file /mnt/usb-data/bashrc" >> /root/.cshrc

# automatically load bash for regular user on login (not clean but works)
echo "bash --init-file /mnt/usb-data/bashrc" >> /mnt/.cshrc

Written by gimpe

August 4th, 2009 at 7:38 am

Posted in bash,FreeNAS

Tagged with ,

Vim (Vi IMproved) in an “embedded” FreeNAS

3 comments

You need an embedded install with a data partition. My FreeNAS server runs from a 1GB usb stick and the data partition is mounted as “/mnt/usb-data”. To install Vim on the usb stick:

# using csh
setenv PKG_TMPDIR /mnt/usb-data/temp

# install package
pkg_add -r vim-lite -P /mnt/usb-data/pkg

Now we need a script to create the symlinks to the Vim binaries in the “pkg” directory:

nano /mnt/usb-data/hooks.sh

Here’s the content:

#!/bin/sh

# Vim symlinks to binaries
ln -s /mnt/usb-data/pkg/bin/vim /bin/vi
ln -s /mnt/usb-data/pkg/bin/vim /bin/vim

# .vimrc for root
ln -s /mnt/usb-data/pkg/share/vim/vim72/vimrc_example.vim /root/.vimrc
# .vimrc for regular user
ln -s /mnt/usb-data/pkg/share/vim/vim72/vimrc_example.vim /mnt/.vimrc

# syntax file
mkdir  /usr/local/share/vim/
mkdir  /usr/local/share/vim/syntax/
ln -s /mnt/usb-data/pkg/share/vim/vim72/syntax/syntax.vim /usr/local/share/vim/syntax/syntax.vim

Now make it run at boot time, go in System —> Advanced —> Command scripts and enter:

/mnt/usb-data/hooks.sh

Select PostInit and that’s it! Everytime you reboot your FreeNAS server the symlinks will be re-created!

Written by gimpe

August 3rd, 2009 at 8:38 am

Posted in bash,FreeNAS

Tagged with ,

Performance Optimization WordPress Plugins by W3 EDGE