From Wiki-UX.info

Wiki-UX / Backup Commands / How to use tar
Jump to: navigation, search

How to use tar

Abstract

This article is a quick reference on the usage of the tar command on the HP-UX Operating Environment. A review of the current HP-UX Reference Mainpages is highly advisable for additional examples, syntax description and relevant warnings or notifications.

Contents


Name

tar - tape file archiver

Synopsis

tar [-]key [arg]...  [file | -C directory]...

Writing an archive

# cd /
 
# tar -cvf /var/tmp/archive.tar ./tmp
tar: /tmp/.AgentSockets/A is not a file. Not dumped
a /tmp/.kc.trace 1 blocks
a /tmp/rpcbind.file 8 blocks
a /tmp/ACL.log 0 blocks
a /tmp/X11_newfonts.log 2 blocks
a /tmp/core 1840 blocks
a /tmp/install.vars 3 blocks
a /tmp/ipv6agt.crashlog 0 blocks
a /tmp/portmap.file 2 blocks
a /tmp/primary.dd 16 blocks
a /tmp/man003006 74 blocks
a /tmp/man010501 29 blocks
a /tmp/man023686 12 blocks
a /tmp/mirror.dd 16 blocks
a /tmp/ntlc.3375 19 blocks
a /tmp/llbdbase.dat 0 blocks
a /tmp/.s.PGSQL.10864.lock 1 blocks
a /tmp/sd_ipd_acl.2705 1 blocks
a /tmp/swlist 0 blocks
a /tmp/kern-verify.17801 8 blocks
tar: /tmp/.s.PGSQL.10864 is not a file. Not dumped
a /tmp/5991-5974.cdimage 34472 blocks
a /tmp/reports 3 blocks
a /tmp/void.psf 1 blocks
a /tmp/root.mail 332 blocks
a /tmp/man021907 8 blocks
a /tmp/man006071 15 blocks
a /tmp/dhcpvalidate 1 blocks
a /tmp/vxportal 0 blocks
a /tmp/nbp.efi 0 blocks
a /tmp/1111io_listener.log 0 blocks
a /tmp/vg01.mapfile 1 blocks
a /tmp/.s.PGSQL.50006.lock 1 blocks
tar: /tmp/.s.PGSQL.50006 is not a file. Not dumped
a /tmp/kern-verify.3285 8 blocks
a /tmp/test 347 blocks

Listing the content of an archive

# tar -tvf /var/tmp/archive.tar
rwxrwxrwt   0/0      0 Jan  1 17:51 2008 ./tmp/
rwx------   0/0      0 Dec 20 15:51 2007 ./tmp/.AgentSockets/
rwxr-xr-x   0/0      0 Oct 10 14:16 2007 ./tmp/lost+found/
rw-rw-rw-   0/3    229 Dec 27 12:19 2007 ./tmp/.kc.trace
rw-------   0/0   3616 Dec 20 15:45 2007 ./tmp/rpcbind.file
rw-r--r--   0/3      0 Oct 12 15:09 2007 ./tmp/ACL.log
rw-r--r--   0/3    808 Oct 10 19:07 2007 ./tmp/X11_newfonts.log
rw-------   0/3 941856 Oct 24 16:52 2007 ./tmp/core
r--r--r--   0/3   1292 Oct 10 14:18 2007 ./tmp/install.vars
rw-r--r--   0/0      0 Dec 20 15:51 2007 ./tmp/ipv6agt.crashlog
rw-------   0/0    744 Dec 20 15:45 2007 ./tmp/portmap.file
rw-rw-rw-   0/3   8192 Nov 13 16:20 2007 ./tmp/primary.dd
rw-------   0/3  37498 Oct 11 12:54 2007 ./tmp/man003006
rw-------   0/3  14795 Oct 16 16:32 2007 ./tmp/man010501
rw-------   0/3   6041 Oct 18 17:41 2007 ./tmp/man023686
rw-rw-rw-   0/3   8192 Nov 13 16:20 2007 ./tmp/mirror.dd
rw-r--r--   0/3   9711 Oct 10 21:54 2007 ./tmp/ntlc.3375
r--r--r--   0/0      0 Dec 20 15:51 2007 ./tmp/llbdbase.dat
rw------- 102/20     26 Jan  1 17:47 2008 ./tmp/.s.PGSQL.10864.lock
rw-r--r--   0/3     53 Oct 10 21:50 2007 ./tmp/sd_ipd_acl.2705
rw-r--r--   0/3      0 Oct 10 17:38 2007 ./tmp/swlist
rw-r--r--   0/3   3899 Oct 29 07:51 2007 ./tmp/kern-verify.17801
rw-rw-rw-   0/3 17649664 Nov 14 10:21 2007 ./tmp/5991-5974.cdimage
rw-rw-rw-   0/3   1025 Nov 22 11:23 2007 ./tmp/reports
rw-rw-rw-   0/3     34 Nov 22 11:44 2007 ./tmp/void.psf
rw-rw-rw-   0/3 169677 Nov 27 11:36 2007 ./tmp/root.mail
rw-------   0/3   3685 Nov 28 15:14 2007 ./tmp/man021907
rw-------   0/3   7352 Dec  7 14:53 2007 ./tmp/man006071
rw-r--r--   0/3    226 Dec  7 17:02 2007 ./tmp/dhcpvalidate
rw-r--r--   0/3      0 Oct 10 17:10 2007 ./tmp/vxportal
rw-r--r--   0/3      0 Dec  7 17:13 2007 ./tmp/nbp.efi
rw-------   0/3      0 Dec 14 17:02 2007 ./tmp/1111io_listener.log
rwxr-xr-x   0/0      0 Dec 10 14:08 2007 ./tmp/ign_configure/
rw-rw-rw-   0/3     30 Dec 18 13:24 2007 ./tmp/vg01.mapfile
rw------- 109/20     27 Jan  1 17:51 2008 ./tmp/.s.PGSQL.50006.lock
rw-r--r--   0/3   4065 Dec 27 12:19 2007 /.tmp/kern-verify.3285
rw-rw-rw-   0/3 177572 Dec 28 10:18 2007 ./tmp/test

