Category Archives: Tech

Bacula Restore Using Ansible

Backups are an essential part of Systems Administration. And backups without validation are, to put it bluntly, useless. Here’s a simple ansible playbook that you can automate every day/week/month backup verification.

- hosts: bacula
  user: user
  sudo: True

  - name: Restore files from bacula for weekly backup tests
    shell: /bin/echo "restore before=2013-10-14\ 08:00:00 client={{ item }}-fd restoreclient={{ item }}-fd file=</root/bacula-restore-tests/{{ item }}.bcl where=/tmp/bacula-restores yes" | /usr/bin/bconsole
        - hostname1
        - hostname2
        - hostname3
        - hostname4
    ignore_errors: yes

Purge All dpkg Packages Marked As rc

Title says it all. Purges the packages and their configuration files. Watch out for “directory not empty” messages and manually delete those.

dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs apt-get autoremove --purge -y


Install A Particular Version of PHP – Debian Squeeze

Recently ran into an issue where I needed a specific version of PHP on a base Debian 6 install. The default is php 5.3.3 but what I wanted to install was php 5.3.8 for some testing.

Dotdeb maintains updated .deb packages for many LAMP applications. They also maintain older versions in their archives. This is what I had to do, which I think can be extrapolated to any other package you need.

Use wget to download all the .deb packages you need.

wget -r -l1 --no-parent -A ".deb"

aptitude install libonig2 libqdbm14 libltdl7 libmcrypt4 libcurl3 #Some dependencies from the stable branch

dpkg -i php5-cli_5.3.8-1~dotdeb.2_amd64.deb php5-common_5.3.8-1~dotdeb.2_amd64.deb php5-gd_5.3.8-1~dotdeb.2_amd64.deb php5-mysql_5.3.8-1~dotdeb.2_amd64.deb php5-mcrypt_5.3.8-1~dotdeb.2_amd64.deb php5-mcrypt_5.3.8-1~dotdeb.2_amd64.deb libapache2-mod-php5_5.3.8-1~dotdeb.2_amd64.deb php5-curl_5.3.8-1~dotdeb.2_amd64.deb php5-common_5.3.8-1~dotdeb.2_amd64.deb

Joomla! – Unexpected $end

I went through some trouble and spent some time on this issue before finally realizing that it was a super easy fix. To address a much bigger issue, I was moving a Joomla! 1.5.x(I know, old) site from Fedora 7 to Fedora 14. Just to make sure everything goes well with the upgrade I test everything in a stage environment.

  • Fedora 14 comes with php 5.3.8 by default.
  • Moved the site and db over. I start seeing a bunch of “Parse error: syntax error, unexpected $end…” httpd errors for a particular template file.
  • Checked the php file in question – no php syntax errors.
  • Some HTML in that file. Is the HTML malformed in some way? Nope.
  • May be its the PHP version.
    • yum downgrade php php-* (To version 5.3.3)
    • Bring the latest code from git and test.
    • This code works on our dev with php 5.3.3 and does not work on this Fedora 14 instance php 5.3.3.
    • So nope. Thats not the issue. Revert the changes made to php.
  • I installed php-suhosin for security. Is that causing an issue?
    • yum erase php-suhosin
    • Doesn’t solve anything. Re-install php-suhosin.
  • Is anything being dynamically added to the page from the database on load? Nope.
  • Check httpd configs – Not the issue.
  • Restarted apache a bunch of times and pulled my hair out.

At last I finally realized it has to be PHP settings – I don’t think anything changed drastically with the way people need to code in php from version 5.3.3 and 5.3.8. So I get the php.ini files from dev server and the Fedora 14 server, strip out all the comments and empty lines and do a side by side diff of the two files.

The culprit: short_open_tag=Off

Apparently this is set to off in the newer versions of php.ini file and for a good reason. These tags are notorious for conflicting with xml tags among other things and code containing short tags is generally considered not portable. Portable being the operating word in my situation since I’m jumping a few OS versions. Change this to “On” and restart httpd and I was good to go. Obviously this old version of Joomla! with a bunch of customizations has a lot of legacy code. I really wish I had started with comparing the php.ini files.

Rename Multiple Files In Debian or *nix

Obviously the n00b trick of trying to do

mv oldName* newName*

does not work.

Interestingly I just found that Debian has a “rename” command that supports perl regular expressions. So this would work in case you were wondering how:

rename 's/^oldName/newName/' oldName*

Replace spaces in the filenames with “_”:

rename 's/\ /_/g' *

Check your man pages before you attempt this on a different *nix system. Different rename binaries might have different functionality.