|
Softpanorama |
||||||
| Contents | Bulletin | Latest | Last year | Top visited | Scriptorama | |
| News | Recommended Links | Recommended Books | Backup media and utilities | Recovering file systems | Flash archives | |
| tar | dd | cpio | pax | ufsdump | ufsrestore | fssnap |
| volcopy | compress /uncomress |
gzip | zip | bzip2 | rar | Tips |
"Native" backup and recovery in Solaris show signs of 30 years of Unix development. Frankly speaking it is potpourri of almost a dozen partially incompatible utilities plus equal amount of GNU clones if you install them (gzip is installed by default). Many utilities duplicate each other and none is very competitive with the best Windows backup and recovery tools (as exemplified by rar and Ghost to name a few; there are close of Ghost for linux).
Most native Solaris tools support ACLs, most
GNU tools don't (although in some combinations like Solaris tar + GNU
gzip (tar.gz or tgz archives) can support them. Solaris' approach
to handling ACLs in cpio and tar archives is using two files of the same name. The
first file held the ACL info, and the second file was the actual file. If
you weren't running on Solaris, the second file would simply overwrite the first
one, so the format was, for all intents and purposes, 100% backward compatible.
Here
is a "slightly skeptical" characterization of some:
ls | cpio -o > /dev/mt0
Solaris version supports ACLs. The cpio archive may span multiple volumes.
The -i, -o, and -p options select the action to be performed.
This specialized archiver is rarely seen any more, having been largely eliminated
by tar/gzip. It's capabilities
are emulated in pax (see below)
ufsrestore
has an interactive mode which can be used to select individual files and directories
for restoration. It also supports an option to read the table of contents from
the archive file instead of the backup media.
Elizabeth D. Zwicky torture tested all the backup programs discussed here. She
created file systems containing a large variety of unusual conditions (and some
not so unusual ones) and tested each program by doing a backup and restore of
those file systems. The peculiarities included: files with holes, files with
holes and a block of nulls, files with funny characters in their names, She
presented the results at LISA V in Oct. 1991. See
torture-testing Backup and Archive Programs. dump behave as one of the best
backup program in her tests.
For example, you can use the volcopy command to transfer the contents of the old /export/home file system to the new /export/home file system on a separate disk that was recently added to your system.
# volcopy -F ufs /export/home /dev/rdsk/c0t0d0s3 - /dev/rdsk/c0t0d1s3 -
There is a very old paper by John Pezzano from Hewlett-Packard comparing three backup utilities:
|
Feature |
tar |
cpio |
dump |
|---|---|---|---|
|
Simplicity of invocation |
Very simple (tar c files) |
Needs find to specify filenames |
Simple—few options |
|
Recovery from I/O errors |
None—write your own utility |
Resync option on HP-UX will cause some data loss |
Automatically skips over bad section |
|
Back up special files |
Later revisions |
Yes |
Yes |
|
Multivolume backup |
Later revisions |
Yes |
Yes |
|
Back up across network |
Using rsh only |
Using rsh only |
Yes |
|
Append files to backup |
Yes (tar -r) |
No |
No |
|
Multiple independent backups on single tape |
Yes |
Yes |
Yes |
|
Ease of listing files on the volume |
Difficult—must search entire backup (tar -t) |
Difficult—must search entire backup (cpio -it) |
Simple—index at front (restore -t) |
|
Ease and speed of finding a particular file |
Difficult—no wildcards, must search entire volume |
Moderate—wildcards, must search entire volume |
Interactive—very easy with commands like cd, ls |
|
Incremental backup |
No |
Must use find to locate new/modified files |
Incremental of whole filesystem only, multiple levels |
|
List files as they are being backed up |
tar cvf 2>logfile |
cpio -v 2>logfile |
Only after backup with restore -t >logfile (dump can show % complete, though) |
|
Back up based on other criteria |
No |
find can use multiple criteria |
No |
|
Restore absolute pathnames to relative location |
Only by using chroot |
Limited with cpio -I |
Always relative to current working directory |
|
Interactive decision on restore |
Yes or no possible with tar -w |
Can specify new path or name on each file |
Specify individual files in interactive mode |
|
Compatibility |
Multiple platform |
Multiple platform with ASCII header, not always portable |
Readable between some platforms, but cannot be relied on |
|
Primary usefulness |
Individual user backup, transfer files between filesystems |
System backup, transfer files between filesystems |
System backup |
|
Volume efficiency |
Medium, usually limited to 10 K block size |
Medium, usually only 5 K block size, but can specify larger size on some OSes |
High, can usually specify up to maximum block size of device |
|
Wildcards on restore |
No |
Yes |
Only in interactive mode |
|
Simplicity of selecting files for backup from numerous directories |
Low—must specify each independent directory, subdirectories included |
Medium—find options |
None—will back up one and only one filesystem |
|
Specifying directory on restore get files in that directory |
Yes |
No—must use path/* |
Yes |
|
Stop reading tape after a restored file is found |
No |
No |
Will stop reading tape as soon as last file is found |
|
Track deleted files |
No |
No |
If you restore with -r, files deleted before last incremental dump will be deleted |
|
Filesystem efficiency |
Better |
Worst (files get a stat from both find and cpio) |
Best |
|
Limit on path length(tests done with Solaris native utilities 7/99) |
155 characters. Complains "prefix is greater than 155 characters." gtar has slight workaround |
255 characters. Doesn't complain. Just truncates pathname to 255 chars |
1056 characters. |
|
Likelihood that file exists in TOC but not in archive |
Low |
Low |
Medium (since TOC is made first) |
|
|
|
|||
|
|
||||
| Bulletin | Latest | Past week | Past month | |
Identifying the tape device
dmesg | grep st
Checking the status of the tape drive
mt -f /dev/rmt/0 status
Backup file system using ufsdump
ufsdump 0cvf /dev/rmt/0 /dev/rdsk/c0t0d0s0
or
ufsdump 0cvf /dev/rmt/0 /usr
To restore a dump with ufsrestore
ufsrestore rvf /dev/rmt/0
ufsrestore in interactive mode allowing selection of individual files and directories using add , ls , cd , pwd and extract commands .
ufsrestore -i /dev/rmt/0
Making a copy of a disk slice using ufsdump
ufsdump 0f - /dev/rdsk/c0t0d0s7 |(cd /mnt/backup ;ufsrestore xf -)
Backing up all files in a directory including subdirectories to a tape device (/dev/rmt/0),
tar cvf /dev/rmt/0 *
Viewing a tar backup on a tape
tar tvf /dev/rmt/0
Extracting tar backup from the tape
tar xvf /dev/rmt/0
(Restoration will go to present directory or original backup path depending on relative or absolute path names used for backup )
Backup using cpio
find . -depth -print | cpio -ovcB > /dev/rmt/0
Viewing cpio files on a tape
cpio -ivtB < /dev/rmt/0
Restoring a cpio backup
cpio -ivcB < /dev/rmt/0
Compressing a file
compress -v file_name
gzip filename
To uncompress a file
uncompress file_name.Z
or
gunzip filename
The Best of All Worlds
The solution is to combine these two products. Through quite a bit of work, you can use Disksuite to mirror the root disks, but carve out a small partition and make that the rootdg. The effort is worth while, as this solution meets all four of the criteria:
- It (almost always) automatically recovers from the failure of one of the mirror pair of disks. Note, however, that the disk failure must be detected and corrected in order to avoid having the other disk fail, taking down the system! Seriously, this has occurred at sites that lack sufficient attention.
- To upgrade a system in this configuration, DiskSuite must be removed, but VXVM can stay installed, unaffected by the upgrade.
- Performance is the same as Disksuite monitoring alone -- that is, quite good.
- Disksuite can be used for what it is good at -- management of a few disks, and VXVM can do its job of managing the rest.
If the system disks (/, /usr, /var file systems) are on RAID and for example the raid controller (or fiber cable) fails, you have a problem, unless the RAID is fully redundant. Also, cold mirroring is simpler, and software RAID can be difficult to recover when the system disk fails.
For some servers, I prefer to put system (and certain data) files on a "normal" disk and mirror to a second disk once or twice a week ("cold mirroring"). If the boot disk dies, we simply boot from the mirror disk. This solution is easier to understand, to recover from in a disaster scenario, and system disks can be more easily added/removed/changed.
In addition, files changed by accident can be recovered since the last mirror run, and deleted files can be recovered until the disk fills up and needs to be wiped clean. More details are provided below.
Each night the offline disk is mounted and synchronized with the primary disk. The script is called from the root cron nightly. It mounts the spare disk under /newroot, copies all file systems, installs a boot block and copies over a new vfstab. This creates a fully updated bootable spare disk. The results of the script are sent to the administrator via email (sample output is mirror_output.txt).
- Advantages:
- Cheap (disks are pretty cheap and evolving faster than tapes).
- Simple (no complex hardware or software).
- Easy to understand in a crisis (when RAID complexity can be unbearable).
- Cold mirrored disks are not written to at the same time as the masters: deleted files several days old can be recovered (e.g., after an attack or a mistake by system administrator or user).
- Disadvantages:
- Hot failover is not available, and a minimum downtime of, say, 15 minutes has to be acceptable.
- The backup disks have to cleaned now and again, as they can fill up.
- Read this document carefully before using the script!
Pax
POSIX 1003.1-2001 defines a backup utility called pax, and along with that utility, a revised archive format that is to a large degree backwards compatible with tar's archive format. This format is extensible and can contain vendor specific extensions. Additional information that is added to this format is stored in extended headers.
The Star tape archiver uses this backup format for Access Control Lists.
Star tape archiver
The Star tape archiver by Jörg Schilling, available at ftp://ftp.berlios.de/pub/star/, since version 1.4a07 supports backing up and restoring of POSIX Access Control Lists. For best results, it is recommended to use a recent star-1.5 version. Star is compatible with SUSv2 tar (UNIX-98 tar), understands the GNU tar archive extensions, and can generate pax archives.
Getting and building Star
Star snapshots are available at ftp://ftp.berlios.de/pub/star/alpha/.
Solaris always includes ACL support in the base OS since Solaris-2.5, but before building Star on Linux, you first need to install the ACL utilities. The ACL utilities in Linux include the ACL library, which Star depends on.
To build Star under Linux, unpack the Star archive, change into the star-1.5 directory, and invoke make. The Star package of course contains more detailed information.
Backing up and restoring with Star
Star supports all command line parameters defined for SUSv2 tar (UNIX-98 tar). There are some differences with GNU tar, for which mostly GNU tar is to blame. Archives can be created as follows. The H=exustar option tells star to create an extended pax archive. The Option -acl tells star to include ACLs in extended headers, for those files that have ACLs.
star H=exustar -acl -c path > archive.tarArchives can be restored as shown below.
star -acl -x < archive.tarThe archive format Star uses for Access Control Lists
Since no official backup format for POSIX access control lists has been defined, Star uses the vendor defined attributes SCHILY.acl.access and SCHILY.acl.default for storing the ACL and Default ACL of a file, respectively. The access control lists are stored in the short text form as defined in POSIX 1003.1e draft standard 17. To each named user ACL entry a fourth colon separated field field containing the user identifier (UID) of the associated user is appended. To each named group entry a fourth colon separated field containing the group identifier (GID) of the associated group is appended. (POSIX 1003.1e draft standard 17 allows to add fields to ACL entries.)This is an example of the format used (lines broken for readability, additional fields highlighted):
SCHILY.acl.access= user::rwx,user:lisa:r-x:502,group::r-x, \ group:toolies:rwx:102,mask::rwx,other::r-x SCHILY.acl.default= user::rwx,user:lisa:r-x:502,group::r-x, \ mask::r-x,other::r-xThe numerical user and group identifiers are essential when restoring a system completely from a backup, as initially the name-to-identifier mappings may not be available, and then file ownership restoration would not work.
As the archive format that is used for backing up access control lists is compatible with the pax archive format, archives created that way can be restored by star or a POSIX.1-2001 compliant pax. Note that programs other than star will ignore the ACL information.
A Solaris Backup Script How-To
This paper will focus on the backup script and will detail a flexible backup script that uses built-in Solaris software tools which create a reliable local backup ...
Internal pages updates by age: Latest : Past week : Past month : Past year
Restoring a Sun system using JumpStart technology
oreilly.com -- Online Catalog Essential System Administration, 3rd Edition Chapter 11: Backup and Restore (PDF)
Sys Admin Magazinev12, i11 More Truth about Tapes, Backups, and Restores
Sys Admin Magazinev12, i07 The Truth about Tapes, Backups, and Restores
Elizabeth D. Zwicky's backup test suite (mirror)
Protecting File Systems: A Survey of Backup Techniques (1998)
Welcome to the Free pax utilities site
freshmeat.net Project details for S tar by Jörg Schilling
Star is a very fast, POSIX-compliant tar archiver. It saves many files together into a single tape or disk archive, and can restore individual files from the archive. It includes command line interfaces for the "tar", "Sun-Tar", "cpio", "pax", and "gnutar" command-line syntax. It includes a FIFO for speed, a pattern matcher, multi-volume support, the ability to archive sparse files and ACLs, the ability to archive extended file flags, automatic archive format detection, automatic byte order recognition, automatic archive compression/decompression, remote archives, and special features that allow star to be used for full and incremental backups. It includes the only known platform independent "rmt" server program.
oreilly.com -- Online Catalog Essential System Administration, 3rd Edition Chapter 11: Backup and Restore (PDF)
The Solaris version of tar includes extra options. The -I option allows a list of files and directories that are backed up to be put into a text file. The -X option allows an exclusion file to be specified that lists the names of files and directories that should be skipped.
The Solaris version of mt supports an asf subcommand which moves the tape to the nth file. n being the number of the file.
Some useful tar options:
| It may be difficult to recover data from a corrupted gzipped tar archive. When archiving important files, make multiple backups. |
#!/bin/bash # Copying a directory tree using cpio. ARGS=2 E_BADARGS=65 if [ $# -ne "$ARGS" ] then echo "Usage: `basename $0` source destination" exit $E_BADARGS fi source=$1 destination=$2 find "$source" -depth | cpio -admvp "$destination" # Read the man page to decipher these cpio options. exit 0 |
#!/bin/bash
# de-rpm.sh: Unpack an 'rpm' archive
E_NO_ARGS=65
TEMPFILE=$$.cpio # Tempfile with "unique" name.
# $$ is process ID of script.
if [ -z "$1" ]
then
echo "Usage: `basename $0` filename"
exit $E_NO_ARGS
fi
rpm2cpio < $1 > $TEMPFILE # Converts rpm archive into cpio archive.
cpio --make-directories -F $TEMPFILE -i # Unpacks cpio archive.
rm -f $TEMPFILE # Deletes cpio archive.
exit 0
|
The zcat filter decompresses a gzipped file to stdout, as possible input to a pipe or redirection. This is, in effect, a cat command that works on compressed files (including files processed with the older compress utility). The zcat command is equivalent to gzip -dc.
![]() |
On some commercial UNIX systems, zcat is a synonym for uncompress -c, and will not work on gzipped files. |
See also Example 7-6.
![]() |
The znew command transforms compressed files into gzipped ones. |
![]() |
The output of sq may be piped to gzip for further compression. |
The -f option causes file to run in batch mode, to read from a designated file a list of filenames to analyze. The -z option, when used on a compressed target file, forces an attempt to analyze the uncompressed file type.
bash$ file test.tar.gz test.tar.gz: gzip compressed data, deflated, last modified: Sun Sep 16 13:34:51 2001, os: Unix bash file -z test.tar.gz test.tar.gz: GNU tar archive (gzip compressed data, deflated, last modified: Sun Sep 16 13:34:51 2001, os: Unix) |
#!/bin/bash
# strip-comment.sh: Strips out the comments (/* COMMENT */) in a C program.
E_NOARGS=65
E_ARGERROR=66
E_WRONG_FILE_TYPE=67
if [ $# -eq "$E_NOARGS" ]
then
echo "Usage: `basename $0` C-program-file" >&2 # Error message to stderr.
exit $E_ARGERROR
fi
# Test for correct file type.
type=`eval file $1 | awk '{ print $2, $3, $4, $5 }'`
# "file $1" echoes file type...
# then awk removes the first field of this, the filename...
# then the result is fed into the variable "type".
correct_type="ASCII C program text"
if [ "$type" != "$correct_type" ]
then
echo
echo "This script works on C program files only."
echo
exit $E_WRONG_FILE_TYPE
fi
# Rather cryptic sed script:
#--------
sed '
/^\/\*/d
/.*\/\*/d
' $1
#--------
# Easy to understand if you take several hours to learn sed fundamentals.
# Need to add one more line to the sed script to deal with
# case where line of code has a comment following it on same line.
# This is left as a non-trivial exercise for the reader.
# Also, the above code deletes lines with a "*/" or "/*",
# not a desirable result.
exit 0
# ----------------------------------------------------------------
# Code below this line will not execute because of 'exit 0' above.
# Stephane Chazelas suggests the following alternative:
usage() {
echo "Usage: `basename $0` C-program-file" >&2
exit 1
}
WEIRD=`echo -n -e '\377'` # or WEIRD=$'\377'
[[ $# -eq 1 ]] || usage
case `file "$1"` in
*"C program text"*) sed -e "s%/\*%${WEIRD}%g;s%\*/%${WEIRD}%g" "$1" \
| tr '\377\n' '\n\377' \
| sed -ne 'p;n' \
| tr -d '\n' | tr '\377' '\n';;
*) usage;;
esac
# This is still fooled by things like:
# printf("/*");
# or
# /* /* buggy embedded comment */
#
# To handle all special cases (comments in strings, comments in string
# where there is a \", \\" ...) the only way is to write a C parser
# (lex or yacc perhaps?).
exit 0
|
$bash which rm
/usr/bin/rm |
$bash whereis rm
rm: /bin/rm /usr/share/man/man1/rm.1.bz2 |
$bash whatis whatis
whatis (1) - search the whatis database for complete words |
#!/bin/bash # What are all those mysterious binaries in /usr/X11R6/bin? DIRECTORY="/usr/X11R6/bin" # Try also "/bin", "/usr/bin", "/usr/local/bin", etc. for file in $DIRECTORY/* do whatis `basename $file` # Echoes info about the binary. done exit 0 # You may wish to redirect output of this script, like so: # ./what.sh >>whatis.db # or view it a page at a time on stdout, # ./what.sh | less |
See also Example 10-3.
This is one of the GNU fileutils.
bash$ vdir total 10 -rw-r--r-- 1 bozo bozo 4034 Jul 18 22:04 data1.xrolo -rw-r--r-- 1 bozo bozo 4602 May 25 13:58 data1.xrolo.bak -rw-r--r-- 1 bozo bozo 877 Dec 17 2000 employment.xrolo bash ls -l total 10 -rw-r--r-- 1 bozo bozo 4034 Jul 18 22:04 data1.xrolo -rw-r--r-- 1 bozo bozo 4602 May 25 13:58 data1.xrolo.bak -rw-r--r-- 1 bozo bozo 877 Dec 17 2000 employment.xrolo |
This is one of the GNU fileutils.
![]() |
Using shred on a file may not prevent recovery of some or all of its contents using advanced forensic technology. |
$bash locate hickson
/usr/lib/xephem/catalogs/hickson.edb |
echo "Usage: `basename $0` arg1 arg2 ... argn" |
![]() |
basename and dirname can operate on any arbitrary string. The argument does not need to refer to an existing file, or even be a filename for that matter (see Example A-6). |
#!/bin/bash a=/home/bozo/daily-journal.txt echo "Basename of /home/bozo/daily-journal.txt = `basename $a`" echo "Dirname of /home/bozo/daily-journal.txt = `dirname $a`" echo echo "My own home is `basename ~/`." # Also works with just ~. echo "The home of my home is `dirname ~/`." # Also works with just ~. exit 0 |
#!/bin/bash
lines=35 # Allow 35 lines for the header (very generous).
for File in * # Test all the files in the current working directory...
do
search1=`head -$lines $File | grep begin | wc -w`
search2=`tail -$lines $File | grep end | wc -w`
# Uuencoded files have a "begin" near the beginning,
#+ and an "end" near the end.
if [ "$search1" -gt 0 ]
then
if [ "$search2" -gt 0 ]
then
echo "uudecoding - $File -"
uudecode $File
fi
fi
done
# Note that running this script upon itself fools it
#+ into thinking it is a uuencoded file,
#+ because it contains both "begin" and "end".
# Exercise:
# Modify this script to check for a newsgroup header.
exit 0
|
![]() |
The fold -s command may be useful (possibly in a pipe) to process long uudecoded text messages downloaded from Usenet newsgroups. |
The make command checks a
Makefile, a list of file dependencies and
operations to be carried out.
| [1] | This is a symmetric block cipher, used to encrypt files on a single system or local network, as opposed to the "public key" cipher class, of which pgp is a well-known example. |
Copyright © 1996-2012 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine. This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
Disclaimer:
Last updated: June 05, 2008