熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

SMB的擴展應用

2022-06-13   來源: Oracle 

  在Linux風行的今天與Windows機器相互共享文件已經是非常普遍的應用了關於samba的設置的文檔也相當的多本站也有不少了不過在使用它的高級功能方面還是比較欠缺的這類文檔是非常稀有的而且只有英文版的為了方便國內的Linux用戶我將這些文檔整理一下翻譯過來並結合自己一些經驗為大家提供一些幫助
  
    注這篇文章並不是一篇關於如何配置samba的基礎文檔而是需要閱讀者有一定的Linux使用經驗熟悉腳本語言並且對samba有一定的使用經驗主要是針對於一些企業的Linux網管或比較有經驗的Linux愛好者
  
    這篇文章也其說是文章不如說是一個技巧提示但是我個人覺得它意義非常大特別是對於大中型企業的用戶來講它可能非常重要
  
    它主要描述了如果在Linux下使用samba來為使用Windows系統的機器作備份並且描述了如何跨子網共享samba
  
  將Windows機器備分到一台Linux主機上
  
    Adam Neat(au)向我們提供了以下一段代碼它描述了如何使用smbclient軟件包將windows機器備份到Linux主機上Adam說它可以用來備份windows x和NT機器到一台Linux的磁帶機上
  
    另一段代碼是Dan Tager ()提供的Dan的腳本是通過rsh來備份Unix機器盡管它可以修改成ssh以便使其更簡單些
  
    在下面這個腳本中字符串agnea是作備份工作的Linux主機的一個用戶名
  
  
   #!/bin/bash
   clear
   echo Initialising
   checkdate=`date | awk {print $}`
  
   if [ f ~agnea/backupdir/backupdata ]; then
   echo ERROR: No config file for today!
   echo FATAL!
   exit
   fi
  
   if [ d ~agnea/backupdir/temp ]; then
   echo ERROR: No tempoary directory found!
   echo
   echo Attempting to create
   cd ~agnea
   cd backupdir
   mkdir temp
   echo Directory Made temp
   fi
  
   if [ $ = ]; then
   echo ERROR: enter in a machine name (ie: cdwriter)
   exit
   fi
  
   if [ $ = ]; then
   echo ERROR: enter in a SMB (Lan Manager) Resource (ie: work)
   exit
   fi
  
   if [ $ = ]; then
   echo ERROR: enter in an IP address for $ (ie:
   xxxxxx) exit
   fi
   #########################################################
   # Main Section
   #
   #########################################################
  
   cd ~agnea/backupdir/temp
   rm r ~agnea/backupdir/temp/*
   cd ~agnea/backupdir/
  
   case $checkdate
   in
   Mon)
   echo Backuping for Monday
   cat backupdata | /usr/local/samba/bin/smbclient
   $$ I$ N echo Complete
   if [ d ~agnea/backupdir/Monday ]; then
   echo Directory Monday Not found
   making mkdir
   ~agnea/backupdir/Monday
   fi
  
   echo Archiving
   cd ~agnea/backupdir/temp
   tar cf mondaytar *echo done
   rm ~agnea/backupdir/Monday/mondaytar
   mv mondaytar ~agnea/backupdir/Monday
   ;;
  
  
   Tue)
   echo Backuping for Tuesday
   cat backupdata | /usr/local/samba/bin/smbclient
   $$ I$ N echo Complete
  
   if [ d ~agnea/backupdir/Tuesday ]; then
   echo Directory Tuesday Not found
   making mkdir
   ~agnea/backupdir/Tuesday
   fi
   echo Archiving
   cd ~agnea/backupdir/temp
   tar cf tuesdaytar *
   echo done
   rm ~agnea/backupdir/Tuesday/tuesdaytar
   mv tuesdaytar ~agnea/backupdir/Tuesday
   ;;
  
   Wed)
   echo Backuping for Wednesday
   cat backupdata | /usr/local/samba/bin/smbclient
   $$ I$ N echo Complete
  
   if [ d ~agnea/backupdir/Wednesday ]; then
   echo Directory Wednesday Not found
   making mkdir
   ~agnea/backupdir/Wednesday
   fi
   echo Archiving
   cd ~agnea/backupdir/temp
   tar cf wednesdaytar *
   echo done
   rm ~agnea/backupdir/Wednesday/wednesdaytar
   mv wednesdaytar ~agnea/backupdir/Wednesday
   ;;
  
   Thu)
   echo Backuping for Thrusday
   cat backupdata | /usr/local/samba/bin/smbclient
   $$ I$ N echo Complete
  
   if [ d ~agnea/backupdir/Thursday ]; then
   echo Directory Thrusday Not found
   making mkdir
   ~agnea/backupdir/Thursday
   fi
   echo Archiving
   cd ~agnea/backupdir/temp
   tar cf thursdaytar *
   echo done
   rm ~agnea/backupdir/Thursday/thursdaytar
   mv thursdaytar ~agnea/backupdir/Thursday
   ;;
  
  
   Fri)
   echo Backuping for Friday
   cat backupdata | /usr/local/samba/bin/smbclient
   $$ I$ N echo Complete
  
   if [ d ~agnea/backupdir/Friday ]; then
   echo Directory Friday Not found
   making mkdir
   ~agnea/backupdir/Friday
   fi
   echo Archiving
   cd ~agnea/backupdir/temp
   tar cf fridaytar *
   echo done
   rm ~agnea/backupdir/Friday/fridaytar
   mv fridaytar ~agnea/backupdir/Friday
   ;;
  
   *)
   echo FATAL ERROR: Unknown variable passed for day
   exit ;;
  
   esac
   ###########
  ______________________________________________________
  這裡是Dan的備份腳本
  ______________________________________________________
   #!/bin/bash
  
   BACKDIR=D/backup
   WINCMD=D/usr/bin/smbclient
  
   function CopyWinHost(){
  
   # tars and gzips windows shares to a local directory using sambas
   # smbclient
   # argument is the remote host windows host name
   # argument is the share name to be backed up
  
   echo $$$
   REMOTE=D$
   SHARE=D$
   DEST=D$
  
   # create a tarred gzip file using samba to copy direct from a
   # windows pc
   # is a password Needs some password even if not defined on
   # remote system
   $WINCMD $REMOTE$SHARE Tc |gzip > $DEST
   echo `date`: Done backing up $REMOTE to $DEST
   echo
   }
  
   function CopyUnixHost(){
  
   # tars and gzips a directory using rsh
   # argument is the name of the remote source host
   # argument is the full path to the remote source directory
   # argument is the name of the local targzip file day of week
   # plus tgz will be appended to argument
  
   REMOTE=D$
   SRC=D$
   DEST=D$
  
  
   if rsh $REMOTE tar cf $SRC |gzip > $DEST; then
  echo `date`: Done backing up $REMOTE:$SRC to $DEST
   else
   echo `date`: Error backing up $REMOTE:$SRC to $DEST
   fi
  
   }
  
   # $: win=Dbackup windows machine unix=Dbackup unix machine
   case $ in
   win)
  # $=D remote windows name $=Dremote share name
  # $=Dlocal destination directory
  CopyWinHost $ $ $;;
   unix)
  # $ =D remote host $ =D remote directory
  # $ =D destination name
  CopyUnixHost $ $ $;;
   esac
  
    以上兩個文件都是針對於具體的機器而設計的如果您准備對自己的機器也進行備份那麼請您安照您自己的機器的具體情況來修改這兩個文件的一個就可以使用了
  
  跨子網使用samba
  
    許多大型企業有不同的子網但是如何將另一個子網的內容被其它子網共享是一個非常關鍵的問題許多samba的用戶在這裡遇到許多麻煩如果這點被解決了
From:http://tw.wingwit.com/Article/program/Oracle/201311/16849.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.