Category Archives: Linux

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

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.

Mac OS X: How to connect to Windows File Sharing (SMB)

I wanted to connect to my home server using my mac today. I said to myself RTFM and went through the Apple KB article mentioned here. Well that did NOT help at all. I kept getting “Invalid User” error. So then I said to myself “I will google it before asking dumb questions” and this is what  found. You can use the same method to connect to any shared folders on a windows computer.

Open a “Finder” windows and press “Command-K”(or use Go > Connect to Server from the menu bar). Enter the url of your samba share as shown below. Depending on the settings of your samba server, if you don’t know the exact share name, you can omit the “/sharename” part from the url. The would open up a window with a list of all shares that you have access to.


DO NOT enter your credentials as shown below. This was why I was getting access errors. Make sure you delete any credentials stored in “Keychain Access” for this particular server if you saved some credentials that do not work.


Enter your credentials with the server name or ip followed by a forward slash and then username. This has been tested on 10.6 and should work for all other versions that support samba.


Remember to delete credentials saved to “Keychain Access” for this particular server if you need to connect to the same server but as a different user. This might come in hand when different folders are accessible only through user credentials.