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.

Automate update of web.config with Microsoft Powershell

1 Comment

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

ASP.NET 4.0 Chart Control Problems on IIS7

11 Comments

I have been playing around with the ASP.NET 4.0 Chart Controls for a new web site (Bilvärdet.se – used car price statistics)

When deploying it to IIS7 on my Windows Server 2008 I ran in to a few problems:

1) I did not have .NET 4.0 Framework installed on the server

🙂 It turns out .NET 4.0 Framework is an optional update in Windows Update and for some reason that I could not figure out failed to install (error code: 80200053) Solution that worked: Manually installed it. I had to use a tool that was new to me, the Microsoft Web Platform Installer (Web PI). Seems to be a cool tool to download, install and configure all sorts of software (incl WordPress, Dupral, Joomla) on Windows, will check this out in more detail in the future.
Don’t forget to change the Application Pool for your Web Site/Web Application in IIS Manager to use .NET Framework 4.0

2) Next problem, error message: An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

This turned out to be a few lines of code in web.config that seems to be needed on my development machine (Windows7 and Visual Studio 2010) but causes problems on IIS7.

Just removed this section from production web.config on server and it worked:

<httpHandlers>
     <add path="ChartImg.axd" verb="GET,HEAD,POST"
     type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
     System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral,
     PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers> 

Thanks to Michael Narinsky for pointing this out.

3) Image file directory problems

First error message: Invalid temp directory in chart handler configuration c:\TempImageFiles\

Solution: Changed dir in ChartImageHandler app settings in web.config

<appSettings>
     <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;"/>
</appSettings> 

Then this error message: The temp directory in chart handler configuration is not accessible c:\xxx\images\

Followed error message suggestion and added access rights to directory (Properties – Security tab) for user NETWORK SERVICE

[Update: Other error message that can appear:
a) “Access to the path ‘C:\xxx\images\charts\chart.png’ is denied.” – this is the same as above, add rights for NETWORK SERVICE
b) “Could not find a part of the path ‘C:\xxx\images\charts\chart.png’.” – make sure directory exists or create it]

4) Charts not rendering with ASP.NET Routing

I’m using ASP.NET 4.0 Routing but this seems to be something Charts are not working well with. Charts are showing up as broken links. If you are using routing, you need to make sure ChartImg.axd is ignored. Add Ignore (or IgnoreRoute) and – this took me quite some time to figure out – make sure you add these before any MapPageRoute or it will not work!

This is what I added in VB.NET, add one line per level in virtual/route folder structure – first line is for root, second line for one subdirectory level, third line for two subdirectory levels.

routes.Ignore("ChartImg.axd/{*pathInfo}")
routes.Ignore("{controller}/ChartImg.axd/{*pathInfo}")
routes.Ignore("{controller}/{action}/ChartImg.axd/{*pathInfo}")

Thanks to Simon Steele.

BTW – Another nice link about ASP.NET Chart Control

Install cURL PHP Extension on Windows IIS

1 Comment

I tried to run a new PHP script that someone else wrote for me on my Windows Server 2008 and got some errors relating to cURL such as this:

Fatal error: Call to undefined function curl_multi_init()

First I spent a lot of time trying to find information on how to install cURL on a Windows IIS installation, downloaded the cURL package, moved around files, copied to c:\windows\system32, updated php.ini and did all sorts of things described in forums, blogs and manuals but could not get it to work.

Finally I decided to upgrade my PHP from 5.3.1 to the latest 5.3.2 release. I downloaded the PHP Windows MSI installer and there in the Setup Wizard you can simply select what extensions you want to install. Selected cURL and it worked like a charm 🙂 I guess it was just to easy…

(I post about this not only to let everyone know how stupid I am but since I could not find this info anywhere it could be good to document it)

I also tried running the installer again in “Change” mode to add and remove Extensions and the installer seems to be doing a pretty good job at adding and removing files + updating php.ini the way you would expect it to.

At one point I tried installing all Extensions but that got me in to trouble giving me a “oci.dll not found” trying to load an Oracle dll. My tip here is to install only the extensions you need or at least not any related to databases you do not use.

After clicking “Next” when you have selected what Extensions to install, the setup wizard may tell you files are locked and you have to restart the server after installing. A way to avoid this can be to (before clicking “Next”) stop the World Wide Web Publishing Service (from command line: NET STOP W3SVC). Just remember to start it again after!

Extensions available from install package in 5.3.2
bzip2
Curl
Enchant
EXIF
Fileinfo
GD2
Gettext
GMP
IMAP
Internationalization (intl)
LDAP
Multi-Byte String
MySQL
MySQLi
OpenSSL
Oracle (10)
Oracle (11g)
PDO
PostgreSQL
Shared Memory
SNMP
SOAP
Sockets
SQLite
SQLite 3
Tidy
XML-RPC
XSL

WordPress on Windows/IIS cannot upgrade, add plugins, upload themes

10 Comments

I have been struggling with this one ever since I moved my WordPress installation from my old Windows 2003 server to a new Windows Server 2008 machine. If I try to use “automatic upgrade” to upgrade to the latest WordPress release or upgrade or add a new plugin I get to the “Connection Information” page asking me to fill out ftp host name, user name and password. When I try to upload a new WordPress theme I get 500 Internal Server Error. I have understood that this is a permissions problem in the file system but have failed to be able to solve it.
I have been trying to give various users and groups permissions on the everything from the entire wordpress directory to the wp-content folder.

However what I did not realize until today is that (at least in my Windows installation) the group IIS_IUSRS does not have any group members but I should instead give the user IUSR permissions. Too easy… 🙂
So simply do this: give user IUSR Modify and Write permissions to your WordPress directory.

Finally!

Looking for Credential Tiles hangs Remote Desktop

8 Comments

On my new Acer TravelMate 5530G I run Windows Vista Home Premium. I use Windows Remote Desktop Connection (RDC) to connect to my server which has been working just fine.

But this weekend after setting up a new Windows 2008 server and trying to connect to it, RDC shows a dialog “Looking for Credential Tiles”. The dialog is up for ever and if I click cancel instead of getting a login screen RDC hangs and I have to shut it down from the Task Manager.

The workaround seems to be to enter the correct credentials into Vistas Advanced User Accounts panel (I later changed password on my server and had the same problem all over again)

This solution is thanks to Denz and can be found as a comment to this Terminal Services Team blog post

1. Type control userpasswords2 into the Start menu search box and hit Enter

2.On the resulting User Accounts screen, click on the Advanced tab and then click the Manage Passwords button

3. On the Stored User Names and Passwords window, click Add button

4. On the Log on to: Type the IP of your server or the Server name, and user name and password

5. Denz instructions says to choose “A Windows Logon Credential” but this option is greyed out for me. However “A web site or program credential” works fine too

Denz and others also have Acer TravelMate laptops (but other models than me) so my theory is that this is a problem with the Acer software that comes with their laptops. Maybe the Bio protection software (fingerprint scanner).

[Update: I can confirm that the problem is related to the Acer fingerprint software. After uninstalling Acer Bio Protection ATU the issue is solved. I had Acer Bio Protection ATU version 6.0.00.16 installed which is the latest version available from Acer at this time]