Archiving Files


      This section describes how to store the files in your directory to either 3.5" diskettes or DDS's (Digital Data Storage) and then how to retrieve them from one of these sources.

      To archive your files from one of the College of Engineering Workstation machines, you will need either:

  1. 3.5" HD diskettes (1.44MB capacity)
    You can purchase 3.5" HD diskettes from almost any bookstore or computer store. Be sure to get HD floppies, not DD floppies.
  2. 4mm DDS (60m = 1.0GB capacity, 90m = 2.4GB capacity)

Note: Do not use standard DAT's (Digital Audio Tapes). 4mm DDS's can be purchased at T.I.S. Bookstore. Other bookstores may also carry these tapes.

Where to
Archive Files
      You can archive files to 3.5" HD diskettes using any Sun SPARCstation. All of these have 3.5" drives available.

You can archive files using 4mm DDS's at most lab sites.


Archiving onto a DOS Disk

Sun
Workstations



Formatting a DOS diskette

To format a DOS diskette on the Suns, insert the floppy into the drive and type:

fdformat -d

Note: If you wish only to format the disk and not copy any files to it, you may include the -e flag on the command given above to eject the diskette when the format is complete. If you did not use the -e flag and still want to eject it (and you have not mounted it with volcheck), then type eject to eject the disk.

Mounting a DOS diskette

      The first thing that must be done before you can access files on a DOS diskette is that you must mount the diskette as a filesystem. To do this, insert the diskette into the drive and type:

volcheck

Assuming the disk is in DOS format, you should get the message:

Floppy mounted on /floppy.
Don't forget to use eject floppy when done.

Note: This command MUST be executed before any operation can be performed on the floppy. In addition, after you have used this command, you MUST use the eject floppy command to unmount and eject the floppy in order to ensure that you r data is safe.
Failure to use
eject floppy can result in lost data!

Copying files from UNIX to a DOS diskette

To copy a binary file from the workstation to the floppy, simply use the regular Unix cp command, as in:

cp myfile /floppy/myfile

      This copies the file myfile in the current directory to the DOS file mydile. Note that you must preface the DOS filename with /floppy/ - this is because the DOS disk is mounted at that point in the filesystem.

To copy an ASCII file from the workstation to the floppy, you need to use a special command:

unix2dos -ascii myfile.txt /floppy/myfile.txt

This converts the Unix formatted file to DOS format and copies it to the floppy.

For further information type man unix2dos at any unix prompt.

Copying files from a DOS diskette to UNIX

To copy a binary file from the floppy to the workstation, simply use the regular Unix cp command, as in:

cp /floppy/myfile ./myfile

      This copies the file myfile from the DOS diskette (note the /floppy that precedes the name - this is because the DOS disk is mounted at that point in the filesystem) to the current directory.

To copy an ASCII file from the floppy to the workstation, you need to use the special command:

dos2unix -ascii /floppy/myfile.txt ./myfile

This converts the DOS-formatted file to Unix format and copies it from the floppy to the current directory.

For further information type man dos2unix at any unix prompt.

Deleting files from a DOS diskette

To delete a file from a DOS diskette, simply use the Unix rm command:

rm /floppy/myfile

This command would remove the file myfile from the diskette.

Listing files and directories on a DOS diskette

To get a directory listing of a DOS diskette, simply use the ls command, as in:

ls /floppy

This would list all files in the top-level directory of the DOS diskette. See the man page for the ls command for more options.

Unmounting a DOS diskette

When you are done working with the DOS diskette, you must unmount and eject it. To do this, use the command:

eject floppy

This will flush all remaining information to the disk, unmount it, and eject it.

Note: NEVER ATTEMPT TO PRY THE DISKETTE OUT OF THE DRIVE. ALWAYS USE THE eject floppy COMMAND TO EJECT IT!!!

Removing a DOS diskette from a workstation

Sparc20
      After entering the command eject floppy, the disk will automatically eject out.

Ultra10
      After entering the command eject floppy, press the eject button on the front of the workstation. This will eject the disk out of the drive. You may then remove you disk from workstation.



Archiving
Using "tar"

      The tar (Tape ARchiver) utility is a standard prmgram on almost all Unix operating systems. All College of Engineering Workstations have this utility. With tar, it is possible to archive not only individual files, but also entire directory trees. Because the tar format is so standard, it is almost guaranteed that you will be able to use the data you have archived using it at any site in the world.

      tar can also be used to create archives on a variety of different output devices, such as floppy disk, tape, and even another file. The section below describes the general usage of the tar utility, and the sections following it describe in more detail the various output options available on EWS machines.

Creating an archive

The general format for creating a tar archive is:

