Scheduled PostgreSQL Database Backups

By , June 11, 2009 8:37 pm

I’ve just started using PostgreSQL as my database of choice for a few projects, and needed some way of scheduling backups. As a result I’ve created the following small bash script that will backup a given database and put it in a gzipped tar archive.

You can find the script in my svn repository here.

Usage is pretty simple:

backup_pgsql dbname

where dbname is the name of the database you want to backup.

By default, the script tries to put your backup in /tmp/ – you can change this behaviour by modifying the BACKUP_DIR variable in the script – make sure to include the trailing / though.

Now, of course this is only the backup part. To schedule this, you can edit your crontab file (usually found in /etc/crontab) and include a line like this:

1  3  * * *     root    backup_pgsql dbname

This will backup the database, dbname, at 03.01am every day. Assuming your backup_pgsql is in your PATH. I put mine in /usr/local/bin/ and chmod +x it. If you don’t want to do that, simply provide the full path to the script.

Show SVN revision number in PHP

By , May 15, 2009 12:16 pm

I recently had a need to display the current svn revision of a php based website on the home page. This is particularly useful when working on a website as part of group and you have a central dev server than runs a copy of the latest code. It allows you to quickly and easily see which revision is being run on that server.

Anyway, on to the doing part.

There are a number of different ways to achieve this, some more complicated and tedious then others.

The simplest method I found was to parse the .svn/entries file. This, of course, relies on the fact that the code you run is based on a checkout of the repo, rather than an export. This probably isn’t a good idea in a production environment, unless you setup your sever to prevent access to the .svn folder.

The code looks like this:

$svn = File('.svn/entries');
$svnrev = $svn[3];

You can now print the contents of $svnrev wherever you want and you should get the revision number dispalyed.

Note that the 3 indicates the 4th line in the file. If you get unexpected results, check the .svn/entries file and adjust the index on $svn[] as required.

The other methods of doing this are discussed here

Excel – Update formulas on Open

By , April 29, 2009 10:16 am

Most of the time this is a relatively trivial exercise. In the majority of cases, simply setting ‘Workbook Calculation’ to ‘Automatic’ in the Excel options will give the desired effect.

However, I recently stumbled across a situation where this doesn’t work. If you find yourself entering data into an Excel workbook through some other means – in my case, using the OpenXML libraries in C# – then you may need to force excel to update any formulas you had.

The solution is simple, using a small VB macro. To get it to happen when the workbook is opened, use the following code:

Private Sub Workbook_Open()
 
 Application.CalculateFullRebuild
 
End Sub

If you put that in the code for the main workbook (as opposed to one of the sheets) then it should happen when the spraedsheet is opened.

Getting Postgresql 8.3.x on Gentoo

By , April 12, 2009 8:47 am

I recently had some fun and games upgrading PostgresSQL on my Gentoo box – I was running 8.2.7 and needed 8.3.x for it’s support of ENUM types.

After some googling I found this blog which explained how to do it. There were a few extra steps for me, however, so I though I’d repost my findings here.

Continue reading 'Getting Postgresql 8.3.x on Gentoo'»

High Quality h264 MP4 Videos with ffmpeg

By , March 3, 2009 5:12 pm
I’ve recently been doing some research in the area of producing High Quality MP4 files with the h264 codec. Of course, my program of choice for encoding to this format was ffmpeg with the libx264 codec. I just wanted to share some of my findings, in particular a few example commands for creating these videos.

Continue reading 'High Quality h264 MP4 Videos with ffmpeg'»

Transact-SQL – Auto Increment Primary Key

By , January 12, 2009 3:06 pm

If like me you learnt SQL using MySQL, and then gone into a job and found yourself using Microsoft’s SQL Server, you’ll probably be as irritated as me to find that Transact-SQL does not feature the ‘AUTO INCREMENT’ keyword that MySQL provides. Fortunately, the solution is far easier here than it is in PostgreSQL.

All you need is to add IDENTITY(1,1) in your column definition. I’m not going to pretend to understand exactly what this does, only that it will Automatically increment and ID field for you. If anyone wants to enlighten me on exactly what it does, then feel free :)

An Example is below:

   1: CREATE TABLE dbo.myTable(
   2:     ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
   3:     ColumnA VARCHAR(200),
   4:     ColumnB BIT
   5: )
   6:  

Windows 7 – A Pleasant Surprise

By , January 11, 2009 8:23 pm

After a few delays by Microsoft, I finally got a hold of Windows 7 Beta this morning. I must say…I’m pleasantly surprised. It certainly does seem much much better than Vista was – even at the Beta stage!

Continue reading 'Windows 7 – A Pleasant Surprise'»

Page Refresh Animations in ASP.NET

By , December 19, 2008 11:33 am

Page Refresh Animations

This refers to the way in which we can display some form of feedback to the user that the page is being updated, without the need for an ugly page flash or the page seemingly doing nothing.

 As always there are several ways to achieve this – a quick google will probably reveal several. Below is probably the most reliable method for our usages.

Continue reading 'Page Refresh Animations in ASP.NET'»

Updates and new features…

By , November 28, 2008 9:56 pm

Right. So i finally decided it’d be a good idea to update my wordpress installation – V2.2 was a little out of date! I must say though, V2.6.x is suprisingly different – but in a good way. The admin panel is so much nicer to use. Looks and feels better too – full of all that Javascript goodness we come to expect from websites these days.

Continue reading 'Updates and new features…'»

Visual Studio 2008 Settings

By , November 12, 2008 6:57 pm

Right, I recently discovered some nice looking colour themes for Visual Studio 2008.

So, i’ve decided to share. I can’t be bothered to put a screen shot up, so if you want to see it you’ll just have to try it. Basically, it’s a dark colour scheme. Dark blue background, and brightly coloured text (but not so much so that it blinds you!). Anyway, point is i like to use it and i’m sharing.

VS2008 Colour Scheme VS2008 Colours and Editor Settings

There are two files – one of them contains my Text Editor settings as well as the Colour Scheme settings. The other is just the colour scheme. Enjoy.

Panorama Theme by Themocracy