Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a script to backup a client's server and write the pertinent data to a cd/dvd recorder. On the way, I need to test the state of the device. I have looked at Linux::CDROM, Linux::Mounts, Filesys::Type, Sys:Filesystem, and lastly, Device::Cdio. None of seem to fit the bill and worse yet, Device::Cdio will not 'Build'. (But that's another question.) Objective:
  1. Verify the device exists,
  2. a disc is in the device,
  3. the disc is available,
  4. the disc been formatted (i.e. use growisofs -Z or growisofs -M),
  5. is there sufficient space on the disc, and finally,
  6. did the write to the disc succeed?
Any assist is greatly appreciated...

Replies are listed 'Best First'.
Re: testing state of cd/dvd
by Joost (Canon) on May 08, 2007 at 20:32 UTC
    I'd probably do something like this:
    1. check for /dev/dvd, /dev/cdrom, /dev/cdrw, /dev/dvdrw
    2. mount the device to some directory and see what happens. on my system mounting without a disc reports "mount: No medium found". if it succeeds you have a formatted disk, another error probably means the disc isn't formatted or formatted using some unusable filesystem.
    3. see 2.
    4. see 2.
    5. skip this, growisofs will check if there's enough space.
    6. check the output/return code of growisofs.

    update: also please don't repeat post. it takes some time for posts to be approved and they won't be visible in the right section until they are (and repeat posts will be removed, but this takes up time and attention from the monks that might be better spend somewhere else). New posts are immediately visible in Newest Nodes.

Re: testing state of cd/dvd
by shmem (Chancellor) on May 08, 2007 at 22:21 UTC
    For 2, 3 and 4, with a lot of handwaving, I'd suggest writing some XS code using the ioclts defined in /usr/include/linux/cdrom.h. I've used that with success to replace the braindead autorun program on Fedora Core 4. If I had the code at hand, I would have posted it - /msg me if you are interested.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: testing state of cd/dvd
by quester (Vicar) on May 09, 2007 at 06:07 UTC
    If you are already paranoid about your backups, you will want to be able to check that the data really made it to the dvd (and wasn't subsequently overwritten.) The old standard way goes something like this...

    • Write a backup archive (tar for example) to disk
    • Copy the archive to the dvd
    • Remount the dvd (so you can read the file that was written)
    • Compare the disk copy byte by byte to the dvd copy

    A more elaborate scheme that lets you test the stored backups later,

    • Write the archive to disk
    • Calculate a checksum of the archive with, say, md5sum or sha1sum
    • Write the archive and the checksum to dvd
    • Remount the dvd
    • Calculate the checksum of the cd/dvd copy and compare to the previously calculated checksum

    The temporary disk space to hold a copy of the backup may be an issue. It is possible to use "tee" to send one copy of the archive to the cd/dvd writing process and one to the checksum program. (You will need to create a named pipe to be the output of the "tee" process and the input of the checksum.)

    If your clients are anything like the ones I've had in the past, you will also want to write the date, the time, the name of the system, and the userid running the backup, plus any other interesting information available. That way you can check that the disks were labeled and stored correctly. (What, the disk labelled "Tuesday, Metropolis" wasn't made on a Tuesday or in Metropolis? Again?)

    Finally, if you aren't paranoid about your backups yet, just wait until you start testing them!

Re: testing state of cd/dvd
by Anonymous Monk on May 09, 2007 at 10:47 UTC