About nixCraft

Topics

Solaris tar command to backup data on tape device

Posted by Vivek Gite [Last updated: March 11, 2008]

Tar name come from Tape ARchiver. It is both a file format and the name of the program used to handle such file. Tar archive files have names ending in ".tar". If an archive is compressed, the compression program adds its own suffix as usual, resulting in filename endings like ".tar.Z", ".tar.gz", and ".tar.bz2". Tar doesn't require any particular filename suffix in order to recognize a file as an archive. Tar was originally created for backups on magnetic tape, but it can be used to create tar files anywhere on a filesystem. Archives that have been created with tar are commonly referred to as tarballs.

Create a new set of backup

To create a Tar file, use tar command as follows:
# tar cvf /dev/rmt/X file1 file2 dir1 dir2 file2 …
Where

For example, backup /export/home/vivek/sprj directory to tape device /dev/rmt/0, enter
# tar cvf /dev/rmt/0 /export/home/vivek/sprj/
Remember c option should only use to create new set of backup.

Appending or backing up more files to same tape using tar

tar provides r option for appending files to tape. For example to backup /data2/tprj/alpha1 files to same tape i.e. appending files to a first tape device:
# tar rvf /dev/rmt/0 /data2/tprj/alpha1/*
Where

List files on a tape using tar command

To display file listing of a first tape use tar as follows:
# tar tvf /dev/rmt/0
To listing the Contents of a Stored Directory (for example wwwroot directory):
# tar tvf /dev/rmt/0 wwwroot
Where

Retrieve / restore tape backup taken with tar

1) Use tar command as follows to retrieve tape drive backup to current directory:
(a) Change directory where you would like to restore files:
# cd /path/to/restore
# pwd

(b) Now, do a restore from tape:
# tar xvf /dev/rmt/0

To specify target directory use –C option

Restore everything to /data2 directory:
# tar xvf /dev/rmt/0 –C /data2
To retrieve directory or file use tar as follows:
# tar xvf /dev/rmt/0 tprj
Note that Solaris tar command is little different from GNU tar, if you wish to use gnu tar with Solaris use command gtar. Gnu tar accepts same command line options plus bunch of additional options :)

See Sun Solaris tar man page and tapes ~ creates /dev entries for tape drives attached to the system.

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Karthik Says:

    how would i create a tar file so it does not copy the tar directory structure. For example:
    tar -cf temp.tar /usr/local/myfile.txt

    I dont want to have the directory structure in the tar file. I dont want “/usr/local/” in the tar file. I just want to file to be stored in the tar file.

  2. Karthik Says:

    how would i create a tar file so it does not copy the tar directory structure. For example:
    tar -cf temp.tar /usr/local/myfile.txt

    I dont want to have the directory structure in the tar file. I dont want “/usr/local/” in the tar file. I just want to file to be stored in the tar file.

  3. Anonymous Says:

    Hmm…

    Try format

    tar –cvf mytar.t.ar.gz file1 file2

    By default it includes directory name however you can pass the following x or fF arguments to tar

    tar –cvf –x dir1, dir2 mytar.t.ar.gz .

    x Exclude. Use the exclude-filename argument as a
    file containing a list of named files (or
    directories) to be excluded from the tarfile when using the key letters c, x, or t.

    F - With one F argument, tar will exclude all direc tories named SCCS from the tarfile. With two argu ments, FF , tar will exclude all directories named SCCS

  4. vinothkumar Says:

    hi suppose i took a tape backup entire harddisk.now but my hard disk crashed . i want to recover this partition slice table whether it’s possible or not.plz help to sort it out

  5. vivek Says:

    Just restore data from tape to hard disk. Did you used tar or dump command?

  6. tamer Says:

    hi…
    when i do this
    tar xvf /dev/rmt/0 tamer

    where is tamer is a dir in the tape .

    befor i didthis command im allredy in th path where i whant this dir to besor in

    but whene i check i cannot find the data

    hellp me pls

  7. Mohan Says:

    Is there a way to check how much used space / freespace in the tape

  8. madhu Says:

    How do you only restore a specific file type onto a specific folder ?
    Also, is there a way to restore files depending on date ?

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.