tar cvf archivename filespec

where:c indicates that we are creating an archive
v indicates that tar should list the names of the files as it adds them to the archive
f indicates that the next item on the line is the archive name
archivename is the filename of the archive we wish to create
filespec is a specification for one or more files/directories to archive

      The filespec parameter can be one or more files or directories you wish to archive. If you specify a file (you can include wildcard characters), then the matching file(s) is (are) copied to the archive. If you specify a directory, then all files an d subdirectories of that directory are archived. Hence, it is possible to archive an entire directory tree.

For example, to copy the files data1.txt, a.out, and program.c to an archive file called program.tar, you would type:

tar cvf program.tar data1.txt a.out program.c

      This command would create a file in the current directory called program.tar which itself would contain the three listed files.

Suppose you wished to archive a subdirectory of your home directory called text to the 3.5" disk drive on an IBM RS/6000. Here's what you would type:

tar cvf /dev/fdO ~/text

      Note that since Unix devices are represented as files, we can tar to them just as we tar to a regular file.

      Here's another example: Suppose you want to archive all files in your directory with the extension .c to an archive file called programs.tar. Here you would type:

tar cvf programs.tar *.c

Viewing the contents of an archive

      There may be times when you will want to see what is stored in a tar archive without actually restoring the files from that archive. The general form for doing this is:

tar tvf archivename [filespec]

where:t indicates that tar should list the entries in the archive
v indicates that tar should give more information about each entry (for example: the size, protection, owner, etc.)
f indicates that the next item on the line is the archive name
archivename is the filename of the archive you wish to list
filespec is an optional file/directory specifier which you can include if you are looking for a particular file/directory

For example, suppose you would like to find out what files are archived in the file utils.tar in the current directory. You would type:

tar tvf utils.tar

      Perhaps you archived your files on a 3.5" floppy disk several months back and now can't remember what you put there. Here is what you would type to list these files back (IBM RS/6000):

tar tvf /dev/fdO

Suppose you are looking for the file resume.tex in the archive file texstuff.tar. Here's how you could do it:

tar tvf texstuff.tar resume.tex

Restoring files from a "tar" archive

The general format for restoring files from a tar archive is:

tar xvf archivename [filespec]

where:x indicates that tar should extract files from the archive
v indicates that tar should list each file as it is being restored
f indicates that the next item on the line is the archive name
archivename is the filename of the archive you wish to restore from
filespec is an optional file/directory specifier which you can include if you only wish to restore a particular file/directory from the archive (otherwise the entire archive is restored)

      Please note that when you archive files using a directory specifier, as opposed to just simple filenames, tar records the directory along with the filename in the archive. Hence, when you go to restore, tar will put the files in the same dir ectory they were restored from, even if it has to create it.

      Usually, it is a good idea to first list the contents of the archive before you restore it in order to make sure that you are restoring it in the proper directory.

      For example, suppose you wish to restore all the files you archived onto a 3.5" disk on one of the IBM machines. The files were archived using the command tar cvf /dev/fdO papers, where papers was a subdirectory of the directory you were in when you typed the above command. To restore these files back into a subdirectory of the current directory called papers type:

tar xvf /dev/fdO

To restore the files static.h from the archive file classwork.tar you would type:

tar xvf classwork.tar static.h

To restore only the usr/include directory (including files and subdirectories) from the archive file /tmp/compiler.tar use:

tar xvf /tmp/compiler.tar usr/include

For more information about the tar command, see the man pages on one of the EWS systems.


