Archive for March, 2011

Backing up your server using JungleDisk Server Edition – part 2

In part 1, I told you how to set up JungleDisk backup for your Linux server. In this part 2, I’ll tell you how to automatically have it dump and backup your MySQL databases (correctly)!

There are security implications if this permissions are not set correctly on the files, as you’re storing your MySQL password in the script, and you’re going to have complete database dumps sitting on your hard drive. However, I will attempt to explain as clearly as possible my solution, and I’m not responsible if it doesn’t work for you.

So, start out by deciding where you want your database-dumping script to run from. A few good example spots are /root (root users home directory), and /etc/jungledisk (with the configuration files). I’ve called my backup script prebackup.sh. You’ll understand the name further below, but I’m going to use that name the rest of the way through.

So create your prebackup.sh script as root, and set it to mode 700.

touch prebackup.sh && chmod 0700 prebackup.sh

This makes sure that root is the only user who can read, write, or execute it.

Now, using your favorite text editor, you can use the following sample script:

#!/bin/bash
date=`date -I`
dir=/var/backups
file=sqlbackup-$date.sql
touch $dir/$file &&
chmod 600 $dir/$file &&
mysqldump --all-databases -p'__MySQLPassword__' >> $dir/$file
find $dir -ctime +7 -delete

Danny pointed out that creating gzipped MySQL dumps, as I had in my original script, is discouraged as it defeats the data de-dup feature of jungledisk. The above script has been changed from the original to make uncompressed dumps. Thanks, Danny!

The last line, with the find statement, is responsible for the cleanup of the directory. It will delete any file which is older than 7 days. If you want more or less time, simply change +7 to your desired number of days (keeping the + sign).

Warning: There’s very little (read: none) sanity-checking in this script. Replace __MySQLPassword__ with your root MySQL password.

Jay pointed out that there will likely be issues with handling special characters in the SQL password. If you have any suggestions, please feel free to post them in the comments below. 

After saving, you should have a 183-byte (give or take) file with 0700 mode:

root@ve:/etc/jungledisk# ls -l prebackup.sh
-rwx------ 1 root root 183 Mar 24 17:08 prebackup.sh

You should make sure that the directory in $dir is owned by user and group root and mode 0700. This will make sure that noone else has access to your dumped databases. Now that you have your script, it’s time to automate it. You could schedule a cron job to run the script, but it’s easier to have JungleDisk run it for you at the start of every backup job.

Start your management-side program, login, and go to your server’s backup configuration. Under Backup Options, check Enable Pre and Post Backup Scripts. Now, click Configure, and in the Pre-Backup Script, enter the full path and filename of your newly created script, i.e. /etc/jungledisk/prebackup.sh.

That’s it!

Now, on your assigned schedule, the server engine will run your database dumping script, and start your backup job. Of course, make sure whatever directory you’re dumping your databases to is included in your backup set.

The last thing to note is this script is amazingly light; it doesn’t delete any old databases and it doesn’t do much else. You’re free to modify it, and I would greatly appreciate any feedback on your modifications.

Comments are welcome, as always.

Advertisements

, , , , ,

Leave a comment

Ubuntu CUPS Brother Print Self-Test Page Error

If you followed my previous article about setting up the Brother HL-2170W under Linux, and attempted to print a self-test page, you may hav e gotten the following less-than-helpful error message:

Print Self-Test Page Brother Error

Unable to send command to printer driver!

Unsupported format ‘application/vnd.cups-command’!

Two bugs have been reported against this in Launchpad (36532 and 510781) and one in Debian (381743), but the end result is that there are two options, “Print Test Page” and “Print Self Test Page.” The “Self-Test” is what generates the error. If you use the “Test Page”, it seems to work without error. The Launchpad pages show fixes/workarounds, but if printing works fine for you, it may be easier to simply let it be until it’s fixed upstream.

Questions, comments, and feedback are welcome in the comments.

, , ,

Leave a comment

Installing Skype on Ubuntu (or Debian) with updates for Skype URLs

This how to will show you how to install a Skype client in Ubuntu & Debian base operating system.

1. First of all you need to start up Synaptic Package manager. Go to System->Administration->Synaptic Package Manager

2. From Synaptic, go to Settings->Repositories. Click on Other  Software Tab. Check the box next to Canonical Partners.

3. Click Close, and Click ‘Reload’ at the top of Synaptic. Now you can locate Skype and install it from Synaptic or Ubuntu Software Center.

Now to install skype-action-handler to handle skype: URLs:

Download and install the Skype Action Handler
http://search.cpan.org/~ecarroll/Net-DBus-Skype-0.02/script/skype-action-handler (direct download link) and extract.

In a console, navigate to extracted files directory and run these as root:

perl Makefile.PL
make
make test
make install

For Mozilla (Firefox)
* Open Mozilla (Firefox)
* Type about:config in the address-bar to open the configuration editor.
* Use the scroll bar to navigate to the network.protocol… section.
* Check if the network protocol section includes a network.protocol-handler.app.skype key.
* If a key exists, edit it. If no key exists, create a key by right-clicking on any key and selecting New -> String from the pull-down menu.
* Enter network.protocol-handler.app.skype as the key name.
* Enter /usr/local/bin/skype-action-handler as the key value.

