Mac/Linux – Backing up MySQL Databases

For similar reasons as to why I created drupal_db_dump for dumping Drupal databases; I wrote a wrapper script for the mysqldump command. One difference however, is that you can pass in options to the mysqldump command, which allows for greater utility. You do this by appending — to the end of the script and then specifying any valid mysqldump flags.

Example:

./msdw -d database1,database2,database3 -p /path/to/store/dumps -a — -u mysql_user –password=itsasecret –single-transaction

The only mysqldump flags you shouldn’t specify are ones relating to which databases to dump (ex: –all-databases). The database(s) you wish to dump must be the argument to -d flag and if you specify multiple databases, they must be separated by commas with no spaces in between. As with drupal_db_dump, specifying -a will auto-purge all but the last dump for the previous month when a new month begins. But again, by design, it will do this only if the backups span a maximum of 2 months.

For anyone wondering, msdw is an abbreviation for mysqldump wrapper. The guy that usually names my scripts got fired for being too verbose. drupab_db_dump, really? Terrible.

Advertisements

Linux/Mac – Backing up Drupal Databases

I manage several servers that are hosts to a variety of Drupal 6 & 7 sites, and I needed a script to intelligently dump each site’s database. Enter drupal_db_dump.  A  script I wrote in Ruby that uses drush (command line tool to manage Drupal) to do exactly just that. This script is best run via a cron job and takes two or three parameters: a Drupal sites directory, a directory where you’d like the dumps to be stored, and an optional archive toggle. Here’s what it will do:

  1. Go into every site in the specified sites directory and dump each database to a dated folder inside the dump directory (organized by site).
  2. Create an md5 checksum of the dump and write it to a file inside the dated folder.
  3. Compress the dated folder, and remove the original.

I also included an optional archiving functionality. If specified (-a), it will purge all but the last backup for the previous month when a new month begins. The last backup is moved to a folder called monthly_archives. By default, this functionality is turned off.

Benefits of use:

  1. Eliminates the need to configure a separate backup for each site,  as it will traverse all sites in the given directory.
  2. Quicker to setup, as you do not need to configure a regular and MySQL user. Drush will use the information in the site’s settings.php file to dump the database.
  3. Checksums!

Caveats:

  1. If the backups for a site span more than two months, this script will not attempt to archive them. This is by design. You will need to manually move or remove the backups until they only span one or two months.

Mac/Windows/Linux – Disabling Adobe’s PDF Plugin in Firefox

Back in January 2010 Greg Neagle wrote up a popular article detailing how to set default settings for Firefox. While his article was Mac focused, this technique is able to be used on all platforms. And in using it, you can effectively control a user’s experience with the browser. I previously have been using custom cfg files to disable the annoying update popups users receive, as we use munki to update software and most of our users aren’t administrators anyways. I recently just updated our cfg to disable Adobe’s PDF plugin and thought I’d share how I did it as, if you can believe this, it’s prone to problems. If you don’t already have a custom cfg file in place I recommend reading Greg’s article and following his instructions first. If you’re doing this on Windows or Linux, swap out the file locations mentioned in Greg’s article for the ones posted in the resource section at the end of this article.

Got a custom cfg file? Good. Add the following lines, this has been tested on Firefox 17+:

pref(“browser.preferences.inContent”, true);
pref(“pdfjs.disabled”, false);
pref(‘plugin.disable_full_page_plugin_for_types’, ‘application/pdf’);

The first two lines enable the in-browser PDF viewer Firefox has recently added. The third line forces Firefox to switch back to its default PDF handling action (Use Preview) if any 3rd party PDF plugin is selected on launch. Note that non 3rd party options (i.e. Use Preview, Always Ask, Preview in Firefox, Save File), are able to be chosen and will stick on re-launch. I want to emphasize this point, the above does not stop a user from selecting a 3rd party PDF plugin for their session but will merely reset it if its been done on re-launch.

Resources:

General:

http://kb.mozillazine.org/Lock_Prefs

Windows (may vary on the architecture version installed):

cfg: “C:\Program Files\Mozilla Firefox”

js: “C:\Program Files\Mozilla Firefox\defaults\pref”

Linux (may vary on flavour, installation method, and/or architecture version installed):

cfg: ” /usr/lib/firefox/”

js: “/usr/lib/firefox/defaults/preferences/”

Mac/Linux – Parallel Rsync Utility

I’m in the process of migrating 10 TBs of data from an NFS share to a CIFS share and while talking over the details with my team lead he mentioned that he would slap me if I proceeded to do the transfer in serial :-). With that motivation I wrote prsync_transfer! He was joking of course, but in all seriousness he is right. If you run rsync in a serial fashion, the initial “receiving file list…” process may take a while to complete, especially if you have a lot of small files to transfer. After the jump I’ll show you the utility I wrote to resolve this issue.

Continue reading

Linux/Mac – Have Margarita Startup Automatically On Boot

A little introduction.

Greg Neagle put together a wonderful third party Apple Software Update Service (SUS) called Reposado. In short, the top three greatest features Reposado offers are the ability to create separate update branches, the ability to offer deprecated updates, and it does not need to be run on Mac OS X hardware.

Reposado is great and if you’re using Apple’s SUS solution I recommend you switch. Reposado does have one drawback though, it’s command line only. While that isn’t a problem for most administrators, there may be times when you want someone else, who doesn’t feel comfortable at the command line, to manage updates. Or, perhaps you want the convenience and speed of a GUI. Jesse Peterson filled this void with Margarita, a web front end for Reposado that also runs on Mac or Linux.

We run Reposado on a Red Hat Enterprise Linux (RHEL) 6 server, and I recently installed and configured Margarita incase someone else needed an easy way to add an update to a branch. The only unfortunate part about Margarita on Linux is that it doesn’t startup automatically. If you plan to use Reposado and Margarita on a Mac, Jesse has a launchd task to accomplish this.

After the jump, I’ll explain to how to install the Margarita startup script I wrote for our RHEL 6 server.

Continue reading