A High-Tech Blech!

Computers got you down? Microwave wristwatch talking back again? Survival solutions abound.

An IT professional in confessional.


Backup Script: A Love Story

Sunday, August 15th, 2010

I have written a few backup scripts by now. Every time I do I find a new interesting challenge somewhere in the task. As such I’d like to talk a little about my most recent backup script and offer my script to the community at large.

First of all, I tend to use rsync for backups. It’s powerful and it works well. You can use rsync to backup any file system and so it is also very flexible in a network or on a virtual machine. I’m not going to dive into the man page for rsync, but you will want to take a look there (man rsync) because there is a wealth of information about the various switches available for that command. I have selected the switches that fit my purposes and that is what is displayed below.

Next, where possible I prefer to leave my backup drives unmounted until they are actually needed for the backup process. I consider my current system for dealing with this imperfect, but again that is what you will see in my current script.

Finally, the server I have written this script for is running the desktop version of Ubuntu. This is not likely important in any way except that (as you will see) if I had been running the server version I would not likely have had the same problems when I did my test run.

Ok, so here is my current script.

#
#
#
# run in cron Mondays at 4 AM
# [0 4 * * 1 /home/[scriptpath] >/dev/null 2>1]

# redirect from script --> sends all STDERR to log file

exec 2> /home/[username]/Desktop/$(date +%Y%m%d) ## use dated folder on desktop

## backup [DriveAa]

if ! mountpoint -q /media/[BUDriveA]
then
   mount -t [filesystem] -U [UUID goes here; no brackets or quotes] /media/[BUDriveA]
fi

# Note rsync -a copies permissions but will not copy owner:group if not run as root

rsync -ailS --delete --progress /media/[DriveA]/[Folder] /media/[BUDriveA]

umount /media/[BUDriveA]

## backup [DriveB]

if ! mountpoint -q /media/[BUDriveB]
then
   mount -t [filesystem] -U [UUID goes here; no brackets or quotes] /media/[BUDriveB]
fi

# Note rsync -a copies permissions but will not copy owner:group if not run as root

rsync -ailS --delete --progress /media/[DriveB]/[Y] /media/[BUDriveB]
rsync -ailS --delete --progress /media/[DriveB]/[Z] /media/[BUDriveB]

umount /media/[BUDriveB]

#

As you can see I like to keep my scripts well documented. I encourage you to do the same. Memory is fallible, after all.

(Note: Everything in square brackets [] will be replaced in your script.)

[filesystem]

This is where you specify the file system type you are using and is called out by the -t argument. For my script it was ext3.

[UUID]

This is a unique identifier for a drive and it is called out by the -U argument. I prefer using UUID’s because other drive/partition designations can change (for instance, sda1 can become sdb1 if you add a new drive). (For information on adding drives to your system see this ink.)

My backup script manages the backups for three directories (recursive) over two drives. I first test to see if a backup drive is mounted and if it is not I mount it. That’s the job of the if statements. (This is what I consider imperfect and will seek to improve as time moves forward.) It works well enough, and if you don’t want your backup drives to be mounted all the time this is a decent way of dealing with the matter.

You will also note that I unmount each drive as I finish with it (umount).

You will also see that in the DriveB example I backup (synchronize) two directories (Y & Z). This also helps to make it clear that you do not need to specify the name of the directory at the backup location.

Lastly, you see my note about -a copying permissions and requiring root to copy also the owner and user information. As such I put this script into a cron job as root.

What?

It’s easy enough to do. Just open cron as root:

#
#
sudo crontab -e

You will be prompted for your password. You can learn more here. You can see my cron entry for this script in a comment in my script above. The man page for cron (man cron) will help you understand how 0 4 * * 1 means every Monday at four in the morning.

Let’s talk about some of the mistakes I made.

The first big snag was not having the if statements correct. I left out the UUID’s and so the script did not mount the drive for the first sync operation. The if statement tested to see if DriveA was mounted and found that it was not. Then it ran the mount command which failed because no valid drive (UUID) was specified.