Extracting an archive

# tar -xf /var/tmp/archive.tar

Copying Files

# mkdir /var/tmp/test
# cd /
 
# tar -cf - ./tmp | ( cd /var/tmp/test; tar xvf - )
tar: ./tmp/.AgentSockets/A is not a file. Not dumped
x ./tmp/.kc.trace, 229 bytes, 1 tape blocks
x ./tmp/rpcbind.file, 3616 bytes, 8 tape blocks
x ./tmp/ACL.log, 0 bytes, 0 tape blocks
x ./tmp/X11_newfonts.log, 808 bytes, 2 tape blocks
x ./tmp/core, 941856 bytes, 1840 tape blocks
x ./tmp/install.vars, 1292 bytes, 3 tape blocks
x ./tmp/ipv6agt.crashlog, 0 bytes, 0 tape blocks
x ./tmp/portmap.file, 744 bytes, 2 tape blocks
x ./tmp/primary.dd, 8192 bytes, 16 tape blocks
x ./tmp/man003006, 37498 bytes, 74 tape blocks
x ./tmp/man010501, 14795 bytes, 29 tape blocks
x ./tmp/man023686, 6041 bytes, 12 tape blocks
x ./tmp/mirror.dd, 8192 bytes, 16 tape blocks
x ./tmp/ntlc.3375, 9711 bytes, 19 tape blocks
x ./tmp/llbdbase.dat, 0 bytes, 0 tape blocks
tar: ./tmp/.s.PGSQL.10864 is not a file. Not dumped
x ./tmp/.s.PGSQL.10864.lock, 26 bytes, 1 tape blocks
x ./tmp/sd_ipd_acl.2705, 53 bytes, 1 tape blocks
x ./tmp/swlist, 0 bytes, 0 tape blocks
x ./tmp/kern-verify.17801, 3899 bytes, 8 tape blocks
x ./tmp/5991-5974.cdimage, 17649664 bytes, 34472 tape blocks
x ./tmp/reports, 1025 bytes, 3 tape blocks
x ./tmp/void.psf, 34 bytes, 1 tape blocks
x ./tmp/root.mail, 169677 bytes, 332 tape blocks
x ./tmp/man021907, 3685 bytes, 8 tape blocks
x ./tmp/man006071, 7352 bytes, 15 tape blocks
x ./tmp/dhcpvalidate, 226 bytes, 1 tape blocks
x ./tmp/vxportal, 0 bytes, 0 blocks, character device
x ./tmp/nbp.efi, 0 bytes, 0 tape blocks
x ./tmp/1111io_listener.log, 0 bytes, 0 tape blocks
tar: ./tmp/.s.PGSQL.50006 is not a file. Not dumped
x ./tmp/vg01.mapfile, 30 bytes, 1 tape blocks
x ./tmp/.s.PGSQL.50006.lock, 27 bytes, 1 tape blocks
x ./tmp/kern-verify.3285, 4065 bytes, 8 tape blocks
x ./tmp/test, 177572 bytes, 347 tape blocks

