Backup or Copy Windows Server 2008 Configuration

No Comments

In Windows Server 2008 there is a backup tool called Windows Server Backup which however creates huge backup files. I prefer to use a simple command/batch file that copies everything I want to backup, zips it and then uploads it to Amazon S3 (aka “the cloud”)

I have not been able to find a simple way to copy all of my Windows Server 2008 settings. Theses are the bits and pieces I have found:

Copy IIS7 Configuration

To save IIS 7 (Internet Information Services) configuration, copy the config directory %SYSTEMROOT%\System32\inetsrv\config, example:

xcopy %SYSTEMROOT%\System32\inetsrv\config c:\backup\iisconfig\ /S/E

Windows Advanced Firewall Export Configuration

To export all the current configurations of your firewall to a file:

netsh advfirewall export c:\backup\advfirewall.wfw

Source: David Davis

Export Windows Registry

To export the Registry, use regedit.exe command line options. Note that export is done in background so you need to allow some time before you are able to access the exported file.

regedit /e c:\backup\regbackup.reg

Source: Speedguide

Network Settings

netsh dump > c:\backup\network-settings-netsh-dump.txt

Source: Chris Sanders

 

Please note that this method cannot and should not to be compared to a full backup method such as Windows Server Backup.

This method will not allow you to do a full recovery. It will mean installing Windows Server and all software from scratch and then recover the data you have backed up. Meaning an unrecoverable hard drive crash would most likely mean more downtime/recovery time.

The reason I like this method is because it takes less space which allows me to use S3 to save my backups. That means I can fully automate it (scheduled batch script and no need to change any media) and it is off-site (meaning if there is a fire where my server is, my backup is still safe). And I prefer the ease of just getting my files from a zip file if I need to check or recover anything. Besides, it’s dirt cheap, I pay Amazon S3 a few dollars for a month worth of daily 1GB backups.

8 Quick Steps: Guide to Microsoft Office 365 Exchange Online Free Trial

No Comments

This guide tells you how to quickly and easily get started with Exchange Online using a 10 user free trial which can easily be converted to a paid subscription later ($6 per user per month, minimum 1 user)

This is how you do it (steps may vary a little bit depending on what country you are from)

  1. Go to Office365.com
  2. Click “Get the trial”. This will give you a fully functional free 10 user trial for 30 days.
    So this means one month free and you can test everything before you start paying. When the trial period is up, it is easy to turn it into a paid subscription. No rebate coupon or voucher code needed.
  3. Select the option for “Professionals and Small businesses”, this is the “P1″ plan. For some countries this may already be preselected.
    (If you are a larger company select the “Midsize businesses and enterprises”, plan “E3″ but note that pricing, features etc is different from what is covered here)
  4. Fill out the information about yourself to create a Microsoft Online Services ID.
    You will have to select an onmicrosoft.com domain name, e.g. mycompany.onmicrosoft.com. Don’t worry, you will be able to add your real domain name (or multiple domain names) later
  5. You should see a page telling you that Exchange Online, Lync Online and Sharepoint Online is being set up and that it will take a few minutes. Wait for them to finish.
  6. Add your own Domain. a) Click Admin in the top navigation. From the Admin page on the left column navigation b) Click Management-Domains, then c) Click Add a Domain. d) Enter your domain name and click the Check Domain button. After domain information is shown e) click Next and you will be taken to a page with instructions how to add a TXT record to your DNS for verifying your domain.
  7. Add users. a) Click Admin in the top navigation. From the Admin page on the left column navigation b) Click Management-Users, then c) Click New + User and follow the instructions.
    If you wish, you can make the admin user that was created when you signed up just an admin account without a paid license. To do this edit the user and uncheck “Microsoft Office 365 Plan P1″ under License.

  8. Add me as your partner – optional. Thanks! a) Click Admin in the top navigation. From the Admin page on the left column navigation b) click Subscriptions-Manage, then c) click your subscription, Microsoft Office 365 Trial (Plan P1). On the far right you will see d) Partner Information, click Add and e) in the box shown enter 1912363 as partner id to use my company XS Tech as partner and click Ok (or if you prefer to use another partner enter their partner id) Thanks.
  9. Done!

