Skip to content


TortoiseSVN – Moving multiple versioned files

I feel silly I’ve been right clicking and choosing rename… from the TortoiseSVN context menu and manually renaming files to move them into other directories.

But… you can do a right click drag and drop which gives you a context menu with Subversion options. Very time saving.

Details here: http://tortoisesvn.net/mostforgottenfeature.html

Posted in IT Tips.


ESXi 4 VM Backup using unsupported SSH login and ftpput

I got the skeleton of this script from another post.

DISCLAIMER: Use this at your own risk. I am not responsible for any data corruption or loss that may occur if you decide to use this without first making sure it works for you.

After playing around with it for hours I have made some changes:

  • When called without arguments show a list of backup candidates
  • Validate the VMID
  • Make sure all VM files are copied even if a VM is stored on multiple data stores
  • Work around some weird ash bugs I discovered while testing

To use copy this file to /sbin/vmbackup.sh on ESXi box and make it executeable.

You need to change the BACKUPHOST, BACKUPUSER and BACKUPPW values to suit and copy it in scp mode because the ESXi box doesn’t have a sftp server on the SSH console.

 
#!/bin/sh 
VERSION=2.0
if [ -z "$1" ]; then
echo "Usage: $0 vmid"
echo "Your choices are:"
vim-cmd /vmsvc/getallvms | grep -v "Name" | awk -F"[" '{ print $1 }'
exit 1
fi
SERVNAME=$1
# Backup host information 
BACKUPHOST=10.11.12.13
BACKUPUSER=ftpuser
BACKUPPW='ftppassword'
# you must create the backup target
# if vmname is "WinXP Pro Client" then
# make a dir on the remote ftp server under BACKUPDIR with that name
# ftpput will not do it for you
# e.g. mkdir "/media/disk/backup/WinXP Pro Client"
 
BACKUPDIR='/media/disk/backup'
 
# Get vm info 
#VMID=`echo $1  /vmsvc/getallvms | grep -v "^Vmid" | grep "$SERVNAME" | awk '{ print $1 }'` 
 
# Using the passed in VMID check if it's valid and exit if not
VMID=`vim-cmd /vmsvc/getallvms | grep -v "Name" | awk '{ print $1 }' | grep  -E "^$1$"`
 
if [ -z "$VMID" ]; then
	echo Invalid VM ID
	exit 1
fi
 
 
 
VMNAME=`vim-cmd /vmsvc/getallvms | grep -i "^$VMID " | awk -F" {2,}" '{ print $2 }'`
 # awk -F" {2,}" '{ print $2 }'
VMSTAT=`vim-cmd /vmsvc/power.getstate $VMID | grep Powered | awk '{ print $2 }'`
 
# vms can exist on multiple data stores so...
# grab  the entire url line 
# e.g.
# url                  /vmfs/volumes/4c372585-c5be3670-5b7e-001d091edb9f   /vmfs/volumes/4c371e81-0c463360-dfe3-001d091edb9f
VMDATASTORES=`vim-cmd /vmsvc/get.datastores $VMID | grep url`
 
# this is better but untested (doens't capture the url first token)
# comment out the "if [ "$j" != "url" ] ; then" if statement
# line if you use this
#VMDATASTORES=`vim-cmd /vmsvc/get.datastores $VMID | grep url | awk '{$1=""; print $0}'`
 
echo "Datastores for $VMID"
echo $VMDATASTORES
#echo At the end
#exit 1
# vmname can be wildly different from vmdir so find vmdir
VMDIR=`vim-cmd /vmsvc/getallvms |  grep -i "^$VMID " | awk -F"[]/]" '{ print $2 }' | sed 's/^[[:space:]]*\(.*\)[[:space:]]*$/\1/'`
 
# get the power status (is it on or off)
VMSTAT=`vim-cmd /vmsvc/power.getstate $VMID | grep Powered | awk '{ print $2 }'`
if [ "$VMSTAT" = "off" ]; then
	echo "Server $VMNAME with VMID $VMID is already powered off"
else
	echo "Powering off server $VMNAME with ID $j"
	vim-cmd /vmsvc/power.shutdown $VMID
 
	VMSTAT=on
	echo "Checking status (now $VMSTAT)"
	while [ "$VMSTAT" = "on" ]; do
		echo wait for "$VMNAME" to shutdown..
		sleep 10
		VMSTAT=`vim-cmd /vmsvc/power.getstate $VMID | grep Powered | awk '{ print $2 }'`
	done
	# ensure to start vm again when it was running:
	VMSTAT=on
fi
 
# set the field separator to new line because it doesn't like
# spaces in the names
# IFS=$(echo -e '\n')
 
# or you can use
#IFS='
#'
 
# working around ash bug regarding spaces in files
 
 
# echo Ok succesfully changed dir
for j in $VMDATASTORES
do
	# vmlocation is the vmdatastore and vmdir
	if [ "$j" != "url" ] ; then
		VMLOCATE="$j/$VMDIR"
		echo "Location: $VMLOCATE"
		echo change to vmware dir
		cd "$VMLOCATE" || exit 1
 
		for i in ./*; do
			FILE=`echo $i | sed s+\./++`
			echo backup "$VMLOCATE/$FILE" to "$BACKUPDIR/$VMNAME/$FILE" on $BACKUPHOST
			ftpput -u $BACKUPUSER -p $BACKUPPW $BACKUPHOST "$BACKUPDIR/$VMNAME/$FILE" "$FILE"
		done
	fi
done
 
if [ "$VMSTAT" = "on" ]; then
	# vm was on when we started the backup, now start it again 
	vim-cmd /vmsvc/power.on $VMID
fi

Posted in IT Tips.


Gnome 3 has option ninjas hiding in plain site

In Gnome 3 you have to press ALT while clicking the System Settings menu (the menu accessed by clicking your username on the top right of the screen) to get the Shutdown (Poweroff) option.

Posted in IT Tips.


Copy file from ESXi Server to your Windows Computer using PuTTY’s pscp

You need to enable the unsupported SSH server on the ESXi box

Then using the pscp utility that comes with PuTTY add -scp to the command line because the default sftp doesn’t work.

Here is an example of copying a file off the ESXi server from the command line of a Windows 7 box

C:\Users\rupert>pscp -scp root@10.0.2.10:/sbin/vmbackup.sh Desktop/
root@10.0.2.10's password:
vmbackup.sh               | 2 kB |   2.5 kB/s | ETA: 00:00:00 | 100%

Posted in IT Tips.


Before you throw away your workstations shred your disks

I did this with a Ubuntu 9.04 bootable Live CD.

Boot from the CD
Choose to try Ubuntu without installing
Start a command prompt (Applications ==> Terminal)

# get root
sudo su -
 
# find your harddisks
root@ubuntu:~# fdisk -l
 
Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x9eef9eef
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9728    78140128+   7  HPFS/NTFS
 
# over write the hard drive with one pass of zeros
# and tell me about it (-v)
root@ubuntu:~# shred -z -n 0 /dev/sda -v
shred: /dev/sda: pass 1/1 (000000)...
shred: /dev/sda: pass 1/1 (000000)...348MiB/75GiB 0%
shred: /dev/sda: pass 1/1 (000000)...700MiB/75GiB 0%
shred: /dev/sda: pass 1/1 (000000)...1.0GiB/75GiB 1%
shred: /dev/sda: pass 1/1 (000000)...1.3GiB/75GiB 1%
shred: /dev/sda: pass 1/1 (000000)...1.6GiB/75GiB 2%
shred: /dev/sda: pass 1/1 (000000)...2.0GiB/75GiB 2%
shred: /dev/sda: pass 1/1 (000000)...2.3GiB/75GiB 3%
shred: /dev/sda: pass 1/1 (000000)...2.6GiB/75GiB 3%
shred: /dev/sda: pass 1/1 (000000)...2.9GiB/75GiB 4%
shred: /dev/sda: pass 1/1 (000000)...3.3GiB/75GiB 4%

Posted in IT Tips.


SOTD: Software of the Day

I’ve just virtualized a windows XP workstation using VMWare Convertor and thought as a final pre wipe and rebuild excercise I would take a Ghost Image of the physical workstation.

I have a Ghost.iso file with Windows PE and Ghost on it and I was trying to transfer it across to a 8GB USB Drive using UNetBootin and this failed to transfer the ISO across.

But I discovered YUMI (Your Universal Multiboot Installer): http://www.pendrivelinux.com/yumi-multiboot-usb-creator/ worked very well and the really cool thing is you can load multiple ISO’s onto your USB Drive and then boot which ever you want.

I’m thinking that combining a Windows PE + GHOST Utilities Image along with a Ubuntu or Knoppix LIVE CD will give me all the tools I need to image and then wipe the harddrives of old pc’s.

So a vote for YUMI a really, really handy transfer bootable ISO image to USB utility!

Posted in IT Tips.


Using nmap to scan a subnet for a specific open port

Today I booted up a box and it’s DHCP assigend IP Address had moved so I had to find it again using this helpful
Use nmap to scan for ssh servers blog post.

After downloading the command line nmap for Windows from http://nmap.org/download.html.

I ran:

# locate ssh servers
# for a range of hosts on a subnet
nmap -p22 --open -sV 192.168.88.100-200
 
# for the entire subnet
nmap -p22 --open -sV 192.168.88.0/24
 
# locate ssh, web and https servers on the entire subnet
nmap -p22,80,443 --open -sV 192.168.88.0/24

No Problemo.

Posted in IT Tips.


Windows 7 – Setting Proxy Configuration from the command line


Was working from memory today and found that proxycfg.exe doesn’t exist in Windows 7 and it’s been replaced by netsh.

You can do it all from the netsh command line but it’s quite easy to first set it up under your Internet Options and then Import the settings as follows:

Enter your proxy address and port then click the Advanced button to configure the proxy bypass list.

Proxy Address

Set proxy address and port

Under advanced settings add the domains / IP’s to bypass

Image of Internet Explorer Proxy Dialog

Set up bypass-list in Internet Explorer

Then import the settings using netsh

Windows CMD Dialog showing netsh winhttp import proxy command

Using netsh to import proxy settings

netsh winhttp import proxy source=ie
Current WinHTTP proxy settings:
    Proxy Server(s) :  192.168.45.22:3128
    Bypass List     :  192.168.55.*;*.internaldomain.local;<local
netsh winhttp show proxy
Current WinHTTP proxy settings:
    Proxy Server(s) :  192.168.45.22:3128
    Bypass List     :  192.168.55.*;*.internaldomain.local;<local>

Posted in IT Tips.


rsnapshot Backup to External USB Drive Gotcha

I am using rsnapshot to make hourly, daily and weekly snapshots of my home workstation data. This is on Fedora 16.

In /etc/rsnapshot.conf there are two commands that specify the root directory you want to create your backups in and whether or not to create it if it doesn’t exist already

###########################
# SNAPSHOT ROOT DIRECTORY #
###########################
# All snapshots will be stored under this root directory.
#
snapshot_root   /mnt/3TB_USB/rsnapshot/
# If no_create_root is enabled, rsnapshot will not automatically create the
# snapshot_root directory. This is particularly useful if you are backing
# up to removable media, such as a FireWire or USB drive.
#
no_create_root  1

Problem:
The problem I am having is that if the USB drive isn’t mounted rsnapshot exits without doing the backup.

I tried to work around this by adding a script to the cmd_preexec setting thinking that rsnapshot would run cmd_preexec and then check to make sure the snapshot_root existed. But apparently the check for rsnapshot_root happens and rsnapshot exits before cmd_preexec runs. So this approach doesn’t work:

# Specify the path to a script (and any optional arguments) to run right
# before rsnapshot syncs files
#
cmd_preexec   /usr/local/bin/mount_backup_usb.sh

Resolution:
So the answer to my problem is to call the mount_backup_usb.sh from the crontab thusly:

# added by jamesm 5/12/2011
0 */4 * * *         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot hourly
50 23 * * *         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot daily
40 23 * * 6         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot weekly
30 23 1 * *         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot monthly

