bash

Duplicity and the Rackspace CloudFiles API for backups

I've been playing with RackSpace Cloud lately and so far I've been quite impressed. The price is quite competitive, the network seems quite stable and performance is no issue. Plus: persistent storage in the cloud, out of the box! Awesome.

The support has been good (I had a routing issue on privatenet interfaces between two servers, which I was certain was either at the network or hypervisor layer and not my firewall. The engineers and I ran through the usual tests til it was assumed a hypervisor routing issue with this particular guest, which a reboot of the guest fixed).

Bash shortcuts

Ctrl-a -> go to the start of command line
Ctrl-e -> go to the end of command line
Ctrl-p -> previous command in history
Ctrl-n -> next command in history
Ctrl-f -> next character in command line
Ctrl-b -> previous character in command line
Ctrl-r -> reverse search in history file
Ctrl-d -> delete current character
Ctrl-k -> delete from the prompt to the end of command line
Ctrl-_ -> undo (yes, but limited)
Meta-< -> go to beginning of history file
Meta-> -> go to end of history file
Meta-f -> go to next word in command line
Meta-b -> go to previous word in command line

Better rsync backup script

#!/bin/bash
# Basic backup script
# Written in February 2010
 
# Set to q to disable verbosity
VERBOSITY="v"
 
# The program we're using to backup
PROGRAM="rsync"
 
# The arguments to the program
OPTIONS="-aHP$VERBOSITY"
 
# The remote machine we're backing up
SERVER="max"
 
# The local disk to back up to
DISK="/mnt/disk"
 
# An array of shares on $SERVER to back up
SHARES=(
  hr
  finance
  clients
  operations
  newsvn
  svn
  backup/jira
  backup/svn/noah
  backup/dbbackups/kontrol_live
  backup/dbbackups/god
)
 
# The magic
for share in ${SHARES[*]}; do

Bash: Monitor file addition/deletion in a directory

Silly little script to monitor changes in a directory (new or removed files)

Takes the destination dir to monitor from stdin

One day I'll learn how to use inotify.

#!/bin/bash
 
# Monitor a directory for file changes
# (add or remove) as requested
 
touch /tmp/testdirb.$$
while true
do
  find $1 -print > /tmp/testdira.$$
  diff /tmp/testdira.$$ /tmp/testdirb.$$ > /tmp/dirdiff 
  if [ -s /tmp/dirdiff ]
    then
      sed -i s/"<"/"New files"/ /tmp/dirdiff
      sed -i s/">"/"Removed files"/ /tmp/dirdiff

Aegir batch site backup script

Many Aegir users ask whether there is a way to schedule backups of all sites provisioned in Aegir. Currently at the time of writing, no such scheduling exists within Aegir itself, since we have a few design decisions to work out (such as where to store the backups, especially when multi-server comes in!)

For the meantime, here's a crude little shell script that might help you. You should execute it as the aegir user.

This site is archived. mig5 is taking a break from writing.