Background
Microsofts cloud offering Office 365 (formerly BPOS) includes among other things Exchange Online, Microsofts hosted email offering.
Exchange Online can be accessed from a browser (Outlook Web App), Outlook (Windows), Entourage or Outlook for Mac or any mobile software supporting ActiveSync, e.g. Android, iPhone, iPad, Windows Phone etc.
I find Exchange Online well priced at just below 50 SEK (US$ 6) per month for a 25GB mailbox with Sharepoint, Office Web Apps and Lync also included. It is half the price compared to my current Hosted Exchange provider and with over 10 times the storage. Extra plus for me is also that my Hosted Exchange provider is running Exchange 2007 while Office365 is on Exchange 2010. New with the change from BPOS to Office365 is also that you can now signup for only one single user instead of the previous minimum of three.

Browsers
I recommend using Internet Explorer or Firefox with Office 365, Exchange Online and other Office Web Apps. Chrome (currently in release 14) is working most of the time but not always.

Disclosure: My company is a Microsoft partner.

Compare and Merge Text Files

No Comments

This is more a less a note to myself to remember what the text file comparison tool that I use from time to time is called: WinMerge!

It’s a nice Open Source Windows application where you can easily compare two or more text files to each other and make changes or copy from one file to the other while comparing. For example great when comparing to versions of a php file etc.

Automate update of web.config with Microsoft Powershell

No Comments

I have an ASP.NET web site project that I use for 5-10 web sites. Each has its own directory, setup in IIS and MySQL database, ie they work as independent web sites, only the code base is the same. For updates I have a setup with one Windows command file to copy out any file changes to the web site directories and another command file that updates the database with any database structure changes.

So far I have made any updates to the web.config files manually but today I finally figured out how to automate this too.

The Windows command tool Powershell has been around for a couple of years but I have not used it before. It was installed with Windows Update some time ago so it should be installed on your machine. To use it simply run powershell.exe from a command prompt. To exit, close the window or type exit.
Powershell can among other things run Powershell script files (file extension .ps1)

This script will show you how to add to and edit multiple web.config files (or any xml file)

# Source: http://blog.tjitjing.com

# Array of files to make changes to, add as many as you like
$filesarray = @("c:\temp\web.config","c:\anotherfile.xml") 

# Go thru all files
foreach ($filename in $filesarray)
{
	# Get file + cast as xml
	$xml = [xml](get-content $filename)

	# Backup file before making changes
	$backup = $filename + "-" + (get-date).tostring("yyyy-MM-dd-hh_mm_s")
	$xml.Save($backup)

	$root = $xml.get_DocumentElement();

	# Add a new node
	$node = $xml.createElement("mynewnode")
	$root."system.web".appendChild($node)
	$subnode = $xml.createElement("add")
	$node.AppendChild($subnode)
	$attribute = $xml.CreateAttribute("url")
	$attribute.set_Value("http://blog.tjitjing.com")
	$subnode.SetAttributeNode($attribute )

	# Change existing node
	$root.connectionStrings.add.connectionString = "My new connection string"

	# Save
	$xml.Save($filename)
}

There are two caveats I ran in to when running my script:

1) You need to always give the path of the file, even if it is in your current directory. To run a file from current directory you need to wite ./

C:\Temp>powershell.exe ./test.ps1

Or from within Powershell

PS C:\Temp>./test.ps1

2) Powershells execution policy is by default set to Restricted. To avoid getting a message similar to “File C:\temp\test.ps1 cannot be loaded because the execution of scripts is disabled on this system.”, you need to run the command Set-ExecutionPolicy RemoteSigned from the powershell prompt.

Some useful links that helped me understand this and get it working:
Powershell on Microsoft Technet
Andy Schneider’s Blog about Windows PowerShell
Blog post by Dave Donaldson

Google Plus invite give away

29 Comments

Would you like an invite to Google Plus, Googles new social network, the “Facebook and Twitter killer”?
I have a few invitations, post a comment here with your gmail address (currently it seems only gmail accounts are accepted, you should also have filled out your google profile)

For Swedish speakers this is another option to get a Google+ invitation: gratis

