LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-01-2008, 01:30 AM   #1
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 69

Rep: Reputation: 24
Translating Backup Media Capacity into Blocks


[solved]
I need help understanding how to calculate available media storage space in blocks for various removable media.

I have a script I wrote a few years ago for making file system backups using dump and partimage. When I originally wrote it, someone gave me a "magic" number, 614400, which translates into 600MB which was fine for low capacity cdroms. The line of code that does the dump work (in a loop) is:

/sbin/dump 0uMBzf 614400 /mnt/portable/${target[$i]} /dev/${filesys[$i]}

It writes a segmented dump in chunks that will fit on individual cdroms.

I looked up dump again and option B lets you specify the chunk size in 1024 byte blocks, but 614400 * 1024 doesn't equal 600MB (unless maybe it's a power of ten thing).

Also, I know that when I write to any media, some of the space is used for overhead like directory structures.

Now, I need to update the script for two different media types: Regular cdroms which supposedly hold 700MB and dvd+r's that hold 4.7GB.

If I just divide the bytes by 1024, that won't take into account overhead and I'm not sure whether the specs are measured in x * 1000 or x * 1024.

So, how do I calculate the new chunk sizes for these or other media types?

Thanks,

Joe

Last edited by josephj; 07-13-2009 at 05:01 PM. Reason: Solved
 
Old 12-02-2008, 11:38 AM   #2
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,348

Rep: Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105
I would simply determine what is an appropriate "chunk size" that will easily fit on the smallest media that you need to deal with: the CD.

Larger-capacity media such as DVDs can then simply store "more than one of these chunks." (For that matter, CDs can do the same thing.)

This strategy has the compelling advantage that it will continue to work even as media-sizes continue to expand. "A media of a particular size 'x' will hold 'y' chunks, with some amount of wasted space." These media are so cheap that you just don't need to worry about squeezing just-a-little more out of each one. Build a solution that you can "just build once." Maybe you already have that solution...

Last edited by sundialsvcs; 12-02-2008 at 11:39 AM.
 
Old 12-03-2008, 10:23 PM   #3
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 69

Original Poster
Rep: Reputation: 24
Need specifics

That's good in principle, but I'm not going to put just 600MB on a DVD and I still don't know exactly how many 600MB's would fit on a DVD.

I just need to be able to calculate *usable* media size in bytes (after overhead) and then divide that by 1024. And, that's what I still don't know how to do.

Joe
 
Old 07-13-2009, 05:38 PM   #4
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 69

Original Poster
Rep: Reputation: 24
Solved!

This one took me forever to figure out, but it's pretty simple in the end.

Media manufacturers list capacities in MB and GB.
These units have been redefined in recent years to be 1000^2 and 1000^3. They used to be 1024^2 and 1024^3. These are now called MiB and GiB respectively.

Linux still does things in 1024 byte (1 KiB) blocks, so you have to convert between the two. The units command will do the math for you.

Below is a code sample from one of my bash scripts that sets the media size in blocks based on the media type I have set in a variable. The actual sizes are the result of division and then integer truncation along with a little wiggle room, so the real media is slightly larger.

Since these values (in my scripts) will be passed to dump or partimage, they are further divided so that no backup chunk will be greater than 2GiB which makes mkisofs happy when creating an image to burn to media. (I put 2 chunks on a DVD and 4 chunks on a DVD/DL.)

Joe
Code:
## Set media sizes - adjust if your media capacities differ

## mkisofs refuses to write a file bigger than 4GiB
## and one of the standards (somewhere) says individual files
## Can't be larger than 2GiB
## So split them by 2 and 4 for DVD and DVDDL
## But now they changed KB,MB, GB to x 1000 (decimal)
## and KiB, Mib, Gib are x 1024 (binary)
## God bless marketing ....
## And, the blinking capacity specs are in GB, MB
## So those have to be translated back into KiB
## 8.5GB = 8,500,000,000B
## divided by 1024
## then divided by 4

case "${MEDIA}" in
DVD)
  SIZE="2294921";    ## 1/2 Size
  HSIZE="4.7GB";     ## Human-readable size
;;
DVDDL)
  SIZE="2075195";    ## 1/4 Size
  HSIZE="8.5GB";
;;
CD)
  SIZE="683593";     ## Full Size
  HSIZE="700MB";
;;
*)
  echo "ERROR ${USAGE}"
  exit 1;
;;
esac

Last edited by josephj; 07-13-2009 at 05:40 PM. Reason: typo
 
  


Reply

Tags
backup, media


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPIO Backup End of Media rma1 Other *NIX 3 10-30-2008 11:19 AM
Choosing hardware/media for backup? jantman Linux - Hardware 7 10-18-2006 11:05 PM
Full backup with bad blocks jrdioko Linux - Software 2 04-02-2006 06:15 PM
Labeling to Backup Media pakuson Linux - General 1 03-01-2005 07:06 PM
Backup Media jcb_dreamvsat Linux - Hardware 1 09-24-2003 04:36 AM


All times are GMT -5. The time now is 02:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration