Backing up and verifying files in Mac OS

There are some interesting backup tools for system backups (Time Machine) but I want to just be able to copy and verify a directory (and its children).  I’ve heard that the commercial product Retrospect provides copy and verify functionality, but I’m cheap.

This is the method that I used.  I’d be interested on hearing feedback about it:

# Copy the files using ditto 
$ ditto /Volumes/Backup/columbus_da/ /Volumes/ghingexternal/columbus_da

# Get md5s for the original and copied files
$ find /Volumes/ghingexternal/columbus_day/ -exec md5 '{}' \; > md5s-new.txt
$ find /Volumes/Backup/columbus_day/ -exec md5 '{}' \; > md5s-old.txt

# Strip out the directory prefix from the md5 files
$ mv md5s-old.txt md5s-old.txt.bak
$ mv md5s-new.txt md5s-new.txt.bak
$ sed 's/\/Volumes\/ghingexternal\///' md5s-new.txt.bak > md5s-new.txt
$ sed 's/\/Volumes\/Backup\///' md5s-old.txt.bak > md5s-old.txt

# Compare the md5s of the copied files
$ diff md5s-old.txt md5s-new.txt

Imapfilter certs

I was having trouble SSHing into my workstation.  It would just hang at the login.  I was worried that I had gotten 0wn3d.  I logged in at the console and ran top and saw that there were a bunch of runaway imapfilter proccesses from my cron runs.

I ran imapfilter from the command line and got the following error:

ATTENTION: SSL/TLS certificate fingerprint mismatch.
Proceed with the connection (y/n)? y

In order to get rid of this error and make it cronable again, I had to delete the contents of ~/.imapfilter/certificates and re-run imapfilter from the command line, telling the program to accept the cert permanently.

This mailing list post was very helpful.

I’m still going to lock down my box anyway.


passing grep results to other unix commands

This is old news to a lot of folks, but new and powerful to me.

Search for text in files and move matching files

$ grep --files-with-matches --null foo * | xargs --null -I xxx mv xxx dir_for_foos/

The above command searches for the string foo in all files in the current subdirectory.  It then moves each file to a specified directory.

Read a list of files from a text file and move those files somewhere

$ xargs -a ok.txt  -I xxx mv xxx /var/lib/accounting/joblogs/parsed

screen cheatsheet

I’ve been using the unix screen command a lot lately, and enough to want to learn more.

I used to just scroll through windows with CTRL-a n and CTRL-a p, but now I have a ton of windows in my screen session, so I want to be able to navigate easier.

According to the manpage, you can automatically set the title of a window, but I think it’s nice to do it interactively because the general task that will identify the window’s functionality might not easily be reflected in a path or command.

You can also use screen to copy/paste text between windows:

  • Enter copy mode: CTRL-a [
  • Start/End selecting text to copy: SPACE
  • Paste text CTRL-a ]