Archiving
using "tar"
with 3.5"
disks
(RS/6000
and SUN
systems

      Although it is possible, as outlined in an earlier section, to store your files on 3.5" diskettes in MS-DOS format, you may find it more desirable to store them in tar format, especially if you never intend to use them on an MS-DOS system.

      Before you can use a 3.5" diskette with the tar command, you must format it. Be sure you have a 3.5" HD floppy diskette inserted in the drive. If you are using a SUN workstation type fdformat. When the formatting is complete, your disk is ready to be used with tar. The archive name you should use for SUN workstations whenaccessing the floppy drive is:

/dev/fdo

      You may be wondering how you can put more than one archive on a floppy disk. Well, this is not easy. Typically, you will only put one tar archive per floppy disk, as it is not possible to divide up the floppy into multiple archives. tar does provide means for extending an existing archive, so if you wish to use that, see the man pages.


Archiving
using 4mm

      4mm DDS (Digital Data Storage) are usable on all platforms. They are capable of storing a very large amount of data - up to 2 gigabytes. Although there is nothing wrong with using them to store the contents of your directory, it is unlikely that you will ever need the full capacity of one of these tapes.

      Just like 3.5" diskettes, these tapes provide some difficulty when trying to use them with multiple tar archives. Fortunately, there is a way to store more than one archive on these tapes!

Rewinding and non-rewinding devices

      Almost any system that has a tape drive attached has more than one device name for accessing that drive. The first is usually a rewinding device, and the other is a non-rewinding device.

      A rewinding device always rewinds the tape after you are done accessing it. For example if one were to store an archive using tar to a rewinding device, the tape would automatically rewind as soon as the tar command had completed.

      A non-rewinding device does not automatically rewind the tape after you are done accessing it. Rather, the tape is left at the position you last accessed.

      If you ever hope to store more than one archive on a tape, you will need to be familiar with and use the non-rewinding device when you access the tape drive.

On Sun platforms, the names are:

/dev/rmt/0  rewinding
/dev/rmt/0nnon-rewinding

On HP platforms, the names are:

/dev/rmt/0  rewinding
/dev/rmt/0mnnon-rewinding

On IBM platforms, the names are:

/dev/rmt0  rewinding
/dev/rmt0.1non-rewinding

Positioning the tape

      In order to maintain multiple archives on a single tape, you need to know how to move the tape backwards and forwards among the archives. To do this, we will use the mt command. The general format for this command is:

mt -f /dev/rmt/0 command

or

mt -t /dev/rmt/0 command

where command if one of the following:

rewind   rewinds the tape
fsf moves the tape forward n number of archives
bfs moves the tape backward n number of archives

For example, to skip over the first archive on the tape in order to be able to read the second, use:

mt -f /dev/rmt/0 fsf 1

To rewind the tape, use:

mt -f /dev/rmt/0 rewind

Extended examples of using multilple archives on DDS

      This example will cover writing several archives to tape, then moving the tape back and forth, then accessing them.

      Let's assume that the user has three directories called bin, text, and source that he wants to archive separately.

      First, he inserts the tape into the drive (this is pretty obvious!). The tape should be rewound, but just to make sure, he types:

mt -f /dev/rmt/0 rewind

Now he is ready to archive his three directories. Here we go:

tar cvf /dev/rmt/0 bin
tar cvf /dev/rmt/0 text
tar cvf /dev/rmt/0 source

      Since the non-rewinding device was chosen each time, each archive was written immediately after the one preceding it. Before he leaves, he rewinds the tape (you should ALWAYS do this).

mt -f /dev/rmt/0 rewind

      Several days later our user, due to some careless use of the rm -r command, needs to restore the entire text directory from his archive tape. Furthermore, he decides that he had better also archive his lib directory, just in case he should accidentally delete anything.

      First, he inserts the tape into the drive. This time we know it is rewound, so there is no need to rewind it. The first action he will do is restore the text directory, which is the second archive on the tape. Since the tape is rewound, it is ready to read the first archive, which is the bin directory. Hence, we need to skip over this archive to reach the second. Here's what he types:

mt -f /dev/rmt/0 fsf 1

This instructs the computer to skip over one archive. Now the tape is positioned to read the second archive.

tar xvf /dev/rmt/0

      This extracts the second archive from the tape, leaving the tape positioned at the beginning of the third archive. Now our user wants to store his lib directory on the tape, so he needs to space over the third archive to the end of the tape. Again, we skip over one file:

mt -f /dev/rmt/0 fsf 1

Now we are at the end of the tape, so he can archive the lib directory using:

tar cvf /dev/rmt/0 lib

Now the tape contains four archives and it is positioned at the end-of-tape.

      Our user now does some file work, and makes another mistake! He has just wiped out his source directory! Since he has not removed the tape from the drive, he decides to immediately restore it.

      Remember, the tape is currently at the end of the fourth archive. The source archive is the third archive on the tape. Hence, to position the tape at its beginning, he must move the tape back two archives - one to skip back over the fourth, and one more to skip over the third.

mt -f /dev/rmt/0 bsf 2

Now the tape is positioned at the beginning of the third archive. To restore it, he types:

tar xvf /dev/rmt/0

Deciding that he has done enough damage for the day, our user thinks he should quit, so he rewinds the tape.

mt -f /dev/rmt/0 rewind

Pushing the button on the front of the tape drive releases the tape.

Using gzip
and gunzip

To save space on your account, you may want to compress, or "zip-up" some of your files. gzip and gunzip make this a relatively easy task.

Simply type "gzip" and the file name to compress a file:

gzip file_name

And simply type "gunzip" and the file name to decompress the file into usable form:

gunzip file_name

For more information and a list of tags to these commands see the UNIX manual page for gzip and gunzip:

man gzip


Back to the table of contents