Background
Recently I was putting together a script to build an archive of all the various files that a project was comprised from. One of the final tasks was to burn the entire lot of files to a CD or DVD, so I took the opportunity to figure out how to do this from the command line.
Doing things this way might seem a little unnecessary, but by doing it this way, the task of creating an ISO file could be fully automated and handed off to our continuous integration (CI) server, Jenkins, going forward.
I needed to archive most of the following directory structure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
% pwd /home/saml/CC_v1.0 % tree -L 1 -CpD . |-- [drwxrwxr-x Nov 28 23:43] apps |-- [-rw-rw-r-- Nov 28 23:43] backup_log.txt |-- [-rw-rw-r-- Nov 28 23:42] backup.sh |-- [drwxrwxr-x Nov 28 23:39] bin |-- [drwxrwxr-x Nov 28 23:43] code |-- [drwxrwxr-x Nov 28 23:39] docs |-- [-rw-rw-r-- Nov 28 23:42] make_cd.sh |-- [-rw-rw-r-- Nov 28 23:43] md5sum.txt `-- [drwxrwxr-x Nov 28 23:43] tmpdir 5 directories, 4 files |
Of the above, I wanted everything except backup_log.txt & tmpdir included in the archive CD/DVD.
Solution
Building the ISO file
All the work can be done using the command line tool mkisofs. The following command can roll the entire directory structure above, excluding any files or directories that I don’t want to include, into a single ISO file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# current directory % pwd /home/saml/CC_v1.0 # command to make the ISO file % mkisofs -o ~/backup.iso -r -J -hide-rr-moved -V "Backup `date +"%d %B %Y"`" \ -x tmpdir -x backup_log.txt -graft-points "CC_v1.0/=." : -input-charset not specified, using utf-8 (detected in locale settings) 24.40% done, estimate finish Tue Nov 29 00:02:28 2011 48.80% done, estimate finish Tue Nov 29 00:02:28 2011 73.12% done, estimate finish Tue Nov 29 00:02:28 2011 97.52% done, estimate finish Tue Nov 29 00:02:28 2011 Total translation table size: 0 Total rockridge attributes bytes: 1558 Total directory bytes: 10240 Path table size(bytes): 74 Max brk space used 1b000 20523 extents written (40 MB) |
Here’s a breakdown of the above switches to mkisofs:
| -o ~/backup.iso | name of .iso file to store everything in |
| -r | sets permissions and ownership to sane defaults (see below) |
| -J | generate Joliet directory records in addition to regular ISO9660 filenames |
| -hide-rr-moved | rename the directory RR_MOVED to .rr_moved |
| -V “Backup `date +”%d %B %Y”`” | sets the volume name to “Backup <date>” (for e.g. 29 November 2011) |
| -x tmpdir | exclude directory tmpdir |
| -x backup_log.txt | exclude file backup_log.txt |
| -graft-points “CC_v1.0/=.” | puts files in . directory into CC_v1.0/ directory on CD or DVD |
And here’s the resulting ISO file, backup.iso:
1 2 |
% ls -l ~/backup.iso -rw-rw-r-- 1 saml saml 42031104 Nov 29 00:02 /home/saml/backup.iso |
To confirm the contents of the ISO file you can mount it like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# mount ISO file % mount -o loop ~/backup.iso /mnt # display contents of backup.iso file % tree -L 1 -CpD /mnt/CC_v1.0 /mnt/CC_v1.0 |-- [dr-xr-xr-x Nov 29 0:02] apps |-- [-r-xr-xr-x Nov 29 0:01] backup.sh |-- [dr-xr-xr-x Nov 28 23:39] bin |-- [dr-xr-xr-x Nov 28 23:43] code |-- [dr-xr-xr-x Nov 28 23:39] docs |-- [-r-xr-xr-x Nov 29 0:01] make_cd.sh `-- [-r--r--r-- Nov 28 23:43] md5sum.txt 4 directories, 3 files |
NOTE: Notice that the top level directory is CC_v1.0 thanks to the -graft-points switch and the -x switches to mkisofs did in fact exclude the file backup_log.txt and the directory tmpdir.
Burning ISO File
To burn the resulting ISO file you can use one of the following commands:
1 2 3 4 5 |
# DVD % growisofs -Z /dev/dvd=backup.iso # CD % cdrecord -v -pad speed=1 dev=0,0,0 backup.iso |
References
links
- CD & DVD Writing from the Linux Command Line – andrews-corner.org
- Linux Tutorial: Burning a CD or DVD - yolinux.com
local copies
- CD & DVD Writing from the Linux Command Line – andrews-corner.org
- Linux Tutorial: Burning a CD or DVD - yolinux.com
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.
LATEST NEWS
