Create a Virtual IP Address in Linux

 

This post will detail how to set ip a virtual IP address and assign an interface to handle the traffic in the Linux OS. This may not work for all Linux distros but it should be accurate for most. 

Run the ifconfig command to see what interfaces are available.

ifconfig

Run the ifconfig command again, however this time create a VIP using the following syntax.

ifconfig INTERFACE IP_ADDRESS netmask NETMASK

Example:

ifconfig eth0:1 192.168.50.53 netmask 255.255.255.0

Substitute INTERFACE = the interface which this VIP will be based on, IP_ADDRESS = the new VIP IP address (note: this must exist) and NETMASK = the netmask of the new VIP.

Update the routing table using arping.

arping -q -U -c 3 -I INTERFACE VIP_IP_ADDRESS

Example:

arping -q -U -c 3 -I eth0 192.168.50.51

Substitute INTERFACE = the interface to bind this VIP to and VIP_IP_ADDRESS = the VIP IP address which was assigned in the above ifconfig statement.

 

Note: changes made will be lost when the machine is rebooted.

Back to top

Backup ESXi 5.0 running virtual machine

ESXi does not provide an option to backup a running virtual machine. This is because the VMDK virtual disk cannot be copied while it is in use. As this is likely to be the boot disk for the virtual machine, stopping disk activity without turning the instance off is impossible. 

The below simple script creates a snapshot of the instance which forces the instance to write all new changes to a new file, instead of writing them to the virtual disk. This frees the disk to be copied. Once the copy has completed, the snapshot is removed writing all changes since the backup started back to the virtual disk. 

This script contains little error checking and requires a few conditions to be met in order to complete successfully.
• No device maps for physical disks must exist in the instance
• ‘Independent’ disks must not exist in the instance
• The parameters of the script must be completed correctly.

Solution

There are 2 lines in the script which must be configured. Open the script using a text editor and change the below variables to match your preferences. 

#Config
BASE_PATH=”PATH_TO_VIRTUAL_MACHINES”
BACKUP_ROOT=”PATH_TO_SAVE_BACKUP”

 

Example

#Config
BASE_PATH="/vmfs/volumes/datastore1/Machines/"
BACKUP_ROOT="/vmfs/volumes/datastore1/Backup/"

Copy script

Copy the script to the below location on your ESXi server. The file name of the script should be ‘VMbackupBash’.

/usr/bin/VMbackupBash

Execute script

To run the script, type 

VMbackupBash [MACHINE_FOLDER_TO_BACKUP]

The machine name must be the name of the folder in ‘BASE_PATH’ which contains the instance to backup.

 

Script

#!/bin/bash
#Backup VMware instance

echo ""
echo "-------------------------------"
echo "-      VM Backup Script       -"
echo "-        James Coyle          -"
echo "-------------------------------"
echo ""

#Config
#root path to where your running instances are stored.
BASE_PATH="/vmfs/volumes/datastore1/Machines/"

#root path to where you would like to save the backup
BACKUP_ROOT="/vmfs/volumes/datastore1/Backup/"

#Do not edit
if [ "$1" ]; then
	MACHINE=$1

else
	#MACHINE=$1
	echo "Enter machine name: "
	read MACHINE

fi

BACKUP_APPEND=$(date +"%Y%m%d-%H%M%S")
MACHINE_PATH="$BASE_PATH$MACHINE/"
BACKUP_PATH="$BACKUP_ROOT$MACHINE$BACKUP_APPEND/"

