Posts Tagged ‘ubuntu’

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

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

Go Do that Gnome-Do that You Do so Well

Monday, February 15th, 2010

Gnome-Do is an application launcher, among other things.  It is the fastest, slickest application launcher I have found for any platform.  It was originally designed after Spotlight from the Mac operating system.  However, it has outclassed its predecessor entirely.

With a couple of key-strokes I can launch any application on my system.  Or I could open a folder location.  Or I could just as easily search for something which came to mind.  Or I could use Gnome-Do to access the inner workings of many different applications on my system through its extensive plugins.   Or I could search the Internet.  Or I could search my del.icio.us bookmarks.

Pretty much anything I could imagine.  Just a few key-strokes.

It’s like magic.  I’m surprised Sarah Silverman doesn’t have a show about it.

If you are running Ubuntu (and you ought to be by now), Gnome-Do is available through Synaptic and the standard Ubuntu repositories.  However, if you would like to latest version of Gnome-Do you can add their repositories directly.

Open your repositories (System —> Administration —> Software Sources) and add these two entries (Third-Party Software tab; Add button):


deb http://ppa.launchpad.net/do-core/ppa/ubuntu [YourVersionHere] main

deb-src http://ppa.launchpad.net/do-core/ppa/ubuntu [YourVersionHere] main

(Substitute your version as appropriate.  I am running 8.10 and 9.10 so I use intrepid and karmic, respectively.)

You’ll also want to add the verification key for this repository.  The simplest way to do that is by running two commands (Applications —> Accessories —> Terminal):


sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 77558DD0

sudo apt-get update

If you are already running Gnome-Do, you can now update your system (System —> Administration —> Update Manager) and you will get the latest version.  If you need to install Gnome-Do, hop into Synaptic (System —> Administration —> Synaptic Package Manager) and look for it by name.

You will have to start Gnome-Do manually before you can use it (Applications —> Accessories —> GNOME Do) and I set it to auto-start (located in its Preferences dialog, which is where you will also find its plugins).

I believe by default you call up Gnome-Do by using cltr-alt-space.  I have a Microsoft keyboard and so set mine to super-space (Windows-space).  You can choose something you like and which is convenient for you.

Have fun with this.  You’ll wonder how you ever got by without it.  And you will sincerely miss it when you are working on other operating systems.

Thanks to this post for the repository information.

  • Share/Bookmark

Stitch Some AVI’s Together

Thursday, January 21st, 2010

So you have that video of your cat doing that thing and that other video of your brother getting startled by the can of joke peanuts, and now you’re thinking “I’m such a wicked director I’m going to edit these films together and put them on the Interwebz.”  Ok.  That sounds important.

In Ubuntu there is a little utility called avimerge which (wait for it) merges avi files.

avimerge -c -o [WhatYouWantItCalled].avi -i [a].avi [b].avi

I know; you’re thinking “dude, that looks like something you type into the terminal window; how am I supposed to do this?”.  Fear not, little tomato.  You just want to replace the stuff in the square brackets with your stuff.  A and B are the two files you are wanting to merge and WhatYouWantItCalled is, well, I think you can manage that one.  Yours might look like this:

avimerge -c -o ScorseseMe.avi -i CuteKitty.avi BroJumps.avi

If your file names have spaces you’ll have to tell the shell (the terminal) how to interpret them:

avimerge -c -o Scorsese\ Me.avi -i Cute\ Kitty.avi Bro\ Jumps.avi

Could it be any easier?

Have fun with that.

  • Share/Bookmark

Returning Encryption to the Latest Ubuntu

Tuesday, September 1st, 2009

Older versions of Ubuntu included a space for each user, encrypted by default and decrypted as that user logged in, under the home area within the folder hierarchy.  The most recent version of Ubuntu (9.04) does not include this feature out of the box.

I rather like this implementation.  Each user has a secure folder-space which is continually encrypted and protected from access by even other local users (though administrators would still have the power to access the user’s account by changing the password and then logging in as that user).  Its simplicity is where this shines.

Essentially, for those unfamiliar, under your Home directory there will be a folder called Private.  That folder and its contents are stored in an encrypted format (using a special file system) and are only decrypted as that user logs into the machine.  Simple and effective, I was rather surprised to see it removed from the latest release.

As fortune would have it this feature is very easy to re-implement for anyone using the newest release of Ubuntu.  It’s merely two lines of code into a terminal (Applications —> Accessories —> Terminal):

  • sudo aptitude install ecryptfs-utils
  • ecryptfs-setup-private

(Thanks to this page at Ubuntu for the information.)