### For GNOME-aware browsers (Epiphany, Firefox 1.5)
Run the following two commands:

/usr/bin/gconftool-2 -s -t string /desktop/gnome/url-handlers/skype/command '/usr/local/bin/skype-action-handler "%s"'
/usr/bin/gconftool-2 -s -t bool /desktop/gnome/url-handlers/skype/enabled true

Thats it – Test Call should work in Firefox. UPDATE: Except, it doesn’t work here. I can’t give you a valid link because WordPress keeps eating it. :\ But, try this yourself in an html file:

skype:echo123?call

To undo the above gconftool key changes, you may run the following:

gconftool-2 --recursive-unset /desktop/gnome/url-handlers/skype

Original post by thestudio53 at http://blogs.skype.com/linux/2006/08/making_skype_links_work.html. Rewritten with updates for Ubuntu 10.04 and information from http://ubuntuforums.org/showthread.php?t=449543

Questions, comments, and feedback are welcome. Please share your experience with this so I can improve the guide. Thank you.

, , , , ,

Leave a comment

Backing up your server using JungleDisk Server Edition – part 1

 

This guide assumes you’re using a Debian-based (Ubuntu, Debian) build of Linux, and we’ll be using the 64-bit download from JungleDisk. The instructions don’t really change for the 32-bit version, except for the installer file name.

The first steps:

Go over to the JungleDisk Business page and sign up for, and download, the server edition. Now, this edition comes in two very important parts: The server-side program, and the management-side program.

The server-side program is what runs on your server. That’s the “backup engine” if you will. You will download the program appropriate for your server environment.

The management-side program is the program that you remotely connect to the “server” to configure it. You will download the program appropriate for running on your desktop computer.

It is fine to download the server-side version for Linux and the management-side version for Windows, if that is your configuration. In this case, I’m downloading the Linux .deb server-side installer for 64-bit linux, and the Windows management-side program. I can’t give you the actual download links; you’ll find them in your account page.

Now, on the server, I’m going to install the server-side engine as root. Navigate to the directory where you placed the downloaded file, and run:

sudo dpkg -i junglediskserver_315-0_amd64.deb

That will install the server. Follow the directions. Now, since it’s the deb package, it will automatically set up init scripts to make sure the jungledisk engine runs on startup. However, you will notice that at the end of the setup you were prompted to copy and edit an xml file. Copy /usr/local/share/jungledisk/junglediskserver-license-EXAMPLE.xml to /etc/jungledisk/junglediskserver-settings.xml

cp /usr/local/share/jungledisk/junglediskserver-license-EXAMPLE.xml /etc/jungledisk/junglediskserver-settings.xml

Now use your favorite editor to make a few changes to /etc/jungledisk/junglediskserver-settings.xml:

between and , enter your license key (found in your JungleDisk account).

Now, restart the jungledisk service.

/etc/init.d/junglediskserver restart

Myself, I also added my login user name and password between and respectively, but I don’t think it’s necessary. Worth keeping in mind if something doesn’t work right.

That’s all for the server-side configuration.

Now, on your management-side program, simply run the program and log into your JungleDisk account and your server should appear in the list. Double-click on it and the configuration screen will appear, where you can create backup sets and schedule them as you wish.

Want to correctly backup your MySQL databases in your backup set? See part 2 of this article, coming soon!

Comments are welcome, as always!

, , , , , ,

Leave a comment

DeskJet 5150 print quality issues

The HP DeskJet 5150 is one of many printers that houses the print heads on the cartridges. This makes troubleshooting and resolving print issues fairly easy.

If you’re having printing issues with your DeskJet 5150 (or just about any other HP inkjet printer), start with the following steps to resolve it:

Step 1 – Clean the print heads programatically

If you don’t already have it, install the HP Printer Assistant software. From within the Printer Assistant, select “Clean Cartridges.” If the printing gets better, but isn’t completely cleared up, run it again. Be careful though, cartridge cleaning consumes a lot of ink.

Step 2 – Clean the print heads and contacts manually

If Step 1 didn’t resolve your issue, or it improved a little and then didn’t improve any more, then try removing the cartridges and cleaning the print heads carefully using a small amount of rubbing alcohol. Also clean the contacts on the back side of the cartridge.

Step 3 – Replace the cartridges

If your printing issue is still unresolved, replace the cartridges. Replacing the cartridges gives you a full tank of ink and new print heads. If it still doesn’t work, then your printer is likely defective and needs replacement.

Have any advice to share regarding printer head cleaning? Feel free to share it in the comments below!

Leave a comment

How to automatically purge Piwik logs using a cron job

If you’re using Piwik Analytics, you may know that over time your Piwik database will continue to grow over time. The piwik log tables as well as the archive tables will continue to grow until you purge them.

The Piwik developers are aware of this and a ticket has been in their system for a while now to develop a way to automatically purge the Piwik logs. The FAQ describes a SQL query you can run to purge the Piwik logs manually, but you may want a way to do this automatically. Fortunately, here’s the solution, with a few caveats.

