What is this?

This is basically where I write down stuff that I work with at my job as a GIS Technical Analyst (previously system administrator). I do it because it's practical for documentation purposes (although, I remove stuff that might be a security breach) and I hope it can be of use to someone out there. I frequently search the net for help myself, and this is my way of contributing.

Thursday, March 24, 2011

Keep your log folders tidy with movelogs.exe

Do you sometimes need to keep a log folder tidy? Well, I do. All the time. We have some webservers who create an awful lot of logs, and since I didn't really find a Windows replacement for Linux' logrotate I tried to write a batchfile to get rid of logfiles that were older than a certain number of days. Eventually I gave up and decided it was easier to write it in c#. I suppose powershell would have been even better, but who cares as long as the job gets done?
I suppose I'm not the only sysadmin out there who might need this from time to time, so here it is: movelogs.exe.

It will search a folder for files with a given extension, then apply another extension of your choice to these files providing they are older than a given number of days.

For instance the following command and parameters:

movelogs.exe c:\temp .log .oldlog 30
will search the folder c:\temp for all files ending with .log and attach .oldlog to the filename if the file is older than 30 days.

Personally I call movelogs from a small batchscript who will delete the .oldlog files after movelogs.exe is done. In other situations you might want to move them to a external dump-folder or something else.

Example myservice_deletelogs.bat:
movelogs.exe c:\temp\myservice .log .oldlog 30
del /q c:\temp\myservice\*.oldlog

I have provideed the executable, but if you want to compile it yourself - here's the c# source (should compile without problems in Visual Studio).


using System;
using System.Text;
using System.IO;

namespace movelogs
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 4)
            {
                string strFolder = args[0];
                string strExtension = args[1];
                string strNewExtension = args[2];
                System.DateTime datetimeNow = DateTime.Now;
                try
                {
                    int intFileRenameAge = Int16.Parse(args[3]);
                    string[] strFileList = Directory.GetFiles(@strFolder);
                    foreach (string strFileName in strFileList)
                    {
                        FileInfo fileinfoMyFile = new FileInfo(strFileName);
                        System.DateTime datetimeMyFileDate = fileinfoMyFile.LastWriteTime;
                        TimeSpan timespanFileAge = datetimeNow - datetimeMyFileDate;
                        if (strFileName.EndsWith(strExtension))
                        {
                            int intFileAge = timespanFileAge.Days;
                            if (intFileAge > intFileRenameAge)
                            {
                                Console.WriteLine("{0} is older than {1} days", strFileName, intFileRenameAge);
                                try
                                {
                                    File.Move(strFileName, strFileName + strNewExtension);
                                }
                                catch
                                {
                                    Console.WriteLine("Problem moving {0}. Possible reasons: file in use or permissions.", strFileName);
                                }
                            }
                        }
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    Console.WriteLine("Problem opening folder: {0}", strFolder);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Wrong format for number of days. Try a number");
                }
            }
            else
            {
                Console.WriteLine("movelogs.exe will scan a folder for files with a given extension who are older than a given number of days and then add a new exension them.");
                Console.WriteLine("v1.0
kjetil.pettersson@gmail.com\n");
                Console.WriteLine("Usage: ");
                Console.WriteLine("movelogs.exe [foldername] [extension] [new extension] [age in days]");
                Console.WriteLine("Example:");
                Console.WriteLine("movelogs.exe c:\\temp .log .oldlog 30");
            }
        }
    }
}
 

Friday, March 18, 2011

HP StorageWorks D2D4312 SATA-disks failing

We recently acquired a HP StorageWorks D2D4312 G2. It was running smooth for about 2 months before it started acting strange. We experienced a noticeable decrease in performance and eventually SATA disks started failing. We replaced two drives in about a week but eventually we could not replace them fast enough to rebuild the RAIDs, and lost data. In addition some of the virtual libraries and drives would go offline for no apparent reason. Clearly something was wrong, although the limitied console and GUI made it hard to pinpoint.

We upgraded the software (to 2.1.01) and used the last supported Firmware CD (8.70). No help there. I opened a case with HP and sent a couple of support tickets, and according to them there had been quite a few predicted disk failures going on prior to when the SATA disks actually started failing. So basically they wanted me to download the "D2D G2 Component Firmware" zip-file (version 20110217) and use that to upgrade the Firmware CD (quite an annoying process to be honest, but I'll spare you the details. Let's just say that doing this when you're working remote is more than a little tricky). When looking at the versions it turns out the only difference between the Firmware CD 8.70 and the "D2D G2 Component Firmware" zip-file is the SATA disks firmware version (version HPG1 vs HPG3)

This took care of the problem immediately. Not only did the disks rebuild, and not fail again (at least not yet), but the performance increase was very noticeable (50% in some cases, but some of that might be because we altered the stream concurrency per drive to 1 (down from 3) on our backup jobs in Data Protector). So there you go - it seems like upgrading your SATA-disks to HPG3 is well spent time.