Extracting archives to relative directories

Tar command allows to restore its contents to a relative directory only if the archive was created using relative paths (all above examples). If that is the case, it is as simple as moving to the desired directory and extract the archive. If the archive was created with absolute paths, you may use the pax command trailing path replacement feature to acomplish this task or chroot to extract the archive using tar inside a jail.

Using tar to backup splitted /dev/vg00

This is a very common backup procedure used to have a snapshot backup of /dev/vg00 or any other volume group using the LVM "lvsplit / lvmerge" commands. This method is valid for all version of HP-UX 11i. It uses a fbackup graph file with relative paths to select the required filesystems.

Graph File

# cat /mnt/backup/split_vg00.graph
i ./lvol1b
i ./lvol3b
i ./lvol4b
i ./lvol5b
i ./lvol6b
i ./lvol7b
i ./lvol8b
i ./lvol9b
#/usr/bin/sh
# History: This program was ported on 2008.01.01 from the fbackup to pax conversion
# modeled on a Virginia Militar Institute script. The script ommits /dev/vg00/lvol2
# since this is the swap logical volume.
 
LOGFILE=/mnt/backup/logs/`date +"%0y%m%d.%R"`
GRAPH=/mnt/backup/split_vg00.graph
STOREMED=/mnt/backup/latest.tar
 
# STEP 1. Splitting the mirrors
 
for COUNT in 1 3 4 5 6 7 8 9
do
   /usr/sbin/lvsplit /dev/vg00/lvol$COUNT
done
 
# STEP 2. Check and mount the volumes
 
/sbin/fsck -F hfs /dev/vg00/rlvol1b
/sbin/mkdir /lvol1b
/sbin/mount -F hfs -o ro /dev/vg00/lvol1b /lvol1b
 
for COUNT in 3 4 5 6 7 8 9
do
   /sbin/fsck -F vxfs /dev/vg00/rlvol$COUNTb
   /sbin/mkdir /lvol$COUNTb
   /usr/sbin/mount -F vxfs -o ro /dev/vg00/lvol$COUNTb /lvol$COUNTb
done
 
# STEP 3. Make backup to tape using tar
# Tar do not use graph files. Usage awk code to convert fbackup graph file to pax compatible command line
 
cd /
/sbin/tar -cvf -f $STOREMED 2> $LOGFILE `cat $GRAPH| awk '{if ($1 == "i") printf "%s ", $2}'`
 
# STEP 4. Unmount and remege the mirrors
 
for COUNT in 1 3 4 5 6 7 8 9 # lvol2 ommited
do
   fuser -k /dev/vg00/lvol$COUNTb # Ensure there are not running processes on the logical volume
   /sbin/umount /lvol$COUNTb
   /sbin/lvmerge /dev/vg00/lvol$COUNTb /dev/vg00/lvol$COUNT
   /usr/bin/rmdir /lvol$COUNTb
done
# History: This program was ported on 2008.01.01 from the fbackup to pax conversion
# modeled on a Virginia Militar Institute script. The script recovers the content
# of the backup in a temporary directory /tmp/tapetest with enough space to contain
# the full volume group.
 
 
GRAPH=/mnt/backup/split_vg00.graph
STOREMED=/mnt/backup/latest.tar
 
# Step 1. Clean the directory to start fresh
 
if [ -d /tmp/tapetest ]
   then rm -rf /tmp/tapetest/* ]
fi
 
if [ ! -d /tmp/tapetest ]
   then mkdir /tmp/tapetest ]
fi
 
# Step 2. Extract the archive.
cd /tmp/tapetest
/sbin/tar -xvf $STOREMED

Reference

  • HP-UX Reference - tar(1) - HP-UX 11i Version 3: February 2007

Authors

Editor

This page was last modified on 20 April 2011, at 19:49. This page has been accessed 2,519 times.