Home Domain Tools How To Photo Albums Unix Stuff Support
Jumpstart Server
Mounting CD in Solaris
Solaris 10 BIND 9.2.4
Solaris 10 Zones
Space from /swap
Luxadm Commands
cfgadm Commands
Changing IP Address
SCSI Unconfigure
Backing Up the OS
Restoring the OS
Solaris IPMP
CPIO Commands
Unix Howto
FIND & DELETE FILES
Windows Howto
IPMP
Enabling tftpd
Unix HowTO
 
 

Sun Solaris UNIX comes with various commands and utilities to make a backup and recovery job:

a) tar command

b) cpio command


Task: Use tar command to backup /data and /home directory


Usually /dev/rmt/0 is tape device name.

To create a new tar file you can type:

# tar cvf home-back.tar /home /data /etc/file1

To create a new tape backup use:

# tar cvf /dev/rmt/0 /home /data /etc/file1


Task: Display the contents of a tar file/tape


Pass tvf option to tar command:

# tar tvf home-back.tar

OR

# tar tvf /dev/rmt/0


Task: Restore files from tar file / tape


To extract the tar file to the current directory type:

# tar xvf home-back.tar

# tar xvf /dev/rmt/0

Understanding tar command options:


  • x : Extract tar file
  • v : Verbose
  • f : filename : Use to specify file name / tape device name
  • t : List tar file contents

Task: Backup files with cpio command


You can also use cpio command, which copies files into and out of a cpio archive. The cpio archive may span multiple volumes. The -i, -o, and -p options select the action to be performed. For example copy all *.c files to tape device or file called prog.cpio:

# ls *.c | cpio -oVc > /dev/rmt/0

OR

# ls *.c | cpio -oVc > prog.cpio


Task: Restore file using cpio


To copy from tape back to a directory, use the command as follows:

# cpio -icvD < /dev/rmt/0

OR

# cpio -icvum < /dev/rmt/0


Task: View the contents of cpio


Use the command as follows:

# cpio -ict < /dev/rmt/0

Understanding cpio command options:


  • i : (copy in) Reads an archive from the standard input and conditionally extracts the files contained in it and places them into the current directory tree.
  • c : Reads or writes header information in ASCII character form for portability.
  • t : Prints a table of contents of the input.
  • o : (copy out) Reads a list of file path names from the standard input and copies those files to the standard output in the form of a cpio archive.
  • v : Verbose
  • u : Use for an unconditional copy; old files will not replace newer versions.
  • m ; Retains previous file modification time.
  • d: Create as many directories as needed.

Further readings:


  • Read Solaris tar, tape and cpio man pages, by typing following command:

man tar

man tape

man cpio


GNU cpio is a tool for creating and extracting archives, or copying files from one place to another. It handles a number of cpio formats as well as reading and writing tar files. cpio command works just like tar, only better.


As I said earlier, cpio works like tar but it can read input from the ”find“ command. This is nifty feature. For example you can find out all *.c files and backup with cpio command.


# find / -name "*.c" | cpio -o --format=tar > c-file.backup.tar

# find / -iname "*.pl" | cpio -o -H tar > perl-files.tarYou can also specify file name using -F option:

# find / -iname "*.pl" | cpio -o -H tar -F perl-files.tarWhere,


  • -o: Create archive
  • -F: Archive filename to use instead of standard input or output. To use a tape drive on another machine as the archive.
  • -H format: Specify file format to use.
  • -i: Restore archive

You can extract archive with the following command:

# cpio -i -F perl-files.tarYou can list file inside archive i.e.


list contents of the cpio file with following command:

# cpio -it -F perl-files.tar


You can write archive of /home to tape (drive /dev/nst0), type the following command:


# find /home | cpio -o -H tar -F /dev/nst0Restore backup using following command:

# cpio -i -F /dev/nst0Backup /home dir, to remote system tape drive:

# find /home | cpio -o -H tar -F user@backup.nixcraft.in:/dev/nst0 --rsh-command=/usr/bin/ssh