Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Contact Me
  • Welcome

Compress database backups with Powershell

Nicolas Galler | January 18, 2010

Disk space may be cheap but it is still not free! And, while SQL Server 2008 supports online compression of backups, it is only available in the Enterprise edition. So I wrote a simple powershell script (more like a snippet) to compress any backup (.bak and .trn files) older than 2 days.


cd E:\MSSQL\BACKUP\SalesLogix
dir *.trn,*.bak | where { $_.CreationTime.CompareTo([DateTime]::Now.AddDays(-2)) -lt 0 } |% `
{ & 'C:\Program Files\7-Zip\7z.exe' a "$_.zip" $_; rm $_ }

Could replace “.zip” with “.7z” to do a 7-zip compression – it will take a bit less disk space but more cpu. Could also be tweaked a bit to support recursion.

I saved that to E:\MSSQL\Backup\ZipBackups.ps1 and created a schedule task to invoke “powershell E:\MSSQL\Backup\ZipBackups.ps1″. This requires the execution policy to be set on powershell, to allow unsigned local scripts:


set-executionpolicy RemoteSigned

I am still working on getting more familiar with powershell as it can be a nifty tool (and is becoming more and more standard on Windows servers as it is bundled with other packages)

Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

Heap Table are Teh Suck

Nicolas Galler | January 30, 2008

Today, converted 2 heap tables to clustered ones, and halved the database size. Heap tables get so fragmented that they will have a gigantic amount of unused space. Here is a link to a great script to find out which tables are using up your disk space in SQL server – if the “Unused” space is abnormally large, you may have a fragmentation problem, and one of the best thing you can do is get rid of heap tables, by creating a clustered index or a primary key:

ALTER TABLE Customer ADD PRIMARY KEY (SID);

or

CREATE CLUSTERED INDEX IX_TABLE ON TABLE(COLUMN)

There are a few other ways to defragment tables – but they may not work well (or at all) on heap tables.

PS: If the above script is gone, google “Bill Graziano BigTables”.

Comments
No Comments »
Categories
Tricks
Tags
SQL Server
Comments rss Comments rss
Trackback Trackback

The unicode BOM (or, what are these funny characters at the beginning of my file and how did they get there)

Nicolas Galler | January 27, 2008

Alright, this isn’t much, and is pretty old news, but it was pretty aggravating to look for it this week-end so I might as well jot it down for later.

Somehow last week I started getting some “Invalid Character” errors all over the place (or maybe I just started noticing them, I don’t know). Some came up in msbuild scripts, and some in Javascript files. They just looked like 1 or 3 gibberish characters at the very beginning of the file. I kind of dismissed it because the errors went away after I opened the file in vim and re-saved it, but they came back with a vengeance last week-end when I found out that was the ultimate cause for my Django templates messing up. I really found out I had a bona fide Django bug there for a moment, but it was just copying the “BOM” (byte order mark) from my source files.

So what is this BOM anyway? Simply put they are a few bytes inserted at the beginning of a (unicode) file to help the computer determine how to read it.
It doesn’t really make sense for UTF-8 (the most common default encoding) because the order in those is fixed! But for a double-byte encoding like UTF-16 you have to know whether to put the first byte first or last (there is a longer story to this “endianness” as they call it but let’s cut short here). ANYWAY, some programs will still put a BOM in UTF-8 file, consisting of the 3 bytes 0xEF, 0xBB, 0xBF. And some programs will manage to choke on it. OR, it will have some strange effect when you try to do some things to the files like concatenate them or whatever.

Where do they come from? It seems like Notepad (not Notepad2) will insert them automatically depending on your encoding settings.

To get rid of them, use “:set nobomb” in vim and save, or in Notepad2 change the encoding to “UTF-8″ (instead of “UTF-8 with signature”).

Here is the Wikipedia article which explains this in much more detail.

Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

Windows Got Grep!

Nicolas Galler | November 19, 2007

Well, almost.

May be old news to a lot of people, but I found out the FINDSTR utility which is installed standard on Win XP machines (probably Win 2k3 as well) has enough options to be a decent replacement to grep in the common cases. Even makes it easier for some things – for example use /S for a recursive search instead of having to build it with find.

For myself I still prefer using grep/find instead (on cygwin)… but will be useful when working on other boxes.

Comments
1 Comment »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

HTML and JavaScript syntax Highlighting for Vim

Nicolas Galler | May 11, 2007

This works beautifully:

  • Install the javascript.vim from http://www.vim.org/scripts/script.php?script_id=1491
  • As indicated on that page (but you have to look in the version history comments), edit html.vim and comment out the 2 lines:
    • HtmlHiLink javaScript Special
    • HtmlHiLink javaScriptExpression javaScript

Thanks to Yi Zhao!!!

Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

Instructions for SVN+SSH on Windows (short version)

Nicolas Galler | May 10, 2007
  1. Go download putty. Install the big installer.
  2. Install subversion, and install TortoiseSVN.
  3. Use puttygen to generate a key. Make sure you specify a pass phrase! Save the private key on Windows, and paste the OpenSSH stuff into authorized_keys in Linux.
  4. Have pageant run at startup: create a shortcut under the startup menu and have this command in it:"C:\Program Files\PuTTY\pageant.exe" "E:\Documents\SSH\putty_key.ppk"
    (replace with appropriate path, but don’t remove the quotes)
  5. Start PageAnt, or preferably relog into Windows to make sure it starts automatically.
  6. Now right click in a windows explorer windows and start the tortoiseSVN repo-browser. As the address, specify something like this:
    svn+ssh://username@host/home/nether/SVN

UPDATE – this method is so damn slow over the LAN I really can’t recommend it anymore (I am running a local svnserve now). BUT, I think it might be OK over the web – I believe the issue is there is a huge overhead in establishing the connection, and TortoiseSVN does that (spawning a new SSH or something…) every time I open a folder. It feels like VSS, if you know what I mean. Meanwhile over the internet there is a bigger latency to deal with so the overhead of opening the SSH may not be that noticeable.

Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

App List

Nicolas Galler | April 26, 2007

Master list – check here: http://www.hanselman.com/blog/ScottHanselmans2005UltimateDeveloperAndPowerUsersToolList.aspx

Download:

  • Paint.Net
  • TaskSwitchXP
  • Cropper
  • Launchy
  • TestDriven.net
  • Vim
  • slickrun
  • autoruns
  • putty
Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

Opening CHM from network

Nicolas Galler | April 5, 2007

Set this in registry (create the key if it does not already exist):

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
“MaxAllowedZone”=dword:00000004

Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (24)

Post History

  • 2010
    • January (3)
    • March (1)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox