01 December 2008

Making locales available without .UTF8 appendix on Ubuntu

In Ubuntu locales are added via

apt-get install language-pack-en-base

Where en is the langcode.
By default locales are added with UTF-8 encoding, and are available to the system via nl_NL.UTF-8 or en_US.UTF-8.

In some environments, PHP coms to mind, this UTF-8 appendix isn't really common. We want to be able to access a local via the langcode only.
To make this possible you have to do the following:

Edit /var/lib/locales/supported.d/ (in this example we'll use nl)
Add a line for each langcode without the .UTF-8 appendix, but leav te UTF-8 after the space intact. The file for nl will look like this when we're done:

nl_BE.UTF-8 UTF-8
nl_BE UTF-8
nl_NL.UTF-8 UTF-8
nl_NL UTF-8


Recreate the locales with:
locale-gen --purge

The locales are now available to the system without the UTF-8 extention.

11 November 2008

Reset bandwidth usage of user in DirectAdmin

To reset the monthly bandwidth usage of a user in DirectAdmin enter the following as root in a terminal:


echo 'action=reset&value=USERNAME&type=user' >> /usr/local/directadmin/data/task.queue
echo "" > /var/log/httpd/domains/DOMAIN.EXT.bytes
echo 'action=tally&value=all' >> /usr/local/directadmin/data/task.queue


The first line resets the bandwidth usage.
I'm not sure if the second line is necessarry, but it reset's the http bandwidth usage of said domain.
The last line recalculates the used bandwidth, shown in DirectAdmin.

17 April 2008

(C#) Flatten DataSet to DataTable

Starting with a valid DataSet:

DataSet s = new DataSet();
s.ReadXml(@"C:\orders.xml");

Add table name to all columns that aren't used for binding ...

foreach(DataTable table in s.Tables) {
foreach (DataColumn column in table.Columns)
{
if(!column.ColumnName.Contains("_Id")) column.ColumnName = table.TableName + "." + column.ColumnName;
}
}

Now join all using David M.'s great DataTable Join function (over at http://weblogs.sqlteam.com/davidm/archive/2004/01/20/748.aspx):

DataTable t = s.Tables[s.Relations[0].ChildTable.TableName];
foreach (DataRelation r in s.Relations)
{
t = Join(s.Tables[r.ParentTable.TableName], t, r.ParentColumns[0].ColumnName, r.ChildColumns[0].ColumnName);
}

List removeColumns = new List();
foreach (DataColumn c in t.Columns) if (c.ColumnName.Contains("_Id")) removeColumns.Add(c.ColumnName);
foreach (string cName in removeColumns) t.Columns.Remove(cName);

Pretty easy, huh ;)

01 April 2008

Import MySQL databases with foreign keys

When importing large MySQL databases with lots of tables that have foreign key constrains (such as in our application framework RedOne), these constraints often interfere with each other. So ...

SET FOREIGN_KEY_CHECKS = 0;

... then dump, and afterwards ...

SET FOREIGN_KEY_CHECKS = 1;

... tadaa! :)

19 March 2007

restore emailaccounts from backup in directadmin

We mirror our production servers with rsync. So on our backupserver we have a copy of the complete filesystem of our production servers.

To restore all emailaccounts of a direactadmin user the following directories have to be copied back from the backup- to the production server:

/etc/virtual/domainname.com/
/var/spool/virtual/domainname.com/
/home/username/mail/
/home/username/imap/
/home/username/.spamassassin/


To copy the files back to the productionservers we use the following rsync command

rsync -avzI --numeric-ids --ignore-errors --force local/path/ user@production.server.com:/remote/path

05 March 2007

Speedup Mac OS X Mail.app


  1. Quit Mail & go to Terminal.

  2. Issue the following commands:
    cd ~/Library/Mail
    sqlite3 Envelope\ Index

  3. You will be dropped in an sqlite> prompt.

  4. Now issue the command vacuum subjects; (this will do something like OPTIMIZE TABLES in MySQL).

  5. Hit Ctrl-D to exit SQLite, exit Terminal and start Mail again

22 February 2007

Automatic backup on Mac OS X using rsync

I want to backup my iTunes music library and my iPhoto library to our local backup server that I'm able to SSH login to ...

  1. First off, enable passwordless login to the remote server. We generate a public/private rsa key pair using ssh-keygen -t rsa. Do not enter a passphrase so that it won't ask for one later :) Now copy the contents of the generated .pub file (your public key) to your server in the file ~/.ssh/authorized_keys. You should be able to login to your server using ssh username@server now.

  2. Create a script that rsyncs your libraries that contains
    rsync -a -e ssh "/Users/local_username/Music/iTunes" username@server:remote_path --update
    rsync -a -e ssh "/Users/local_username/Pictures/iPhoto Library" username@server:remote_path --update
    and name it, for instance, backupLibraries.command in your ~ folder. You can test it from the command line, now, if you so desire: ~/backupLibraries.command.

  3. The easiest way to make sure that your script is executed daily, automatically, is by using an iCal event (pffff...). First, we'll create the AppleScript that will be executed by iCal. Open Script Editor (Applications:AppleScript:Script Editor) and create a script that contains
    do shell script "/bin/bash /Users/local_username/backupLibraries.command > ~/rSyncErr.txt || echo -n"
    You can try this by pressing 'Run' from Script Editor. Store the script as backup.scpt, for instance.

  4. Now create an iCal event that executes the script daily, by setting Repeat: every day, Alarm: Run script, backup (select Other... and select the file that you just created from Script Editor), and 1 minutes after.

  5. There, you should be all set now! If something goes wrong, you will be able to find out by taking a closer look at ~/rSyncErr.txt. If you're the optimistic type, just remove "> ~/rSyncErr.txt" from the AppleScript.