Unix Makinalarda Basit Yedekleme Komutları

Cpio ile:

Bulunduğunuz dizinin yedeğini eğer varsa tape sürücüsüne almak. (Solaris'lerde genelde /dev/rmt/0 olur)
 
# find . -print | cpio -ovc > /dev/rmt0

Bulunduğunuz dizinin yedeğini bir dosya içine almak.

# find . -print | cpio -ovc > nuri.cpio

Aldığınız yedeği görüntülemek.

   # cpio -itB < /dev/rmt0
   # cpio -itB < nuri.cpio

Aldığınız yedekten geriye dönmek.

   # cpio -icvdBum file.name < /dev/rmt0
   # cpio -icvdBum file.name < nuri.cpio

Örnek: Diyelim ki /home/nuri dizinin yedeğini cpio ile aldınız.

# find . -print |cpio -ovc > nuri.cpio

Görüntülediniz.

# cpio -itB < nuri.cpio

/home/nuri bir alt dizininde şu dosyayı sildiniz.

# rm orhun1_files/top_data/top.js

Geriye yükleyelim.

# cpio -icvdBum orhun1_files/top_data/top.js < nuri.cpio

İşlem bitince şöyle bir mesaj belirir:

orhun1_files/top_data/top.js
116 blocks

Diyelim ki /home/nuri tüm alt dizinleriyle birlikte /home/ali altına da kopyalansın. (Erişiminiz olduğu ya da superuser olduğunuz varsayılmıştır.)
  
   # find . -print|cpio -pmdv /home/ali


---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tar ile remote backup

# Remote backup almak:

tar cvfz - . | rsh 193.140.151.5 dd of=/dev/rmt/0


# Karsidaki teybi goruntuleme

rsh -n 193.140.151.5 dd if=/dev/rmt/0 | tar tvfz -


# Karsidaki teypten restore etmek

rsh -n 193.140.151.5 dd if=/dev/rmt/0 | tar xvfz -

mt off komutu teybi sürücüden çıkartır.



------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Tar ile:

sing tar

  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

  there is more than one way to skin these cats, this being no comprehensive
  look at these utilities.

Using dump and restore (ufsdump, ufsrestore)

  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.

Using mt command with dump and restore

  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

Example

    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 -
Now some small scripts

#!/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

Frequently used examples of tar:

1.  Using tar to copy files over the net:

    % cd dest-dir

    % rsh -n remote-mach '(cd /dir/wherever ; tar cf - template)' |
       tar xpBf -

    or, this works for me

    % cd from-dir
    % tar cf - template | rsh remote-mach '(cd /dir/wherever ; tar xvpBf -)'

2.  Using tar to copy files from one parititon to another:
    
    % tar cf - . | (cd /pathname ; tar xpBf -)

3.  Writing a tar tape accross the net:

    % rsh remote-mach mt -f /dev/rst1 rew   
    % tar cbfX 127 - /var/backup/tarX . |
        rsh remote-mach dd of=/dev/rst1 obs=127b  

4.  Extracting a tar tape across the net:

    % rsh remote-mach mt -f /dev/rst1 rewind
    % rsh -n remote-mach dd if=/dev/rst1 ibs=127b | tar xpBfb - 127 .      


Ana Sayfaya