Because the drive was not mounted at the mount point rsync began synchronizing data to the mount folder and not the mounted drive. This caused the script to fail (once the OS drive containing / was full—about 105 GB later) and borked the / partition.

I was not able to restart Gnome (Gnome, the desktop environment, requires some free space on your / partition to function and mine was 100% full). I ssh’d into the machine from a Windows box nearby (using Cygwin) and maybe two hours later I sorted out what I had done. I was able to remove (using the rm command) the offending folder after making absolutely certain DriveA was in fact not mounted. After that I was able to reboot and get back into Gnome. (However, I did have to run fsck on the drive probably due also to the drive having filled itself. If you boot your system and get a shell stating you cannot login try running fsck and answering y to all the fixit questions.)

Oops. This is why we make test runs, right?

So I fixed the if statements (specifically the mount and umount commands) and that took care of that.

Then the script ran fine through the backup for DriveA but finished DriveB in a few seconds. Not possible. I looked back at the script and realized that I had specified the backup location for both the source and the destination. Damn it. Fixed that and DriveB was synchronizing properly.

I hope this helps you out.

(Thanks to Ian over at Ubuntu for his suggestions while I was troubleshooting.)

Happy scripting.

JamesIsIn
  • Share/Bookmark

BASH sudo through a Pipe

Tuesday, June 1st, 2010

I fixed my dad’s Windows box and after getting it all set up I figured I would create a backup image based on the completed build/installations/updates.  A nice best-of restore point, eh?

So I booted the machine into an Ubuntu 10.04 Live CD, created the necessary partition using gparted, and mounted that partition onto which I would create the backup.

I tried using dd to create the backup image, but found that my backup space was too small for the full OS partition.  To build the backup I ran this:

#
#
# dd command from partition to file
#
sudo dd if=/dev/hdb of=/path/to/image

Not such a problem because I could of course pipe my dd output into gzip and compress my backup image.  Typically if you want to compress the  image you would merely pipe the dd output into gzip like thus:

#
#
# normal format for piping dd into gzip
#
dd if=/dev/hdb | gzip > /path/to/image.gz

The problem is that if I used sudo on this full command I hit a permission denied error.  This is because sudo only applies to the first command (dd) and not to any subsequent commands (in this case gzip)—sudo does not flow through the pipe.  However, I pulled out my trusty BASH Cookbook and found a way to run the whole thing under sudo:

#
#
#
# proper way to manage using dd, gzip, and sudo
#
sudo bash -c 'dd if=/dev/hdb | gzip > /path/to/image.gz'

This runs a bash terminal as root (non-interactive) for the duration of the quoted command and then exits back into the interactive terminal I had been using.  Worked great.

(My backup partition was hdb; adjust your code accordingly.)

Thanks, O’Reilly.

JamesIsIn
  • Share/Bookmark

Hypocrisy Really Is the Greatest Luxury

Wednesday, May 19th, 2010

My dear friend Steve Jobs (and when I say dear friend I mean someone I’ve never met) has posted an article today describing their (Apple’s) relative disgust with Adobe for playing less nice than Apple as concerns Flash.

If you know nothing about computers the facts in this article might seem acceptable, but if you happen to know that the Internet isn’t something that exists on your computer then you will probably see at least some of the comedy available.

… we met Adobe’s founders…

I do so love the royal We.  It’s just rare one sees it in polite company anymore.

The two companies [Apple and Adobe] worked closely together to pioneer desktop publishing…

What?  What happened to Aldus?  PageMaker anybody?  Adobe acquired Aldus, kept PageMaker, and dumped Freehand (both successful Aldus products).  Oddly enough, Adobe ended up reacquiring Freehand when they much later acquired Macromedia.  The victors get to write the histories, I guess.  According to the Wikipedia article PageMaker “… is generally credited with creating the desktop publishing (DTP) field”, but this is certainly not something which can be credited to Adobe.  And Queen Steve?  Who’s garage where They in and what were They smoking?

First, there’s ‘Open’.