UPDATE: As of Piwik 1.5, the following method is depreciated. Piwik now has log purging implemented. See Piwik FAQ #42.

First, before proceeding, check the FAQ link for the correct SQL query to run. The SQL query has changed at least once that I’m aware of. The below guide reflects the SQL query that was posted as of the day this article was posted.

Second, this method uses a script which will contain a SQL password, so it does have some security implications. You can avoid these by making sure the script has the correct permissions. This guide will assume that your SQL user’s name is ‘piwik’ and you are running the script as unix user ‘www-data’. Please adjust for your individual configuration.

Third, and lastly, it’s suggested to run this query monthly. You will want to make sure your logs have been archived for the proceeding month. In most normal installations this is the case. The only time this would not be, is if you are archiving using a cron job and your cron job has not been running.

So here goes:

Step one:

Find a place where your cron user will have access to the SQL file. A suggested place is the misc/cron directory within your piwik installation, right next to the archive.sh file. Let’s call this file purge.sql. It’s not necessary for it to not be accessible from the web, as it won’t have any sensitive information in it — just the SQL query. Create this file and paste the following SQL query into it:

DELETE piwik_log_visit, piwik_log_link_visit_action
FROM piwik_log_visit INNER JOIN piwik_log_link_visit_action
WHERE piwik_log_visit.idvisit = piwik_log_link_visit_action.idvisit
AND visit_first_action_time <= DATE_SUB(CURDATE(), INTERVAL 30 DAY);
OPTIMIZE TABLE piwik_log_visit, piwik_log_link_visit_action;

Step two:

Create the script which will call the SQL query. This script will contain your SQL password, so it’s a good idea to make sure it is mode 0700 and outside a web-accessible directory. We will call this purge.sh. Assuming your database is called piwik, your SQL username is piwik, and your password is piwik123, create the file with this query:

mysql piwik -upiwik -p'piwik123' < /var/www/piwik/misc/cron/purge.sql

For your reference, the mysql command sequence is:

mysql -u -p < mysql.sql

Step three:

Time to schedule the cron job. You can either edit the crontab yourself from the terminal ( crontab -e ), or use your favorite web-GUI scheduler such as cPanel, Webmin, etc.

For the terminal users, you’ll want the crontab line to read:

1 0 1 * *     sh /path/to/purge.sh

This will schedule the purge.sh script to run at 12:01am on the first day of the month.

For the web-GUI users, refer to your GUI’s documentation.

Once this is done, just relax. Auto-purging will take place as scheduled.

Questions or comments about this? See anything that could be improved? Have a better way of doing this? Your comments are welcome, as always.

, , ,

Leave a comment

Getting the IP address of your networked Dell 3333dn printer

Suppose you’ve got a Dell 3333dn printer, plug it into your network, and want to set up your printer driver, but you don’t know the printer’s IP address. No sweat, just reach for the printer’s touchscreen and hit:

Menu > Reports > Network Setup Page

A one-to-two page report will print which has your printer’s IP address, MAC address, host name, and anything else you could want.

Comments are welcome, as always.

Leave a comment

How to get your Dell Service Tag from the command line in Windows and Linux

There’s plenty of times you can need the serial number (aka Service Tag) from a Dell machine, but not be able to physically look at the label. It’s a server in a datacenter, it’s your laptop and it’s on a dock, etc, etc. Fortunately, there are easy commands to get the serial number right from the command line in both Windows and Linux.

Windows:

From a command prompt, type:

wmic bios get serialnumber

Linux (Ubuntu and others):

From a terminal, type:

sudo dmidecode -s system-serial-number

Comments are welcome, as always.

, , ,

Leave a comment

Get your Feedburner follower count in PHP

Important: Please see the update at the bottom of this post.

If you use Feedburner for RSS circulation, here’s a handy ready-to-go way of getting your Feedburner follower counts using PHP. This requires that you have the Feedburner Awareness API enabled for your feed.

Note that the code below uses PHP’s file_get_contents() rather than the preferred cURL function, but it does work. You may also want to cache your result to prevent hitting any API limitations.

function GetFeedburnerFollowerCount($feed){
$feedburner_xml = file_get_contents("http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed);
$xml = new SimpleXmlElement($feedburner_xml, LIBXML_NOCDATA);
$new_feedburner_followers= $xml->feed->entry['circulation'];
return $new_feedburner_followers;
}

You can also substitute ‘hits’ or ‘reach’ for ‘circulation’ in the example code.

Update: The Google Feedburner API is no longer available.

Comments are welcome, as always.

Leave a comment

Generate a random password in PHP

Here’s a code snippet that will quickly generate a random password, using PHP. You can specify the characters set and the number of characters.

function generatePassword($length = 6, $chars = '23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ')
{
  $password = '';
  $char_length = strlen($chars);
  for ($i = 0; $i < $length; $i++)
  {
    $num = rand() % $char_length;
    $password .= $chars[$num];
  }
  return $password;
}

Comments are welcome, as always. Have a faster way or a leaner function? Feel free to share!

,

Leave a comment