Sun Solaris UNIX Backup Commands
Sun Solaris UNIX comes with various commands and utilities to make a backup and recovery job:
a) tar command
b) cpio command
Important Directories and Files to Backup
1. /export/home or /home (Home directory)
2. /etc
3. User mailboes
4. Cron files (/var)
5. MySQL and Oracle databases etc
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 the following command (backup /home/, /data/ and, /etc/file1 files to home.back.tar file) :
# tar cvf home-back.tar /home /data /etc/file1
To create a new tape backup use:
Backup /home and /data directory to /dev/rmt/0 tape device, enter:
# tar cvf /dev/rmt/0 /home /data
Task: Display the contents of a tar file/tape
Pass tvf option to a 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:
# cd /
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.
References:
Read Solaris tar, tape and cpio man pages, by typing following command:
man tar
man tape
man cpio
Solaris tar command to backup data on tape device
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
c – Create a new files on tape/archive
v – verbose i.e. show list of files while backing up
f – tape device name or file
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
r – append files to the end of an archive/tape
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
t – list the contents of an archive/tape
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.
Sun Solaris UNIX Backup Commands
Reviewed by Positive thinking
on
4:24 PM
Rating:
No comments