For Apple to accuse Adobe of running a closed system with Adobe’s Flash is the best example of the pot calling the kettle black I have seen in print.  It’s like Adolf Hitler accusing Joseph Stalin of “not being very nice”.  Oh, that’s not fair.  It’s not as though it were Microsoft accusing IBM of using proprietary systems.  Pick two minor totalitarian dictators from history (there are so many) and you’ll have the basic point.

It is true that “Flash products are 100% proprietary”.  But it is also true that the App Store is a conduit utterly controlled by Apple.  I’m not a big fan of Flash, but I don’t want to be forced into one store to do my shopping either.

Rather than use Flash, Apple has adopted HTML5, CSS and JavaScript – all open standards.

What about, say, Perl?  Or Ruby?  PHP?  MySQL?  I mean, there are dozens of ‘open’ programming languages and environments which Apple is necessarily excluding.  And because they control the conduit and the operating system there is no way for any of us to foist any of these other options on board.  They foist so that we don’t have to.

Apple even creates open standards for the web.

One.  Webkit.  And, let’s be honest, Apple didn’t create Webkit.  They co-opted an existing open source browser (Konqueror) and transformed that into Webkit and from there based Safari.

Almost every smartphone web browser other than Microsoft’s uses WebKit. By making its WebKit technology open, Apple has set the standard for mobile web browsers.

I’m not sure why they specify “Microsoft’s” mobile browser (sometimes known as Internet Explorer, Internet Explorer Mobile, IE Mobile, Pocket Internet Explorer, PIE, and (by me) That Stupid Clicking Browser), but what they neglected to mention was Opera.  I suppose by “set the standard” they mean “if you add all the Webkit based mobile browsers together they manage to eke past Opera Mini”.  Nice.  Opera Mini is still faster than Safari on an iPhone (so say my friends who have iPhones and LifeHacker).  Raise the bar.

Second, there’s the ‘full web’.

In this case “full web” means “video and games” and a very narrow swath of them at that.  Let’s list a handful of non-Apple supported Internet: FLAC, Ogg Vorbis, Matroska.  Full Web ftw!

Third, there’s reliability, security and performance.

Fourth, there’s battery life.

These claims are more or less reasonable.  (Though I have never seen Flash crash a Mac.  I have seen it crash many a browser, however.)  Though this is something that could be left to the consumer.  Freedom of choice just might be more important than security and flexibility more important than reliability.

What they say about battery life may or may not be true.  I am inclined to think it an exaggeration; however, I have neither tested this nor sought out such a test.

Fifth, there’s Touch.

Flash was designed for PCs using mice, not for touch screens using fingers.

For example, many Flash websites rely on ‘rollovers’, which pop up menus or other elements when the mouse arrow hovers over a specific spot.

I like touching.

The whole Internet “was designed for PCs using mice” because it was designed before the iTouchMyself.

Oh, wait.  The entire Internet was designed before the mouse was ubiquitous.  Shit.  The Internet was originally text based.  Double-shit.  When you send an image through e-mail, your message (including the image) is converted to text and then shattered and sent.  What the fuck?  It is converted back somewhere at the other end where things get reassembled.  In fact, e-mail is a lot like the transporter beam in Star Trek.

And sorry, but you can use mouse-overs in Javascript as well.  Then again Opera Mini doesn’t use Flash and hasn’t.  Yet somehow they have managed to be the dominant mobile Web browser for more than a decade.  Either it’s a miracle or Flash just isn’t that important.

… Adobe also wants developers to adopt Flash to create apps that run on our mobile devices.

If developers grow dependent on third party development libraries and tools, they can only take advantage of platform enhancements if and when the third party chooses to adopt the new features. We cannot be at the mercy of a third party deciding if and when they will make our enhancements available to our developers.

Really?  This is “the most important reason”?  Let me think: how many of my Mac applications run on any other platform?  Oh, yeah: fucking-none!  How about getting those ALAC or AAC files iTunes loves so much onto a non-iPod music player?  No fucking chance.  How about playing FLAC files on my iPod?  Only if I hack the little fucker using RockBox (which I have done and love).  (RockBox will play Apple’s proprietary file types as well, but if you are running RockBox you ought to be running FLAC and Ogg anyway.)

