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.

20 February 2007

Director: Finding the drive letter of a Windows CD-ROM

If you are creating Director Projectors which need to access data on the cd-rom drive the projector is distributed on you need to know the drive letter of the cd-rom drive.

Macromedia (now Adobe) gives us a nice solution in TN 3123 (google cache). This solution uses the fileIo Xtra to try open a uniquely named file on all of the drives. Since you provided the cd-rom, with the uniquely named file, you know that the drive which has this file is the drive you are looking for. The problem with this solution is: it doesn't work within a projector!

A much better way of finding the drive letter of the cd-rom drive the projector is currently running from is using the Lingo function the moviePath.
the moviePath contains the path of the directory the movie is current;y running out of, or in our case the cd-rom drive letter!

Example:
To build a path to a directory called "PDF" on the cd-rom, you'll only need the following Lingo:
set pdfPath = the moviePath & "PDF"