Happy hunting.

  • Share/Bookmark

My Pidgin Ain’t Yodelling Today

Thursday, June 25th, 2009

Ah, the sounds of Spring…

Well, yeah, it’s the middle of summer but never mind that.  I have been having difficulties with my Yahoo connections.  I don’t use their bulky, rancid chat client.  No, I use a multi-protocol chat client.  My preferred client is Trillian but it doesn’t run perfectly on Wine (a Windows emulator I use in Ubuntu), so sometimes I bite the bullet and run Pidgin.

Pidgin is an open-source option for the multi-protocol chat clients.  Allow me to explain that for the uninitiated in the audience.  Pidgin is a program that allows one to interact within many chat venues—like Yahoo! and Windows Live and AIM—without having to run the proprietary software generously foisted on us by those behemoths.  (Pidgin also publishes its source code for all to enjoy.)

Of course those behemoths would prefer each of should use their chat client, adore the ads they place before us, and sacrifice our first borns on the alters of their corporate ledgers. But I digress.

These companies sometimes make changes to the manners in which their clients interact with their servers.  Standard operations for them.  Plays occasional havoc for the developers of applications like Trillian and Pidgin (and Adium).

Anyway, my Pidgin hasn’t been able to consistently connect to Yahoo for some time now.  After the usual research I found a couple of articles which finalized the problem (here and here).  Basically, Yahoo has changed its authentication method and Pidgin hasn’t caught up quite yet.

I went ahead and installed the beta version of Trillian Astra (their newest client, currently in beta) on my Ubuntu machine using Wine, but there are problems with the visual displays within those Trillian windows (specifically the contact list) which make it effectively unusable.

Hopefully the folks at Pidgin will be able to get this sorted out soon.  Alternatively, the folks at Wine might get the issues with Astra sorted out too.

  • Share/Bookmark

Slipped Clutch; Blew Transmission

Wednesday, April 1st, 2009

Haha!  Oh, how I love breaking things.  It’s a how-to for fixing them.

I didn’t like the fact that I had a drive without a name (officially it was named “disk” and when it was mounted it appeared as “160 GB Disk” or some such).  I wanted to give it a name.

I opened GParted, unmounted the drive, and renamed it:

  1. System —> Administration —> Partition Editor
  2. You will be asked to enter your password
  3. Select the drive from the drop-down at the right of the button bar within the GParted
  4. Be sure you have selected the correct drive or you can really screw things up
  5. Right-click on the partition/drive in question (below the button bar) and choose Unmount
  6. Again, right-click on the partition/drive in question (below the button bar) and this time choose Label
  7. Name the drive whatever you want
  8. Close GParted

This worked wonders.  However, it breaks anything formerly linked to objects on that drive/partition.  This should come as no surprise.  It may come as a bit of a shock that you’ll have to open the hood to fix a couple of these.

I decided the easiest way to remount the drive was to merely reboot.  You may be able to choose the new drive by its new name from your Places menu, but it probably won’t hurt anything to go ahead and reboot as I did.

Now, I use Transmission for BitTorrents.  My BT download folder was located on that newly renamed drive.  When I subsequently opened Transmission it was a little lost, understandably.  So I told Transmission where the download folder was now located.

It basically ignored me.  I mean, in all the places one would care to look Transmission said it was going to use the new location, but when I opened the log file (Help —> Message Log) it was throwing errors which related to the old location (specifically to it not being found).

A little research told me that this information was kept in a file:

  • /home/[username]/.config/transmission/settings.json

I opened that file in a text editor (choose any you’d like) and changed all occurances of the former path to the new path.  Yours might look something like this:

  • OLD: “\/media\/disk\/DownloadFolder”
  • NEW: “\/media\/TorrentDrive\/DownloadFolder”

Sounds basic enough, yes?

Well, it will cause a new kind of havoc.  This is the correct solution, but before you do that (or like me after you’ve done that a few times) you will want to do one other thing:

  1. Copy your current torrent files by right-clicking on /home/[username]/.config/transmission/torrents
  2. Paste a copy of this folder some place safe—I chose my desktop
  3. Remove all torrents from Transmission by right-clicking each or all of them and choosing “Remove
  4. Close Transmission
  5. The Important Step: Now go back and perform the editing steps to change the path as mentioned above
  6. Open Transmission
  7. Some of your torrents may reload themselves, but toss all of the torrent files from the copy we made in step 2 into Transmission (drag and drop works nicely)—the duplicates will not be reloaded
  8. I manually told Transmission to Start and Verify Local Data, but it will likely do both all on its own