[Edit: As I understand it Google Plus is now open for all gmail accounts. I still have plenty of invites, so comment here if you want one and don't have a gmail email address]

Get root path in ASP.NET without using Tilde ~

No Comments

As you probably know you can use the tilde sign (~) in ASP.NET to get the relative path of the root of your Web Site or Web Application. But unless using the Link Server Control or similar you may need some code to convert it to a correct url or get the absolute path.

Using a Server Control – example using the HyperLink Web Server Control

MyHyperLink.NavigateUrl = "~/Products/XYZ"

Using HttpRuntime.AppDomainAppVirtualPath

strAbsoluteUrl = HttpRuntime.AppDomainAppVirtualPath & "/Products/XYZ"

Using VirtualPathUtility.ToAbsolute

strAbsoluteUrl = VirtualPathUtility.ToAbsolute("~/Products/XYZ")

Thanks to Yousef

ASP.NET 4.0: Extra space above Menu in Chrome and Safari using Menu Control

4 Comments

In Visual Studio 2010 when creating a new ASP.NET Web Site or ASP.NET Web Application you get a shell for ASP.NET 4.0 web site with a menu using the ASP.NET 4.0 Menu Control. However in Google Chrome and Safari browsers the menu will show with some extra space above it. It took plenty of googling to find the answer since google is filled with solutions for Chrome problems in ASP.NET 2.0.
Finally – the solution for .NET Framework 4.0:

Add these lines to the Site.css file (in the Styles folder of your VS 2010 project)

/* Fix for extra space above menu in Chrome and Safari */
img[alt='Skip Navigation Links'] {
    display: none;
}

An alternative is to add SkipLinkText=”" to each menu item (have not tested this)

Thanks to MattyF for the solution

Get URL without QueryString in .NET

No Comments

To get the current Url without the query in VB.NET

Request.Url.AbsoluteUri.Split("?")(0)

Split text in two columns in VB.NET

1 Comment

This is a function code snippet to split a text in to two or more columns in VB.NET.

It is converted from my previous posted: Split text into multiple columns in PHP

Parameters:
InputString – String to be split into columns
Columns – Number of columns
SplitString – String to look for to not split midtext etc

Example of how to use:

        Dim strColumns As String() = SplitIntoColumns(strText, 2, "<h2>")
        strText = "<table><tr><td>" & strColumns(0) & "</td><td>" & strColumns(1) & "</td></tr></table>"

Code snippet:

Function SplitIntoColumns(ByVal InputString As String, ByVal Columns As Integer, ByVal SplitString As String) As String()

        ' Source: http://blog.tjitjing.com
        '
        ' Splits a string into x number of columns and returns result as an array of columns
        '
        ' Parameters:
        ' $InputString String to be split into columns
        ' $Columns     Number of columns
        ' $SplitString String to look for to not split midtext etc
        '
        ' Change history:
        ' 2011-02-04/Max    Version 1
        ' 2011-05-16/Max    Version 1.2
        '

        Dim Output() As String
        ReDim Output(0 To Columns - 1)

        ' Find middle of text
        Dim ColLength As Integer = Len(InputString) / Columns

        ' Split into columns
        Dim ColCount As Integer
        Dim Pos As Integer, LastPos As Integer = 0
        For ColCount = 1 To Columns

           ' Find $SplitString, position to cut
            Pos = -1
            If (LastPos + ColLength) < InputString.Length Then
                Pos = InputString.IndexOf(SplitString, LastPos + ColLength)
            End If
            If Pos = -1 Then Pos = InputString.Length

            ' Cut out column
            Output(ColCount - 1) = Mid(InputString, LastPos + 1, Pos - LastPos)

            LastPos = Pos

        Next ColCount

        Return Output

    End Function

[Edit: Updated function]

Split text into multiple columns in PHP

2 Comments

I made a Swedish shopping directory using affiliate links for a site and wanted to split it into two columns.

I wrote the following php function that can be used to split a string in two or more pieces. One parameter is at what character or string you want to split. For example if you want to split at a space to not break up words, or split at a period to not split up sentences, at certain html tags such as <h1> to keep headlines and text in same column etc.

The function returns a string array with columns.

Example how to use:

	$TextString = "some text to split")
	$Columns = SplitIntoColumns ($TextString, 2, "<h1>");
	echo ($Columns[0]);
	echo ($Columns[1]);

Function

function SplitIntoColumns ($InputString, $Columns, $SplitString) {

	// Source: http://blog.tjitjing.com
	//
	// Splits a string into x number of columns and returns result as an array of columns
	//
	// Parameters:
	// $InputString	String to be split into columns
	// $Columns		Number of columns
	// $SplitString	String to look for to not split midtext etc
	//
	// Change history:
	// 2011-01-25/Max	Version 1
	//

	// Find middle of text
	$ColLength = strlen($InputString)/$Columns;

	// Split into columns
	for($ColCount = 1; $ColCount <= $Columns; $ColCount++) {

		// Find $SplitString, position to cut
		$Pos = strpos($InputString , $SplitString , $LastPos + $ColLength);
		if ($Pos === false) {
			$Pos = strlen($InputString);
		}

		// Cut out column
		$Output[$ColCount - 1] = substr($InputString, $LastPos, $Pos - $LastPos);

		$LastPos = $Pos;

	}

	return $Output;

 }

[Edit: VB.NET version: Split text in two columns in VB.NET]

Older Entries