TechDirectory UNIX System Security and Performance Tuning
Backups are one of the major tasks that a Systems Administrator do. Here are few hints for the beginners. You will have to replace the tape device name with the one you are using. See some scripts here.
If you are in hurry and want to use ufsdump and ufsrestore, see example below.
Using cpio to create a file archive on a tape device: # find . -print |cpio -ocBv /dev/rmt0 Using cpio to list the entries in a file archive on a tape device: # cpio -itcvB < /dev/rmt0 Using cpio to retrieve a file from a tape device: # cpio -icvdBum file.name < /dev/rmt0 You can also use cpio to copy directory structure. For example copy Directory structure from current path to /export/home/tariq # find . -print|cpio -pmdv /export/home/tariq
Using tar to create a file archive on a tape device: # tar -cvf /dev/rmt0 file.name or # tar -cvf /dev/rmt0 . or for multiple directory hierarchies # tar -crvf my.tar `find /tmp/junk -type f` `find /var/tmp -type f` using tar to list the entries in a file archive on a tape device: # tar -tvf /dev/rmt0 using tar to retrieve a file from a tape device: # tar -xvf /dev/rmt0 file.name Copy files from current directory to directory /to/dst/dir/, keeping ownership and rights #tar cvf - . | (cd /to/dst/dir/; tar xvf -) There is more than one way to skin these cats, this being no comprehensive look at these utilities.
dump ( in solaris and others called ufsdump )is said to be the most reliable way to backup the whole filesystem. restore is the utility for restoring data from a dump. We can use restore interactively to restore certain files or directories. To make a dump of root filesystem on tape device /dev/nrsa0. Note that this is a non-rewinding device. See example below. # /sbin/dump -0ua -f /dev/nrsa0 / or for solaris # /usr/sbin/ufsdump 0f /dev/rmt/0cn / To interactively restore a backup # /sbin/restore -i -f /dev/nrsa0 or for solaris # /usr/sbin/ufsrestore -xvf /dev/rmt/0cn Every thing will be restored in current directory.
mt (magnetic tape manipulating program) is a very useful command specialy if you are using dump and restore combination. Following are some useful options of mt command. # mt status Print status information about the tape unit. # mt rewind Rewind the tape. # mt erase Erase the tape. # mt retension Re-tension the tape (one full wind forth and back. # mt fsf 1 Forward space count by one file. One can be any number. -f option can be used with mt to specify the different device. For solaris /dev/rmt/0 is the default device. # mt -f /dev/rmt/1n fsf 3
If you are backing up three filesystems /, /var and /usr on a solaris Box to a tape device: # /usr/sbin/ufsdump 0uf /dev/rmt/0n / # /usr/sbin/ufsdump 0uf /dev/rmt/0n /var # /usr/sbin/ufsdump 0uf /dev/rmt/0n /usr This will take three file spaces, one for each filesystem. Filesystem / will be on file count 0 of tape and /var will be on file count 1 and /usr will be on file space 2. Option 0 specify full backup,u will update the dump record in /etc/dumpdates file and f to specify file or device. You can use following command sequence to restore /var filesystem. # mt status This will show you the current status of tape. After the backup on a non-rewinding device, tape will show file number 2 # mt rewind This will rewind the tape to beginning. # mt status Tape will be on file count 0 # mt fsf 1 Tape will move to file count number 1 where /var is dumped. # /usr/sbin/ufsrestore -xvf /dev/rmt/0n /var will be restored in current. This will over-write the current contents. Use /dev/rmt/0cn for compression, no rewind device.
Commands for remote tape backup
It is often neccesary to backup into a remote machine's tape drive. Here are the commands that can be used to achieve this. Execute this command on the machine you want to backup. $ tar cvf - $DIRNAME | rsh $SYS dd of=$TAPEDEV Substitute $DIRNAME with the directory to backup, $SYS with the machine name with the tape drive, $TAPEDEV with the tape device. Note: You must be able to rlogin into the remote machine without a password. To do this add the name of your local machine with your user name in the .rhost file in your home directory on the remote machine. To retrieve the backed up info... rsh $REM dd if=$TAPEDEV | tar xvf - |
#!/bin/sh tar -cvf my.tar $(for i in `cat list` do echo $i done) exit This script is backing up to tape using dump command. Logging date and all the messages to a log file. #!/bin/sh # echo "$DATE"backup.log filenumber=`/usr/bin/mt stat|/usr/bin/grep "File Number"|/usr/bin/awk '{print $3}'` echo "Backing up / to tape location: $filenumber"backup.log /sbin/dump -0ua -f /dev/nrsa0 / &2backup.log if [ $? -eq 0 ];then echo "/ backup successful"$HOME/log/backup.log fi
Copy files ( even complete filesystem) from remote to local system
Note: You must be able to rlogin into the remote machine without a password. To do this add the name of your local machine with your user name in the .rhost file in your home directory on the remote machine. #!/bin/sh # # Copies files from Remote System to the local current directory # name=`basename $0` if [ $# -ne 2 ];then echo "Usage: $name <remote-system> <dir-to-copy>" exit fi system=$1 dir_to_cp=$2 rsh $system "cd $dir_to_cp; find . -print|cpio -ocB"|dd ibs=5k obs=5k|cpio -iducmvB |
Home UNIX System Security and Performance Tuning
html hit counter code |