Monthly Archives: May 2011

MySQL database dump & restore

Putting this here as I keep having to google it (paranoid that I’d do something wrong and mess up the db more than anything else) and keep finding crap results.

mysqldump -u [username] -p [database_name] > dump.sql
# it then prompts for the password

mysql -u [username] -p [database_name] < dump.sql
# it then prompts for the password

Using strace to analyze apache

For times that you want to know exactly what a process is doing (for instance, if your apache is Pleskified and you’re getting weird website errors that can’t be traced back to any of your own code…) you can use strace.

 service apache2 stop

strace -f -o trace.txt /etc/init.d/apache2 start  # this will run strace on all child processes of apache, so you don't need to worry about figuring out the correct process

## do whatever to generate the error message (in my case, just accessing the site)

service apache2 stop

## use htop to verify the strace has stopped

service apache2 start
 

Then check trace.txt to find your issue!

And have a look here for a more thorough tutorial.

Drupal 7 custom template files per content type

Very useful – got this from here where you can also find the one for D6.

As the comment suggests, if you have a content type called ‘blog’, you can create a template file to apply to nodes with this content type only called page–blog.tpl.php.

<div class="codeblock"><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">themeName_preprocess_page</span><span style="color: #007700;">(&amp;</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$hook</span><span style="color: #007700;">) {
if (isset(</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'node'</span><span style="color: #007700;">])) {
</span><span style="color: #ff8000;">// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'theme_hook_suggestions'</span><span style="color: #007700;">][] = </span><span style="color: #dd0000;">'page__'</span><span style="color: #007700;">. </span><span style="color: #0000bb;">str_replace</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'_'</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'--'</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'node'</span><span style="color: #007700;">]-&gt;</span><span style="color: #0000bb;">type</span><span style="color: #007700;">);
}
}
</span><span style="color: #0000bb;">?&gt;