This is the script that I use to mount the external USB Drive. Note that I am using the by-uuid device entry to provide un-ambiguous access to the USB HDD volume just in case the device path (/dev/sdb, /dev/sdc) changes (which it can depending what you have plugged into the PC).

#!/bin/sh
 
VOLUME=/mnt/3TB_USB
BYUUID=/dev/disk/by-uuid/89406e23-02b9-4846-a9db-38c344fe851f
 
if mount | grep -q $VOLUME ;
then
	echo already mounted
else
	echo not mounted
        # just in case it's already mounted by the user to /media/*
	umount -f $BYUUID > /dev/null 2>&1
	mount $BYUUID $VOLUME
 
fi

Posted in IT Tips.


DIY Websites

Keep getting asked “Where can I build a site on the internet” preferably for free or low cost

OK so here are some links to templated DIY site building websites:
Google Sites
Wix Website Builder
Squarespace

So to get started on the Internets for eCommerce what do you need?

  • Commitment to spend money to get the result you want
  • Domain Name – a few dollars to 40$ for 2 years. e.g. this websites Domain Name is jamesmcdonald.id.au
  • A reliable Domain Name Server to Host the Domain Name – This can be a part of the webhosting package or another provider (dyndns.com) – $20 – $40 per year
  • Depending on the complexity of your site. You need to decide on whether you need a Content Management System (CMS) or just plain old HTML and Templates (e.g. Joomla, WordPress) (Free to 150$ per month)
  • If you have the need of highly customized site and you can’t do graphic design or PHP/HTML/Javascript coding then retaining Web Developer will be needed ($500-$10,000)
  • A Web Server. Somewhere to put the files that make up your website. Depending on how much help you need you can spend as little as $3.95 to $10.00 (justhost.com, dreamhost.com) per month or as much as $150 (full dynamic scaling on a clustered cloud environment with support from real people)
  • For eCommerce a payment gateway provider – e.g. Paypal or Bank eCommerce Gateway (percentage of each transaction to several thousand dollars + merchant fees)
  • Email – either a free email address (hotmail.com, gmail.com) or one the same as your domain e.g. james at james mcdonald dot id dot au )
  • Email Mailbox & Server to send and receive your emails
  • A fax / phone number so people can contact you
  • On going technical resource to perform backups, edits and upgrades
  • Reliable backup and restore capability

Posted in IT Tips.




Page optimized by WP Minify WordPress Plugin