Hope you find this time-saving.

  • Share/Bookmark

Dell Joins (One of) My Movement(s)

Monday, March 9th, 2009

It’s hard to believe that I have two concurrent movements under my wings, but what can I say?  I started Luxagraphia years ago and have even written a manifesto.  More recently I began advocating Linux for Anybody and encouraged others to join along.

Dell has, unbeknownst to me, joined along.  Maybe it’s just ego, but I would have liked an e-mail or a phone call, just a little “hey, we thought you should know” but oh, well.

Dell has been selling a tiny laptop among a line of small laptops (so called netbooks) all of which come with the option of being outfitted by the manufacturer with Ubuntu 8.04—a line of laptops starting at about $250.  They are branded as Inspirons carrying the model signatures Mini 9 (8.5 inch display), Mini 10 (10 inch), and Mini 12 (12 inch).  (The 10 and 12 start about $300.)

You can read an interesting article (with a great comment thread) here.  The claim by Dell is that these Ubuntu installed netbooks are accounting for fully one-third of their total netbook sales in the US.  (The Mini 10 and Mini 12 are too new to be included in these statistics, and Dell is currently only offering Ubuntu as an option to their US market.)

As they say: a walk will give us a run.  Thanks, Dell.

Happy hunting, you crazy squirrels.

  • Share/Bookmark

Ubuntu Sends a Print-Job to WindowsLand

Friday, February 27th, 2009

Another of the more basic computing needs is the ability to print to a shared printer.  Now if you are running all Ubuntu systems, that’s certainly a boon for you.  But what happens if you have that old, clunky Windows box you are using as a sort of private server for your music hard drive and your printer?  You will want to set your Ubuntu machine up to print through the Windows shared printer, that’s what.

I’m going to assume you have shared your Windows printer.  You will need some information from that machine, so have it handy (see my article concerning remotely accessing a Windows machine here).

Open your Ubuntu printers dialog:

  • System (menu) —> Administration —> Printing

Now prepare a new printer:

  • New —> Printer

On the New Server dialog under Select Connection choose Windows Printer via SAMBA.  On the left the SAMBA area will appear.  In the “smb://” text field I was successful by entering serverIP/printerShareName (for instance “192.168.1.1/HPPrinter”).  It ought to work also using serverName/printerShareName.  (You can find the share name for your printer on the Sharing tab of the Properties dialog for the printer in question on your Windows machine.)

NOTE: Do not use spaces in your share names; it can only cause trouble.

Neither the “Browse” nor the “Verify” buttons worked for me.  You, I suspect, may safely ignore them.  Instead, once you have entered the information for the server and printer share, click on the “Forward” button.

Now we get to an area that may be more familiar feeling.  Under “Select printer from database” find your specific brand under “Makes” (mine was an HP).  Then click the “Forward” button.

Now locate your specific model under “Model“.  Once you have done so a list of potential drivers will appear under “Drivers“.  Prefer the one listed as “(recommended)” (there ought to be one).

This is the last page of the New Printer dialog.  This is information largely for your benefit and not something Ubuntu or Windows needs to get along.  The Printer Name (short name) field should auto-fill.  You may leave it alone.  The (optional) Description field may be used to give the printer some name you like to call it (Old Mr. Crappy or Sweet Dumpster Laserjet or anything else that strikes your fancy).  The Location field is for if you want to say something like “The printer in the kitchen” or “Pass the printer on the left-hand side”.  Click the “Apply” button and you are ready to send a test page to the printer from your Ubuntu machine.

Happy hunting, you crazy campers.

Addendum:

Well, that worked for a few days and then, for reasons obscure to me, it stopped working. I had to go back and re-create the print queue on my Ubuntu machine this time using the printer port. So now my entry looks more like this:

smb://ServerName:Port#/PrinterShareName

So, either:

MyServer:usb001/HPPrinter

or:

192.168.1.1:usb001/HPPrinter

Ok, now you can have some happy hunting.

  • Share/Bookmark

Linux and the Visually Impared: the Sequel

Thursday, January 22nd, 2009

If you enjoyed learning how to transform a single application in Ubuntu into a nagative image of itself (read: reversing all the colors), then you’ll love to read about this newest accidental discovery of mine.

Read the original article here.

I have now discovered that you can make the entire Ubuntu system go negative by using the shortcut super-m (windows-m).

Apparently I mash my fingers all over the keyboard when I type.  Probably due to my frenetic nature.  No grace at all.  Really makes one wonder how I can create such fine and delicate pieces of art.

  • Share/Bookmark