Command-line backup methods
The following is a brief overview of standard Unix comman-line utilities used for data backup on Solaris systems. Most of the information below is also applicable to other unixoid systems.
Common backup/copy methods:
tar | gzip
Basic syntax for creating *.tar.gz archive is:tar cvf - . | gzip > target.tar.gz
Common tar options include:
-c: Create a tar file
-t: List the contents of a tar file
-x: Extract or restore a tar file
Create tar file of /etc/mail:cd /etc tar cvf mail.tar mail
Extract contents of mail.tar file to /backup/mail directory:cd /backup tar xvf mail.tar
Copy files from the current directory to tape:pax -w -f /dev/rmt/0
Show tape contents:pax -v -f /dev/rmt/0
dd is commonly used to copy disk slices and entire disks. Here’s an example that will copy disk c0t0d0 to the disk c0t1d0:dd if=/dev/rdsk/c0t0d0s2 of=/dev/rdsk/c0t1d0s2 bs=128
If you are looking to make a copy of the boot disk, check out this script.
ufsdump | ufsrestore
These two commands are used in concert to duplicate filesystems. Take a look at this script that uses ufsdump | ufsrestore to duplicate boot disks.
Copy /var and its contents to /var2:find /var -depth -print | cpio -pudm /var2
Copy directory and its contents to tape:ls -R | cpio -oVc > /dev/rmt/0
Copy tape backup back to directory:cpio -icvD < /dev/rmt/0
Copy directories and files contained in the “list” to tape:cpio -ov list > /dev/rmt/0
Restore data from tape while preserving timestamps:cpio -icvum < /dev/rmt/0
Read contents of the tape:cpio -ict < /dev/rmt/0
This example will copy the /export/home filesystem from disk c0t0d0 to disk c0t0d1volcopy -F ufs /export/home /dev/rdsk/c0t0d0s3 - /dev/rdsk/c0t0d1s3 -