Thursday, 29 January 2009

Backing up folders using Samba and Cron

Now that we have a nightly backup of the joomla database we should probably make regular back ups of the folder structure to a separate machine. Our network is a predominately Windows based one. So we need to first of all gzip up the folder along with the database and then write it to the P: drive using Samba:

date=`date +%Y-%m-%d_%Hh%M`
mysqldumpdir='/home/administrator/Scripts/joomla-backup/'
mysqldump -uroot --password='******' --all-databases | gzip > $mysqldumpdir$date.gz
tar -c /var/www/joomla/ -i $mysqldumpdir$date.gz | gzip -c > Documents/backup.tar.gz

This first of all puts the joomla folder and the mysqldump file created last post into a tape archive. We string that together and gzip the results, at the moment this points to the Documents folder of the administrator, we will have to now hook it up with Samba. I started by installing the Samba client on my Ubuntu build. Or if you want an easier route, try Places -> Connect to Server, you can see it from there.

But you want to mount it right, folow the guide. warning make sure that the code will run from anywhere and use absolute addresses, then copy your local backup to the backup server, code looks like this:

date=`date +%Y-%m-%d_%Hh%M`
mysqldumpdir='/home/administrator/Scripts/joomla-backup/'
backupfolder='/home/administrator/Documents/'
mysqldump -uroot --password='******' --all-databases | gzip > $mysqldumpdir$date.gz
tar -c /var/www/joomla/ -i $mysqldumpdir$date.gz | gzip -c > $backupfolder$date.tar.gz
cp $backupfolder$date.tar.gz /mnt/devserver/$date.tar.gz

Wednesday, 21 January 2009

Cron PHP mysqldump ubuntu sendmail

The problem is we have a Joomla install on one of our servers, we want to back up the databases each night and mail us to confirm. Problem being that Ubuntu doesn't have sendmail installed by default and when you try and call the php mail() function it breaks saying it can't find send mail. A quick "sudo apt-get postfix" installed postfix mail, a much more competent mail system.

Next up is starting the cron tasks, I used a little guide and soon had cron running a mail script using a command line "sudo crontab -e" and editing in nano, not a big fan of vi

32 * * * * php /home/administrator/Scripts/backup-intranet.php

this emails me every 32 minutes, mails work on my gmail account, but my work account must be eating them with the spam filter.

So all good so far, the next stage is to set up the daily mysqldump to backup joomla. Adding another line into cron:

04 18 * * * mysqldump -uroot --password='******' --all-databases | gzip > /home/administrator/Scripts/joomla-backup/joomlasqlbackup_`date +%m_%d_%y`.gz

backing up at 6:04 each evening, it executes when I'm root from command line and from normal, but when I'm in cron it doesn't fire. To get around this I placed a bash script to run this and pointed cron to that:


#!/bin/bash

date=`date +%Y-%m-%d_%Hh%M`

mysqldump -uroot --password='******' --all-databases | gzip > /home/administrator/Scripts/joomla-backup/$date.gz

Make sure the folder has permissions for scripts ot write to it! And the new cron is:

/home/administrator/Scripts/databasebackup.sh

Tuesday, 13 January 2009

Differences in Eclipse 3.4.1 when using salesforce

As mentioned in the previous post, there are differences in the behaviour of Eclipse 3.4.1 from the 3.3.x instructions provided by salesforce. A few other differences include:

When writing classes and triggers you were previously asked to right hand click (RHC) and select Apex -> Run Tests

All the RHC commands are now accessible under RHC Force.com. A bit of rebranding I suppose

Setting up Eclipse 3.4.1 with salesforce IDE

The current Salesforce documentation only covers setting up Salesforce with Eclipse 3.3.x. This little guide shows how you can set up Eclipse 3.4.1 with the salesforce IDE.

Download Eclipse Classic and install to you local machine.

In Eclipse click Help -> Software Updates... -> Available Software -> Add Site

Add the reference http://www.adnsandbox.com/tools/ide/install/ and click OK

Tick the boxes and click Install.

Window -> Open Perspective -> Other -> Force.com

Let's create our first project

File -> New -> Force.com

Name it and fill in your details. Be warned, if you are running a sandbox and a live site, which ever security token was reset last is you current security token

This isn't supposed to work with 3.4.x and there is a idea request for this feature, I seem to have negated the need for this change. Yippee!

use the cookbook to get you started

Salesforce Apex Code development

Apex is a language that only deals with logic of the business variety. Finding a route into developing it proves a little more complicated that you might think.

You need Salesforce

You need a developer account and a sandbox to play about in. As soon as you save Apex it is live!

Get the Eclipse platform with the Java IDE

Next download the Salesforce IDE from the website

You need a developer account, this must be separate from your normal salesforce account

log into you developer account by going through .force.com

The old starting apex development video made in 2007 suggests that when in salesforce you go to:

Setup - Build - code

but this is no longer the case as the build tab does not exist on a clean install

To see triggers, they are under:

Setup - Customise - XYZ - Triggers