if [ -d $MACHINE_PATH ] && [ -d $BACKUP_ROOT ]; then

	cd $MACHINE_PATH

	VIMID=`vim-cmd vmsvc/getallvms | egrep -o [0-9]+[ ]+$MACHINE | cut -d" " -f1`

	if [ -z VIMID ]; then
		echo "Could not get VM ID."
		vim-cmd vmsvc/getallvms

		echo ""
		echo "Enter vimid of $MACHINE"
		read VIMID
		echo ""
		echo ""

	fi

	#Get existing files
	FILE_ARRAY=`find $MACHINE_PATH -type f`

	I=0
	for T in $FILE_ARRAY[@]
	do
	#echo "$I[$T]"
	I=$((I+1))
	done

	echo "-        Backup info"
	echo "-------------------------------"
	echo "  Machine path: $MACHINE_PATH"
	echo "  Backup path: $BACKUP_PATH"
	echo "  Using VM ID: $VIMID."
	echo "  Machine name: $MACHINE."
	echo "  Files in Machine folder: $I."
    echo ""

	echo "-      Starting backup"
	echo "-------------------------------"
	mkdir $BACKUP_PATH

	echo "  Creating snapshot..."
	vim-cmd vmsvc/snapshot.create $VIMID tempbackupsnapshot
	echo "  Snapshot complete."
	IFS='
'
	for A in $FILE_ARRAY
	do
		if [[ -n "`echo "$A" | grep '.vmdk|.nvram|.vmx'`" ]] ; then
			FILESIZE=$(stat -c%s "$A")
			echo "  Copying file: $A - Size: $FILESIZE bytes"
			cp "$A" "$BACKUP_PATH" 

		else
			echo "  Skipping file: $A"

		fi

	done

	#Remove snapshot
	echo "  Removing snapshot..."
	vim-cmd vmsvc/snapshot.removeall $VIMID
	echo "  Snapshot removed."

	echo "  Starting compression..."
	tar -czpf "$BACKUP_ROOT/$MACHINE-$BACKUP_APPEND.tgz" "$BACKUP_PATH"
	echo "  Compression complete."

	echo "  Removing backup temp..."
	rm -rf "$BACKUP_PATH"
	echo "  Removed temp files."

	echo ""
	echo "-------------------------------"
	echo "       Backup Complete!"
	echo "-------------------------------"

else
    echo ""
	echo ""
	echo "-------------------------------"
    echo "          Error"
    echo "-------------------------------"
	echo "  Folder $MACHINE_PATH or $BACKUP_ROOT does not exists"
	#exit 1
fi
Back to top

TO_DATE errors with Oracle SQL

When applying TO_DATE to a none date value, Oracle can sometime throw an error as it dislikes the value you are trying to transform. Often, this can be due to poor source data which needs to either be fixed, or worked around. 

The following PLSQL will pick out the the invalid values and output them so that you can investigate further. 

DECLARE
v_rid ROWID;
v_value VARCHAR2(50);
v_test DATE;

CURSOR driver
IS
SELECT ROWID rid
, some_date_column column_to_date
FROM table_to_test;

BEGIN
FOR x_rec IN driver
LOOP
v_value := x_rec.column_to_date;
v_rid := x_rec.rid;

BEGIN
v_test := TO_DATE(x_rec.column_to_date, 'DD-MON-YYYY');

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('ROWID: ' || TO_CHAR(v_rid) || ' failed with value ' || v_value || '.');

END;

END LOOP;

END;
Back to top

OBIEE 11g reset all prompts on dashboard page

By default, there is no button in Oracle BI 11g to reset all dashboard prompts. 

The following code can be added to a dashboard page to reset all prompts on the current dashboard page to their default value. 

1: Add a textbox to the dashboard page where you would like the reset prompts button to be displayed.

2: Enter the below code in the text box:

<input id="gobtn" class="button" type="button" name="gobtn" value="Reset All Prompts" tabindex="0" onclick="return PersonalizationEditor.removeDefaultSelection(false)">

3: Tick the ‘Contains HTML Markup’ checkbox.

A styled button will now be visible and will reset all prompts when clicked.

 

Back to top

Restart Windows through the command line

Sometimes you may want to restart windows without clicking the Start menu. In some cases, such as remote desktop, the option to restart Windows is missing completely from the Start menu. 

You can restart Windows XP/ Windows Server 2003 or newer, using the Windows command line or a shortcut. 

SHUTDOWN -r -t 10

-r: is the argument to request a restart, rather than a complete shutdown. 

-t n: is used to specify a delay, before the restart command will take effect. The default is 60 seconds. ‘n’ represents the time in seconds.

 

To name a few, you can run this command from the Run form, from a CMD, or from a shorcut.

Back to top