Ring ring!  Uh, yeah, Kettle?  Hey.  This is Pot.  I have some bad news for you…

Conclusions.

Perhaps Adobe should focus more on creating great HTML5 tools for the future, and less on criticizing Apple for leaving the past behind.

Perhaps Apple “should focus more on” certain open source standards, like FLAC, and give up this hypocrisy.

Damn.

Kisses.

Leave your comments below.

JamesIsIn
  • Share/Bookmark

How Facebook Fails to Scrape

Thursday, April 15th, 2010

I just wrote an article on setting up Google’s new Buzz (social site) to pull data from my blog.  I wanted to follow that up with an article on how to get Facebook to do the same.  The only problem is Facebook fails to manage this simple process.

Google and Buzz manage to pull information from my blog by scraping or periodically checking my blog site for new posts.  Facebook, through Notes, claims to be able to take an RSS feed from my blog (really any RSS feed) and deliver information about new posts to anyone watching my Facebook account.  As fate would have it, there is a bug which breaks this functionality—a bug which is over a year known.

(See my comments below for the preferred method of alerting Facebook concerning your RSS feed.)

There is as yet no fix.  There is a really crappy work-around.  It is the same as adding an RSS feed, so here are those instructions (see update below for an easier update method):

  • Click on Account —> Application Settings
  • Click on Notes (this will take you to the My Friends’ Notes, and oddly this is the only way I have found to get to this particular page)
  • Click on Edit import settings » (in a box to the right)
  • If you are performing the work-around, click the Stop Importing button (it is convenient to copy your blog’s RSS URL first)
  • Enter your blog’s RSS URL into the Web URL: field (mine is http://www.soundunreason.com/InkWell/?feed=rss2 )
  • Click the Start Importing button
  • You will then be offered posts to import; click the Confirm Import button

My RSS feed worked in Facebook for about 15 months.  Then it just stopped.  Now I have to perform this work-around anytime I create a blog post.  Fucking useless.  It’s only slightly helpful if I happen to create more than one post at a time.

Since Facebook has their own (crippled) blogging capabilities (Notes itself is a sort of blogging application) I have my doubts about Facebook feeling a strong motivation to fix the RSS problem.  However, maybe when they realize how soundly Google is kicking their ass with their ability accomplish blog-to-social-site updates (in spite of the fact that Google also has their own blogging application—at least BlogSpot and Blogger if I’m not mistaken) Facebook will suck it up and fix it.

Happy blogging.

Update:

I was pointed to another way to manually update RSS feeds.  Those instructions were not up to my annoying standards so I have re-written them.

  • Visit your Wall (which is to say go to your Facebook profile)
  • Beneath the “What’s on your mind?” Share button, click Options
  • This will reveal a Settings link; click it
  • This will reveal Stories Posted by You (and some other stuff); click Blog/RSS (which should be your blog)
  • This will reveal some settings for your blog; click Update Now

Not as painful.  I haven’t tested this yet. This will manually update your RSS activity.  Best of luck.

JamesIsIn
  • Share/Bookmark

How I Spill Ink into Google Buzz

Thursday, April 15th, 2010

I have a blog.  Shocking, I know.  I like to ensure that my social diseases sites are continually updated by my narcissistic ever-important posts.

It has gotten to the point where my social sites have social sites, but the latest and greatest entrant into the fold is Buzz from our overlords friends at Google.

I searched the Web and found a host of well-intentioned but either overly complex, poorly instructed, or downright misguided information about adding an RSS feed or automatic scrape from my blog to my Buzz updates.

Turns out it’s simple to get updates from my blog and I don’t have to use RSS per se.

There are two parts to setting this up.  First you need to add your blog to your Google profile.  Then you need to connect Buzz to that linked blog.  It’s a bit tricky, but with a small amount of attention to detail you should be able to do this in maybe ten minutes.

Ok, so let’s set up that profile.

Go to your Google profile and then follow these instructions:

  • (If you used my link above click View my profile)
  • Click Add more info to my profile
  • Under Links add your blog to the My Links section
  • If your blog doesn’t appear under Add Links use the Add custom links to my profile and paste in your blog address
  • (Do not use your RSS address; I used merely http://www.soundunreason.com/InkWell )
  • Locate your blog under My Links and click Edit
  • Check the box that says This is a profile page about me (This is the most important step.)

Now you can head on over to Buzz.

  • Locate and click the connected sites link (you may have to click on your name first)
  • If you did the first part correctly, your blog should appear here and you can simply click the Add button

Easy enough?

Ladies and gentlemen, spill that ink.

  • Share/Bookmark

Everyone Pads in the Field

Sunday, April 4th, 2010

I really enjoyed making fun of the pad.  (Microsoft already invented the iPad, like, forever ago–they called it Notepad.  (That’s funny on so many levels.  (I call this writing style Nesting Absurdities.)))

But I gave myself a good think and me thunk it ain’t so bad.  Yes, it may have been silly to  use the phone OS, but so was making a phone that couldn’t copy and paste.  Still they stumble on.  Reminds me of this song by Lori Anderson where she talks about walking being merely continuously falling and catching oneself.  “Why do we fall Bruce?”  Meh, you get the picture.

It occurred to me, it was like magic really, there was suddenly something new in my brain.  Not merely something I’d misplaced, but a story of a photographer in the field with a camera and an iPad (or any compatible TouchMePad) wirelessly tethered to one another.  Each time a photograph is taken it can be immediately analyzed on the substantial screen (Go Team TouchMePad!).

In a way this is like taking photography back to the days when one needed to carry around the glass plate negatives, only more compact.

I would suspect that graphic designers will also want to be seen with TouchMePads.   And of course the accessories!  “I put one sticker on mine.  Just one.  Ya wanna see it?”  Really?  Hello, Kitty?  That’s so amazing.

And you can have a screen object where shared files can be wirelessly exchanged with nearby TouchMePads?  Ok, yes, that will make many aspects of your job not just easier but also rather Star Trek cool.

Well, that’s where what’s left of my mind is residing.  Where’s your mind lounging?

  • Share/Bookmark

Unretarding Edit in Vista or Windows 7

Tuesday, March 30th, 2010

In XP it was possible to change which program ran when you chose Edit from the right-click context menu for a particular file, say a jpeg.  In Vista and Windows 7 they have merged that setting with the Open function.  In other words, in XP you could set one application to open a jpeg and a different application to edit a jpeg.  In Vista and Windows 7 if you want to have different applications perform these functions, you have to dig into the registry.

Sure, you can use Open With instead of Open to get to the other application; but, oh wait, Open With only works if you select one file.  What?  That’s right, select two jpeg’s and Open With goes away.

Really, what the fuck is the point of offering Edit and Open as separate options if they both do the exact same thing?

Retarded.

It is easy to arrange this on the Mac OS; it is easy to do in Ubuntu; it was easy to do in XP.  This is what happens when you work towards a Fisher-Price operating system designed for children and the geriatric: it slows the rest of us to a crawl.

Ok, so how do we fix this marvelous error and once again improve the disimprovement Microsoft has handed down from on high?

Obviously we need to hop into the registry editor:

Run —> regedit

Once in the registry editor (as an administrator, so don’t try this as a limited user), you will want to change two registry keys.  Here are the paths/names of those keys:

HKEY_CLASSES_ROOT —> SystemFileAssociations —> image —> shell —> edit —> command

HKEY_CLASSES_ROOT —> jpegfile —> shell —> edit —> command

I think my SystemFileAssociations key originally pointed to Paint and the jpegfile key pointed here:

%SystemRoot%\System32\rundll32.exe “%ProgramFiles%\Windows Photo Gallery\PhotoViewer.dll”, ImageView_Edit %1

But I replaced them both with the path below.  Once you find each key, change the contents of that key (either double-click the key or right-click and choose Modify…) to something which will open your preferred editor (I use Photoshop CS3 currently).  Basically it’s “DRIVE:\Path\To Your Editor’s\executable.exe” “%1″ so something like this:

"C:\Program Files (x86)\Adobe\Adobe Photoshop CS3\Photoshop.exe" "%1"

Click the OK button after each change and then hit your f5 key to refresh the registry (or just close it).  Now you ought to be able to Edit images with a different application than one with which you Open them.

Happy hunting.

  • Share/Bookmark

Calling for Retired Computers

Tuesday, March 30th, 2010

I run a program I call Linux for Anybody.  Essentially I accept donated machines and build them with Linux (currently Ubuntu) and deliver those machines to persons who otherwise may not be able to obtain a computer.

I am always seeking machines for this project.  The point of this post is to place this request for retiring machines in front of all who read my blog these days.

Is your company getting ready to replace machines?  Will those old machines be retired or sent off to a recycler?

Giving them to me is better than recycling them as they will be directly re-used.  Of course, I only accept fully functional machines and won’t take anything that’s ancient (this is not a museum project).  I can use keyboard, monitors, and mice as long as they are also fully functional (and please talk to me first if what you have are massive CRT’s).

I have what it takes to completely and securely wipe hard drives, so please include the hard drives with the machines.  I am happy to eradicate any potential data before I build the Ubuntu systems.

Let me know if you have any questions and thanks for participating.

On a related note, if you know of someone who might benefit from this program (a student, a teacher, some other struggling person) please talk to me and perhaps we can get them a machine with which they can perform research, surf the Web, communicate via e-mail and chat, and create and store important office documents.

  • Share/Bookmark

Don’t Lose Your Grip

Monday, March 29th, 2010

You may recall my article on using the wonderful Gnome ripping software Grip.  You didn’t read it?  Well, you ought to.  It’s right here.

As fortune would have it, this particular application has been languishing as concerns development.  That is to say that it’s a bit out of date and is using archaic libraries.  As such, or so I am told, Grip has been dropped from the Ubuntu repositories with 9.10 and I see nothing to indicate it will be returning with 10.4 either.  Woe is me.

Now I did find one person who took the time to arrange a repository and installation script all his own.  You can find that over on the Ubuntu forums:

http://ubuntuforums.org/showpost.php?p=8759491&postcount=25

It’s a bit of command line work, but it’s easier than compiling the program yourself.

You should report any troubles you might have on that forum post as you are likely to get faster responses.

  • Share/Bookmark

Update to My Renaming Script

Wednesday, March 3rd, 2010

A while back I wrote a post on renaming FLAC files to include their associated disc numbers. For example, if you have a file from disc 1 named “01 – Track Name.flac” my script would change it to “01.01 – Track Name.flac”.

This updated version of the script allows the user to enter the path to the folder needing files renamed and the associated disc number.

I think this is a slightly simpler method than my previous method for using this script. You can read about the original script here.

Here is the current script:

#
#
# Prepend album number before track numbers
# 01 - Track Name.flac becomes 01.01 - Track Name.flac

echo
echo "This script will change FLAC file names based on a containing folder and a disc number which you supply."
echo "Example:  \"01 - Track Name.flac\" becomes \"01.01 - Track Name.flac\""

read -p "I will require the path to the containing folder: "
if [ -d "$REPLY" ]; then
printf "I have confirmed this is a directory.\n\n"
directory="$REPLY"
else
printf "I cannot find this directory.\n\n"
exit 1
fi

read -p "Which disc number, please (01 through 99): "
# add test for 01-99
printf "%b\n\n" "I will prepend $REPLY to all FLAC files in: $directory\n\n"
newname=$REPLY

read -p "Press <ENTER> to continue (ctrl-c will abort)."
echo

cd "$directory"

rename "s/^/$newname./" *.[Ff][Ll][Aa][Cc]
#

This version also handles FLAC extensions in any case (flac=FLAC=FlAc &c).

If I make any updates, I’ll likely just change this post. As such, I should say that this current version is current as of 8 March 2010.

Have fun with that.

JamesIsIn
  • Share/Bookmark