Thursday 17 October 2013

Automatic FTP backups of SQL Server Express

Had a bit of a head-scratcher here, OK I know that in full versions of SQL Server backups can be managed (from what I understand) but how do you automate backups of SQL Server Express Versions?

The thing that I wanted (I don't ask for much!) was for cumulative, sequential backup volumes to be created on a daily basis and then pushed out to a remote FTP server which I know is backed up offsite as well (a double backup if you like)

So, what's the principle? Simple really, I run a scheduled task on the Window VPS each night when the database is quiet (normally after 9pm GMT) which is just a .bat file which does the following:

  1. Exports a backup of the named database (via a .sql command file)
  2. Moves it into a tmp directory
  3. Creates a directory for today's date
  4. Moves the temp file into that
  5. Dynamically writes an FTP script
  6. Executes the FTP command
  7. Tidies up the tmp files

Sounds easy enough, but the internal functions had me thinking a little bit. Let's walk through the process of the files needed:

SQL file export of whole database

Create a text file called export.sql and added this command into it

BACKUP DATABASE [nameofdatabase] TO  DISK = N'(pathtothedatabase\nameofdatabase.bak' WITH NOFORMAT, NOINIT,  NAME = N' EasyToRememberBackupName', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

nameofdatabase = yeah, the name of your database
pathtothedatabase = full directory structure where you want the backup to be saved to (e.g. D:\SQLBackups\Name\TMP
The TMP bit you need to create to save the initial .bak file into from the SQL dump
EasyToRememberBackupName = This is nothing more than a convenient name to call the backup and won't be used anywhere else anyway, but will be referenced if you restore a database from this in the future. We'll call it SQLbackup.bak for this exercise

Save that file into a dedicated directory (which will be referred to as VolumeRunningTheScriptFrom in the next stage) and create a new empty text file called backup.bat

Now the really fun bit, we've nicked a bit of internal DOS commands coupled it with SQL commands and chucked in a bit of FTP command line code as well to create this beast:

sqlcmd -S .\SQLSERVERLOCALNAME -i "VolumeRunningTheScriptFrom\export.sql"
set string=%date:~-7,2%%date:~-10,2%%date:~-4,4%
echo %string%
md VolumeRunningTheScriptFrom\%string%
VolumeRunningTheScriptFrom\%string%
cd..
move VolumeRunningTheScriptFrom\tmp\SQLbackup.bak VolumeRunningTheScriptFrom\%string%\SQLbackup.bak
cd VolumeRunningTheScriptFrom\%string%\
move VolumeRunningTheScriptFrom\%string%\SQLbackup.bak VolumeRunningTheScriptFrom\%string%\BACKUP_%string%.bak
cd "VolumeRunningTheScriptFrom"
@echo off
del script.txt
echo open FTPserveraddress>>script.txt
echo user FTPuseraccount>>script.txt
echo FTPpassword>>script.txt
echo cd RemoteDirectory>>script.txt
echo bin>>script.txt
echo put VolumeRunningTheScriptFrom\%string%\BACKUP_%string%.bak>>script.txt
echo bye>>script.txt
echo exit>>script.txt
echo cls>>script.txt

ftp -n -s:"VolumeRunningTheScriptFrom\script.txt"

Now that's a mixed bag of code to walk through, let's do it a line at a time:

sqlcmd -S .\SQLSERVERLOCALNAME -i "VolumeRunningTheScriptFrom\export.sql"
From the command line tell the local SQL engine to open the Local SQL Server (in this case SQLSERVERLOCALNAME they typically run as SQLEXPRESS or SQL2008EXPRESS whatever name you gave it when it was set up) and then the FULL path to the .sql file created earlier to execute.

set string=%date:~-7,2%%date:~-10,2%%date:~-4,4%
echo %string%


OK so using a lovely old DOS date function, we are setting a string to be today's date, so if it was 23/11/2013 then the date string would be

23112013

which will make the sequential nature of the backup a whole lot easier to name for uniqueness


md VolumeRunningTheScriptFrom\%string%
VolumeRunningTheScriptFrom\%string%
cd..


Let's make a directory within your backup folder to the value of the date string (23112013) and check its ok, then skip back up to the root of where we are running the script from

move VolumeRunningTheScriptFrom\TMP\SQLbackup.bak VolumeRunningTheScriptFrom\%string%\SQLbackup.bak

OK, so now we want to move the temporary SQL dump from the TMP folder into the newly created datestamp folder


cd VolumeRunningTheScriptFrom\%string%\
move VolumeRunningTheScriptFrom\%string%\SQLbackup.bak VolumeRunningTheScriptFrom\%string%\BACKUP_%string%.bak


So now we want to rename the backup to be specifically renamed to the datestamp. In my case we were running a number of backups into the offsite directory so we wanted to prefix the file with the database name, in this example BACKUP_

So we've basically moved back into the new backup folder for 23112013 and renamed ("move" in DOS terms) the SQLbackup.bak file to a new filename of BACKUP_23112013.bak

cd "VolumeRunningTheScriptFrom"
@echo off

Move back up the folder to the root

del script.txt

Now the funky FTP script to handle the date-specific file. The issue I had with this was that we wanted to keep FTP transferring files from the system from a scheduled task running each evening, but in the past we used a static FTP text file to call from, this was no use when using date-sequential strings, so we are basically creating the script.txt file on the fly, a cunning way of making sure we reference the correct backup for FTP offsite.

First thing though, delete yesterday's script!!

echo open FTPserveraddress>>script.txt
echo user FTPuseraccount>>script.txt
echo FTPpassword>>script.txt
echo cd RemoteDirectory>>script.txt
echo bin>>script.txt
echo put VolumeRunningTheScriptFrom\%string%\BACKUP_%string%.bak>>script.txt
echo bye>>script.txt
echo exit>>script.txt
echo cls>>script.txt


Now we have written all the values into the script.txt file, all that's left is for us to call the script via the system FTP command, silently...

ftp -n -s:"VolumeRunningTheScriptFrom\script.txt"

So, that's the basics in place for the backup, all that's needed now is to schedule this batch file through the Task Scheduler and we're good to run.

I always just run the batch file at the beginning to check it and there's a nice satisfying DOS window which runs through the 0-100% back up process and the FTP transfer which informs you that the files are being pushed offsite.

Please drop me a note if you want the source files, mark{at}1stclassmedia.co.uk

Friday 28 June 2013

Finding a kitchen designer in Edinburgh

Edinburgh is the centre for many things, festivals for one, museums? Art Galleries aplenty. In fact when it comes to high class design houses, Edinburgh has a huge array to choose from. The same (bear with me here) can be said for Kitchen Designs. OK, you can get an economical kitchen from a large DIY outlet, it'll have factory quality finishes and will require replacing in 12 years or so, but will it be truly original? Enter the real experts, bespoke kitchen designers. Choosing from the number of Kitchen Designers in Edinburgh may seem like a daunting task initially. Opening up a phone book or doing a web search may lead you to the designer, however great designers come by recommendation and referral routes - there simply is nothing quite like a word of mouth recommendation for the best kitchen designer. Once you get an idea who to engage it becomes a whole lot easier to make an educated choice about who to use, particuarly one who will take into account full planning and layout and will stick to your budget.

So how do you find such a good Kitchen Designer, particularly a bespoke kitchen designer in Edinburgh? One of the best ways to find the right person who will provide first class guidance and design services is, ask. Ask everyone, your friends or family who have recently had their kitchens replaced and ask about their experiences. More importantly if you have found a decent looking kitchen designer, go them directly and get some insight into the planning process and get testimonials. Also sit down and have a coffee and a chat - if you believe you can work with the designer, all the better!

Choosing from the sheer volume of kitchen designers you find may actually be quite easy, prepare your list of services you are looking for in your kitchen designer, the type of kitchen design you want, and a budget outline for the work you can afford and present it to them, any designer worth their salt will try their best to make a decision whether you can afford them or if you are looking in the right place. As cost is the primary limitation for a lot of people, decent early on which area of the kitchen you want to focus on, if it's worktops or finishes or just the best quality appliances then be true to yourself, you're investing a lot of money in this, so demand the best.

Preparing your list and then taking the time to ask friends, family and the designer themselves about their experience can make finding a Kitchen Designer in Edinburgh so much easier than you probably expected!

Thursday 20 June 2013

jQuery Window Handler (target="_blank")

I love jQuery. I make no bones about it - it's been a revelation for many developers who want to utilise code blocks as reusable elements and by golly it does speed up development both client-side and server-side!

However there are occasions when the traditional view on using "legacy" HTML is sometimes the only way we can perceive a solution. Take this example - we had a colleague who was at his wits end as he'd spent ages trying to use the good ole image map for a map of Scotland to make a clickable map for guest houses. All very well and easy to do. Problem was that the code used another jQuery handler to overlay a replacement map of the area clicked to make it look pretty which in turn played havoc with the internal target="_blank" directive.

After much swearing he dropped me a note to see if we could help. We took a look at the code and it all seemed fairly ok and we encountered the same problem, wtf was going on here, we couldn't use the traditional means above nor could we see how the href wasn't being looked at by the jQuery function.

After much looking and wondering (god bless Stack Overflow, by far one of the best troubleshooting websites ever) we pulled together a code block which may suit one or two others who have need of it.

Image Map Code:

<map name="mymap" id="map">
<area coords="6, 234, 17, 235, 35, 205, 37, 22, 44, 163, 56, 152, 76, 122, 82, 115, 80, 91, 66, 83, 28, 183, 25, 137, 22, 151, 7, 160, 7, 179, 16, 181" class="newWindow" href="#" rel="http://www.bbc.co.uk" id="12" shape="poly" alt="altname" title="title" />

</map>

We added the class to the area to make it a little easier to pass into the jQuery function

jQuery:

$('.newWindow').click(function(e){
e.preventDefault();
var url = $(this).attr('rel');
window.open(url, "_blank");
return false;
});

So, basically, breaking down the code the following happens:

$('.newWindow').click(function(e){ //render a new function each time the class newWindow is clicked

e.preventDefault(); //stop any links from working (note this could probably be left out, we kept it in for convenience)

var url = $(this).attr('rel'); //create a variable "url" from the rel value on the area

window.open(url, "_blank"); //good ole JS to handle the window event

return false; //stop other shit from happening

So, in summary, the little function allows image maps to open URLs in a new window by making the existing link a # (null) link and placing the URL into the rel tag. Grabbing the rel tag into the url variable we push that into the window.open event and voila the target="_blank" emulator kicks in.

There are probably numerous ways of doing this but I thought this may help some poor troubled soul out!

Scripts pooled from various links including

http://stackoverflow.com/questions/4813879/window-open-target-self-v-window-location-href

http://stackoverflow.com/questions/970388/jquery-disable-a-link

Tuesday 4 June 2013

Getting a Landscaper in Edinburgh

Many homeowners love the idea of landscaping their gardens or surrounding land (depending on size) since it is one way of increasing the value of their property. You may have a beautiful home, but an untidy front garden makes it look boring and less homey. By hiring a professional landscaper, you will be able to achieve a perfect design to make a bold statement about who you are, as well as adding value to your property.

One of the many my someone would choose not to hire a profession landscaper is largely down to cost. This is one of those situations where experience speaks volumes and it really does boil down to "are you prepared to spend many weekends getting dirty" against an initial outlay which can pave the way for long term ease of maintenance.

There are many reasons to hire a professional Landscaping Company in Edinburgh. Here are just a few that you should bear in mind:

Unnecessary Expenditure

It's a fact that some landscaping projects can amount to many hundreds. This usually involves professional fees, labour charge, and materials. However, if you compare the cost of trying to undertake the project yourself; hiring machinery, tools and equipment that will basically be used once, making poor choices of plants (and any other features like ponds or rockeries) and the potential for falling behind on the project as well, you'd be better spending a little bit and getting professional service.

Do you really know where to put that thing?

As mentioned above the "unnecessary costs", there is also potential risk for things to go wrong. If you are not great with the planning of proper landscaping projects, then maybe leave it to the experts. There is a real chance that you can do damage to your home or the existing plants, lawns and other parts of your garden. Landscapers can plan and design a beautiful garden for especially for your home, focussing on a larger picture. A full and open discussion will be part of the process.

So, you're an expert huh?

Don't get me wrong, if you've a limited budget or the necessary know-how then perhaps doing the landscaping yourself may be a solution, especially if it only involves basic planting,pruning or moving furniture about. But if it will involve major paving, patio design or building of walls, it's probably best to let the experts do it. Any decent landscaper will know the correct processes, tools or machinery, materials, and how to manage the schedule to maximsie the landscape design for your property.

Having recently completed a website for John Lessels Ltd, a Midlothian Landscaping Company covering Edinburgh and the Lothians, I thought it might be a nice touch to present my thoughts.

Tuesday 30 April 2013

Railway Sleepers - From Track to Garden

So a client of ours asks what we can do to promote the sale of railway sleepers. Naturally my curiosity is piqued - "As in what you put railway tracks on?" asked a rather niave and puzzled looking me. "Erm yes, as opposed to what other kind?". OK, fair come back I thought but the question still remained unanswered. How the heck and who on earth would buy railway sleepers?

Enter John Lessels Landscaping, my friend Andrew, and probably the rest of christendom, apparently it's not uncommon for treated and untreated railway sleepers to be reused/recycled into chique new garden design. Popping round to my pal Andrew's garden and he points out that his monster lawn is fringed with trimmed down railway sleepers which had been placed upright, like mini- Easter Island men between his patio and his lawn, quite a cool way of clearly demarking the start and end of the patio, but in his case because they dug the patio out a little way and this resulted in an 18" difference in height. It transpired that his landscaper new an Railway Sleepers seller in Edinburgh which turned out to be a couple of hundred poind cheaper that a reinforced dwarf wall which would need to have foundations, supporting brickwork etc to make it hold back even a tiny eighteen inches of lawn (apparently it gets quite mobile when very wet - every day's a school day huh?)

John Lessels, a leading landscaping and garden maintenance company in Midlothian also employ railway sleepers which they use to great effect for making raised beds for people in nursing homes and people with disabilities who can't get down to ground level too well. They thought, if they can't reach the ground, let's bring it up! So with some cheap railway sleepers, they have created a number of raised beds and even a fish pool using railway sleepers as the structural decoration and support for both beds and pond.

So there you have it, my lesson learned, railway sleepers, treated and untreated are particularly good for landscaping and contemporary garden design and layout as they can be shaped and trimmed to not only provide the muscle needed to support any beds or hold back lawns, but also to look really quite nice!

Tuesday 23 April 2013

Getting your website listed on Google

As a business owner, if you afford importance to your website then applying a close eye to marketing on Google is a vital first step. Not only is Google one of the most heavily used websites accessed on the internet, it plays a huge part in your marketing plan. Many articles and tipsters offer specialist insight into how to get Google to feature your website above the rest, but the truth is much more simple than that - if you play by the rules within Google's framework you will be on the correct path

We've offered a few ideas about how to get started in Google.


Create a Google Account - this doesn't need to be a chore, just go to the Google home page and click on the sign in link top right and you can create a new account in there using your existing email address, nothing easier than that (apart from the activation).
First step done!


Tell Google you're out there - this needs to be done in the right procedure. Firstly let Google know you are the site owner so when you sign into Google, click your name top right on Google and then the account link to take you to your Google account dashboard. On the left you should see a "products" link follow this to see what products you have in your personal Google portfolio and if you can't see the icon for the webmaster tools, go here to sign up https://www.google.com/webmasters/tools/ . You should see a red box offering you to add a site, click on this and you will be able to add the full URL (web address) of your website. Now Google will ask you to verify the website is actually yours (really a formal acknowledgement that you have access to the website!) by either uploading a meta tag or, and easier, to upload a confirmation html file. This will be something like google71b4e3e3f40eaab543.html simply transfer this onto your website (or ask your web contact to do this is you don't know how to do this)
Second step done!


Webmaster Dashboard - the next steps, creating a site map
Now you need to tell Google what pages to look for. You may have 5 or 500 web pages knocking around your website, more if you run database-driven catalogues or the like. It's important you let Google know what pages to expect to see and this is guided normally by a sitemap. (Quick history lesson: a sitemap used to be a nicely laid out HTML file which acted as a directory for human visitors - these have largely been superseded by XML versions which provide search engines with a clear map of pages). Unless you know XML, we recommend popping over to the http://www.xml-sitemaps.com/ site and creating your own free one there. Simply enter your full URL into the box and select how often you update the website (or leave it as none). If this is the first time you're uploading a sitemap, then you don't need to worry about modifications or priorities, they will come later on (in another blog update to follow). Let the process run on the XML-sitemaps website (they have a nice progress monitor) and the site will let you download the final XML file. Save it locally and upload it into the root of your website (normally www/httpdocs/public_html folder).
Now pop back to the webmaster tools and click on your website and then on the Optimization link on the left to expand it to see sitemaps etc. on the submenu. Click on the Sitemaps and click the red button top right to add/test a sitemap. You should be presented with a popup which has your website address followed by a small box which you will add the name of your sitemap into. Typically the file is called sitemap.xml and this is what you would enter in there. Click the submit sitemap and your page will reload. Now we wait for Google to process the XML file which can take a few hours, so we can keep ourselves busy with a few more tasks.
Step Three Complete


Fetching as Google.
One thing which has been added quite recently is to request that the Googlebot (the software used by Google to trawl the web for new information) come to your website and that the internal pages are indexed and stored in Google for searching.
To do this, click on the webmaster tools and the Health category. Expand this to see the menu sub-items and you will see Fetch as Google which will permit you a limited number of round trips to your website from Google. Click the red fetch button and the page will tell you that it is pending and the page will refresh itself whilst it queues up the fetch exercise. If it's quite a quiet time of day (tip: do this early morning UK time as the US is sleeping and it works faster then!) you will see the Fetch Status as pending and you may be given an option to fetch URL and linked pages. Click this and this will queue up a complete index of your website.
Step Four Complete.

Please come and see us...
Adding to Google. Back in the early days of webmaster tools it used to be necessary to tell Google to please come see me by visiting http://www.google.co.uk/addurl . Whilst this is largely overtaken by webmaster tools, it's still worth doing as I've experienced better uptake of websites when running through this measure than skipping it. It's simply a case of submitting your URL with some hideous captcha images and you're done.
Step Five Complete


Add Analytics.
This could have been done at any stage, but we tend to put it at this point in the list for no other reason than it's just another part of the process. There are occasions when you may want to tie webmaster tools into analytics for commercial reasons, but for simple steps let's proceed.
Easiest thing it to get your way back to the Google home page > Your Name > Account > Products or browse to www.google.co.uk/analytics/ if it's your first time setting up Google analytics.
You will need to add your website as a new account (follow the steps for single domain set up) and then you will be presented with tracking code which you will need to add within the section of your website. Your website designer can assist with this, you will need to add it onto each and every page you want to track visitor access to, as gaps can appear which make for awkward results.
Step Six Complete

Submit your website to Google Places
Once this is done, you can now finish your set up with a final visit to Google Places at www.google.com/business/placesforbusiness/ and submit your business into the new Google maps for businesses which (depending on how central your business is within a town or city being searched) will eventually (there's a verification step in here, use your mobile phone to activate the listing, you can remove this number later) be listed in Google Places, the place to be found for businesses seeking to use the entire Google toolbox.

And that pretty much sums up the potted process to start getting your site listed in Google. The next steps are getting your website found in Google which is a much tougher battle.

Happy Promoting

Saturday 13 April 2013

Dental Implant Surgery in Edinburgh


Dental implant surgery is often the last stage of most dental hygiene treatments - having to get dental implants would suggest that it's the only option open to remedial work performed by oral surgeons. A lof people are a little daunted by the prospect probably because this type of medical procedure usually involves having to receive some level of sedation. In a a large number of cases, the patient is put into a light sleep which enables the surgeon to work more easily without causing a great deal of distress and discomfort for the patient.

We have seen that most general dental practitioners will refer the patient to an oral surgeon, typically one specialising in dental implants when other treatments such as endodontic treatment and periodontic treatments have been less than successful. This why you would probably want to check out the practice where the surgery would be performed. Whilst all leading surgeries have th necessary experience, you'd really want to know that you are in safe hands.
You should also find out as much of the information as you can about dental implant surgery as a procedure and your surgeon should be both available and amendable to this. You want reassurances about the level of care you will expect to get during the surgery and what to expect during the recovery period following your departure from the clinic.
Whilst Dental Implant Surgery is surgery, it's not classed or considered to be major surgery, this is a planned procedure performed at a state of the art clinic by highly skilled dental professionals

David Offord and his team at Vermilion have all the pedigree, experience and training you would need to ensure that your dental implant surgery would be carried out in both the safest and highest quality surroundings possible. The Vermilion clinic on St Johns Road in Edinburgh is equipped with such high end technology as is demanded by discerning patients and by the leading and respected oral surgery referral partner in Edinburgh and the Lothians.

For more information about Edinburgh-based Dental Implant Surgery Referral Clinic follow the link

Monday 8 April 2013

Edinburgh-based Health & Safety Consultant

We recently started working with an Edinburgh-based Health & Safety Consultant, Colin Watt Associates. Located near Bilston on the outskirts of Edinburgh, they have been working in the construction industry for many a year and have some hair-raising and scarcely believable stories to report on.

Anecdotes aside, Colin says the whilst serious injuries can still occur, the overall rate of mortality and life-affecting injuries has been reduced by some very good advances in technology which make for working at heights (an area of their expertise) something which can be very well managed and overseen.

There are all sorts of fall-arrest harnesses, special floor coverings and specialist ropes and pulleys for many types of work which are the mainstay of your regular steeplejack but the key, in Colin's view starts at the very top, figuratively and literally.

With competitive tendering meaning that many companies have to trim down costs for many construction projects, but if, like me you see the sheer array of notices and protective measure demanded around constructions sites you will see that companies never sacrifice safety measures. As a somewhat flippant side-comment (by us) it doesn't do to be lax about these things as good staff and team members are a lot harder to find than state of the art equipment! Back onto the serious note, I'm impressed with the ingenuity of the design and development of equipment which has been brought into the mainstream for everyday use to keep the workforce safe and its testament to the powers that be in major (and not so major) companies that they embrace this technology to keep their construction sites safe places of work.

Colin Watt Associates are ATLAS members and provide consultancy support for CDM projects and for long term staff health and safety training for all things height-based. For more information contact them on 0845 338 7038

Monday 11 March 2013

LED Lighting - energy and money saving

We've recently been involved in the creation of an ecommerce website for Rice Products who have embarked on the retail of LED lighting for home and commercial clients.

LED lighting has had a it of stigma of over-priced and under-powered lighting and in all honesty for good reason - the technology had been sorely lacking and in some cases, woeful.

Step up new semi-conductor materials, particularly our old Gallium (yeah I'd never heard of it either) which is particularly good in its exchange of electrons under low voltages - great for creating light with little or no heat and with a double whammy of low energy usage.

As most type of lighting which employs LED technology is retrofit (dimmable ones need special drivers or transformers) this means that typically your 60W or CFL (compact flourescent lighting) low-energy bulb and GU10/MR11 spotlights this means there are normally few issues when it comes to straight swaps for your existing lighting.

One thing which is the "shot in the foot" for LED technology is that it is still relatively expensive to manufacture these lights which means that the upfront cost for a complete substitution of your standard current lighting for LED equivalents can be a pricey undertaking, I reckon for a 20 bulb house you are talking around £180-£200 depending where you shop.

Then it was pointed out to me that, ok you will pay, say £200 for your lighting replacement in one go, but you will reduce your energy usage by up to 85-95%. OK great I say, I'm not that much of a tree-hugger what does that mean to me?

Well look at it this way - you have 20 bulbs of assorted sizes and wattages, say some are 20W low energy CFLS, some are GU10 50W spotlights and the odd 60W standard bulb knocking around a hall cupboard or a centre light in your lounge. Add them all up and you get around 900W of power of which you will use say, 12 hours of half of them so you are running 450W for 12 hours a day. If you changed your bulbs to LED equivalent your wattage would be reduced to around 40W for same amount of time which an amazine 85% reduction in lighting usage in terms of energy. Translate into kWh usage and the currrent tariffs you will save around £25 per month on your lighting bills. Try an online LED energy savings calculator for more ideas about your saving potential

Now the killer point, if you added up all these savings and looked at the savings you will make on the energy usage alone, you will expect to get TOTAL payback within around 12-16 months - that means that the £200 you spent on day one would be completely paid back typically just over a year later. The final dagger in the heart for standard luminescent lighting is lifespan - the typical lifespan for an LED spotlight or bulb is between 3-5 years with typical domestic use. So you would typically replace your GU10 spotlight once a year when it blows, you wouldn't need to replace the LED equivalent for a further 4 years or around 30,000 hours of use.

Need I say anymore? Pop across to Scotland's newest LED lighting website for more information!