Al Hoang

July 24, 2008

Social Networks

Filed under: humor — hoanga @ 8:57 pm

July 16, 2008

Multiple renaming utilities: mmv

Filed under: fixes, geek, tech, unix — hoanga @ 2:58 am

There are many multiple file rename utilities that you can dig up.

One that I am used to on Debian/Ubuntu-based distros is called rename which is one that is derived from the Perl Cookbook. However, note that this rename script does not seem to exist on other UNIX variants in a packaged format. It definitely does not seem to exist on a Fedora Core 9 box I use nor does it exist on a FreeBSD machine.

While it would not be too hard to swipe the perl script and copy it in place onto a system. I hate having to remember moving that script around and around with me from place to place so I looked around for other equivalents and found one called mmv. One nice thing is that there are packages for at least FreeBSD, FC9, and Debian/Ubuntu variants so it should be quite lazy to install compared to rename.

Below I give an example of using it to do a multiple renaming where I want to append the value 1 to the end of a bunch of filenames.

$ ls
cat_100  cat_15  cat_200  cat_50  cat_500
$ mmv cat"*" cat#1_1
$ ls
cat_100_1  cat_15_1  cat_200_1  cat_500_1  cat_50_1

July 14, 2008

On the irritation of trying to run GPG on a remote headless server

Filed under: gripe, stupid, unix — hoanga @ 12:40 am

My short, short suggestion is… don’t: This blog post explains it much better than I can although I definitely have been the victim of trying to generate a GPG key on a headless server to no avail:

While trying to generate a gpg keypair on a remote server, I discovered I lack entropy. Eventually I had to physically type on the keyboard in order to generate enough random bytes.

I guess in the meantime the best workaround is to generate a GPG key on a workstation somewhere and transfer that to the server in question. A little hokey but I guess if you truly need a GPG key that would be my suggestion.

References

July 3, 2008

svnbackup-restore.rb, svnbackup’s handy companion tool

Filed under: Open Source, fixes, ruby, tech, unix — hoanga @ 10:48 pm

Doug Hellman’s svnbackup script tool is a really handy tool for setting up automated backups for a subversion repository.

However, the non-fun time comes when one wants to restore a subversion repository that has way too many dumpfiles parts. The instructions for restoration are basically ‘roll your own’ if you want to try to automate the restore procedure. What would be nicer is if there was the converse tool that made it easier to not have to figure out how to re-order the backup files in the proper manner in order to perform the restore.

I spent a few minutes thinking about it and wrote a small Ruby script to help with this that I call svnbackup-restore.rb. Here is the (hastily written) source code. (Download here)

#!/usr/bin/ruby
# Program Name: Restore the restore
# Purpose:      Take all the svn dumpfiles generated from svnbackup
#               sort them and try loading them via svnadmin
# Usage:        1. Create the new repo path with svnadmin create
#               2. Set repo_name to the repo backup file names
#               3. Set restore_path to the new path to restore to
#               4. Run it ./svnbackup-restore.rb
# Assumptions:  svnrestore-backup.rb is in the same dir as the svn dump files

# CHANGE PARAMETERS HERE
repo_name = 'myrepo'
restore_path = '/path/to/myrepo'

# Print out debugging?
DEBUG = true

# DON'T CHANGE BELOW

# Filename format is 'dumpfile---.bzip2'
svn_dumpfiles = Dir["dumpfile-#{repo_name}*.bzip2"]
sorted_files = svn_dumpfiles.sort do |a, b|
  left_rev = a.split('-')[2].to_i
  right_rev = b.split('-')[2].to_i
  left_rev  right_rev
end
sorted_files.each do |dump_part|
  results = `bzcat #{dump_part} | svnadmin load #{restore_path}; echo $?`
  puts results if DEBUG
  res = results.split.last.to_i
  if res != 0
    puts "Error on trying to load up #{dump_part}!"
    exit 1
  end
end

Powered by WordPress

Protected by AkismetBlog with WordPress