歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> Linux下的各種有效的備份方法匯總

Linux下的各種有效的備份方法匯總

日期:2017/3/6 15:49:55   编辑:關於Unix
一. 在單個 服務器 上的備份 最常見的備份方法是在命令行上用經典的備份程序tar .是最通用最簡單也最有用的備份工具# tar cvf backup.tar /etc (備份整個etc 目錄及下面的所有子目錄和文件)#gzip -9 backup.tar (得到最大的壓縮率) 你可以把備份後的backu
  一. 在單個服務器上的備份
  最常見的備份方法是在命令行上用經典的備份程序tar .是最通用最簡單也最有用的備份工具# tar cvf backup.tar /etc (備份整個etc 目錄及下面的所有子目錄和文件)#gzip -9 backup.tar (得到最大的壓縮率)
  
  你可以把備份後的backup.tar.gz轉存到其它介質,CDR/CDRW光盤,私人信箱等
  
  二. 跨服務器的備份
  1. 利用ssh/scp功能直接把文件或目錄從一台服務器拷貝到另一台服務器上。參見文章荟萃中另一篇文章《如何不用密碼進行ssh/scp》
  2.利用smbmount先mount另一台服務器上的Samba共享目錄到這台機器的某目錄下,直接進行cp操作。 如:[root@sh/mnt]# smbmount //sh3/pub /mnt/sh3 -N將服務器sh3上的Samba共享目錄pub mount到服務器sh上的/mnt/sh3目錄下面。且不提示密碼
  3. 利用NFS功能進行服務器間的備份,有一定程序的安全性問題,在此不多做介紹。
  
  三. 備份到其它介質
  你可以備份到磁帶,ZIP drive , JAZ drive
  1. 備份到磁帶
  假設你已經設置並安裝好了磁帶機,本人用的是HP SuitStore 500,外置,SCSI接口。
  1. 查看磁帶中的目錄 tar tvf /dev/st0
  2. 查看磁帶內容並輸出到一個文件中 tar tvf /dev/st0 > stlist
  3. 備份檔案 tar cvf /dev/st0 /etc
   tar cvf /dev/st0 /etc/hosts /boot /etc/smb.conf
  4. 按指定的文件內容或目錄釋放出磁帶中的相應文件
  tar -T stlist -xvf /dev/st0
   tar xvfz /dev/st0 /etc/
  6. 附加個別文件到磁帶後面
   tar -r /etc/hosts /etc/passwd -vf /dev/st0
  7. 從現有磁帶中刪除一個或幾個文件
   tar --delete etc/hosts -vf /dev/st0
  8. 附加一個現有的tar文檔到磁帶後面
   tar -A pamd.tar -vf /dev/st0
  2. 備份到JAZ 驅動器
  7.3 Getting a Zip drive to work
  (參見Redhat FAQ: href="http://www.redhat.com/support/docs/faqs/rhl_general_faq/FAQ.html"target="_blank">http://www.redhat.com/support/docs/faqs/rhl_general_faq/FAQ.html)
  There are excellent references in the ZIP HOWTOs at href="http://www.redhat.com/mirrors/LDP."target="_blank">http://www.redhat.com/mirrors/LDP.
  
  Also, there is a Zip HOWTO at:
  
  target="_blank">http://www.linuxdoc.org/HOWTO/HOWTO-INDEX-3.html
  
  In Red Hat Linux 6.1, there are a few extra steps needed to get a parallel port Zipdrive to work:
  
  Edit your /etc/conf.modules and add:
  
      alias parport_lowlevel parport_pc
      alias scsi_hostadapter ppa
      
  Then log in as root and run:
  modprobe ppa
  
  Some people have had problems if they daisy chain a Zip drive off of a chain with a printer on it. Currently, we recommend that you use either the printer or the Zipdrive.
  
  For more information, check target="_blank">www.torque.net/paraport
  
  If you are having problems with an IDE Zip drive, here is further information:
  
  First check and make sure there is a disk in the drive. Also, make sure you aremounting it as partition 4 instead of 1. An example would be hdc4. The reason for this is thatthe Macintosh uses partition 4 for its data partition and has problems if data is on another partition.
  
  3備份到 JAZ 驅動器
  假定JAQ驅動器為SCSI接口,把JAZ驅動器當作SCSI鏈上的一個存儲設備即可。
  
  四. 跨操作系統進行備份
  1. 把Linux服務器上的數據資料備份到windows 95/98機器上 假定一台windows機器jephe有一完全讀寫共享目錄 data ,且密碼為 secret,現希望把Linux上的文件備份到這個共享目錄下,則先把這個共享可寫目錄mount到Linux下,再做普通的cp操作
  
  附:在Linux上對Novell服務器上的數據進行備份:(http://www.pcquest.com/linux/netware.asp) NetWare And Linux
  
  Making your Linux server talk to NetWare servers and printers
  
  As almost every office-LAN has a NetWare server, your desktop client must be able totalk to NetWare. This article tells you how a Linux box can aclearcase/" target="_blank" >ccess files on a Novellserver and print to a Novell print queue.
  
  Linux, by default, uses the IP network protocol for network communication. However,Novell NetWare uses the IPX network protocol. As the Linux kernel has a completely newnetwork implementation compared to other operating systems like Unix, it supports a range of non-TCP/IP protocols including the IPX protocol. Kernels 2.x onwards have built-in IPX support. The Red Hat Linux distributed on our CD-ROM has it too. The Linux kernelsupports the IPX protocol only. It does not, yet, support protocols such as IPX/RIP, SAP, orNCP.
  
  The first step is to configure your IPX interfaces.
  
  Login as root
  Type ipx_configure--auto_primary= on --auto_interface=on
  Wait for a minute and type cat /proc/net/ipx_interface. You should see something like:
  Network Node_Address Primary Device Frame_Type
  000000E1 00A0C925164A Yes eth0 802.2
  
     4.Type slist. You should see a list of the NetWare servers on your LAN.
  
  Known NetWare File Servers Network Node Address
  D74_SERVER 00000D74 00000000001
  
  If you don't, wait for a few minutes and retry. If the slist command displays amessage like: ncp_connect: Invalid argument, then your kernel probably does not support IPX.
  Check that you have actually booted off the appropriate kernel. When you boot youshould see messages about IPX and ncpfs in system startup messages. If the slist commanddoes not list all of your fileservers, then you may need to use the manual networkconfiguration method. Type cat /proc/net/ipx_interface. You should see something like:
  
  At this point, your Linux box is setup for IPX networking. Check if your kernel has support for NetWare NCP file system. The default Red Hat kernel has NCP file system support. You simply have to load the ncpfs module /usr/sbin/lib/modules/2.0.32/fs/ncpfs.0.
  You can also add the line to your local file to load it automatically at the boottime.
  
  Once that is done
  
  Login as root (only root can mount NetWare volumes).
  Type mkdir/netware to create a directory for mounting the NetWare volumes.
  Type ncpmount -S D74_SERVER -U user10 /netware. You will be prompted for a passwordfor user10.
  At this point your server is mounted on /netware. The volumes are sub-directoriesunder /netware. So the SYS volume would be /netware/sys and the DATA volume would be/netware/data.
  If you only want to mount a single volume, you can use ncpmount -S D74_SERVER -V sys-U user10 /netware. This will mount only the SYS volume to /netware.
  When you finish using the Net-Ware volume, you can unmount usingncpumount/netware.
  Tip: You don't need to manually unmount NetWare volumes when you shutdown.
  When you want to share the mounted NetWare volume among other Linux users, you need to understand file permissions. The NetWare file system doesn't support user IDs andgroup IDs for directories. So all files and directories on the mounted directory have the permissions as the directory where it was mounted. For example, if you type ls-ld/netware, drwxrwxr-x 1 root root 512 Nov 24 1960 /netware is what you get.
  
  So, all the NetWare files will have the above file permissions.
  
  If you want non-root users to mount NetWare volumes, ncpmount command must be SetUserid Root, so you would need to type chmod 4755 ncpmount
  
  Simplifying mounting of volumes
  
  There is another way of configuring NetWare mounts-by creating a .nwclient file inyour home directory. This file contains details of temporary or user specific NetWare mountsthat would be performed regularly. It allows you to store the details of mounts so that you canrecreate them without specifying all details each time. Its format is quite straightforward:
  
  # The first entry is the 'preferred server' entry and is
  # used whenever you do not specify a server explicitly.
  #
  # User USER01 login to D74_SERVER fileserver with password 'password'D74_SERVER/USER01 password
  #
  # User CYBER login to the CYBER_DOC fileserver with no password.
  CYBER_DOC/CYBER -
  
  To activate these mounts you type ncpmount/netware to mount D74_SERVER with a login(say) TERRY under /NetWare directory. Note that this entry was chosen because no fileserver wasspecified in the mount command. Had we used ncpmount -S CYBER_DOC /netware, then it would mountCYBER_DOC with a login of CYBER under /NetWare directory.
  
  Since the passwords for your Novell accounts are not encrypted, you should protectthem by typing chmod 0600 $HOME/.nwclient.
  
  Printing to NetWare print queues
  
  Once you are comfortable accessing your files, you can try printing to a Novell printqueue.
  
  Use slist to check that you can see your Novell server.
  Type pqlist -S D74_SERVER -U USER01 to list the print queues on D74_SERVER.
  Type nprint -S D74_SERVER -U USER01 -q DMPQUEUE/etc/passwd. This would print the/etc/passwd file to the DMPQUEUE print queue on the D74_SERVER by logging in as USER01. If youhave created your .nwclient file, then you can use nprint -q DMPQUEUE /etc/passwd instead. Theserver and login ID are taken from the .nwclient file. Ensure that the queue names are incapitals.
  Check your Novell print queue from a DOS client using PCONSOLE. You should see aprintjob called No Description in the DMPQUEUE.
  Printing using nprint is tedious-first it requires you to print to a file and thensubmit using nprint. You can automate this by setting up a Linux print queue, whichautomatically sends it to the NetWare print queue. The following steps are a bit confusing andreading about Unix printing in the Printing HOW-TO would be beneficial.
  
  The following steps tell you how to configure a NetWare print queue for Red Hat Linux.
  
  Copy Netwareprint.tgz from the CD-ROM to the /tmp directory.
  cd /;tar xzvf /tmp/netwareprint.tgz. This will replace /usr/bin/printtool, /usr/lib/rhs/rhs-printfilters/master-filter, and/usr/lib/rhs/rhs-printfilters/nwprint, with the latest versions.
  If you aren't already in X Windows, start by typing startx.
  If the graphical control panel is not visible, start it by typing control-panel &in an XTerm.
  Click the printer icon in the control panel. You should see a list of printerscurrently configured for Linux.
  Click Add. A dialog box with various supported print queues appears. Select Novell Netware print queue.
  In Printer name, enter nwqueue.
  Enter D74_SERVER and DMPQUEUE for the NetWare server and print queue. Ensure that thequeue names are in capitals.
  Enter the user name and password if needed. If you have a password, you must enter ithere because it will not prompt you for a password during printing.
  In the filter type, select the appropriate printer type. If your laser printersupports postscript printing, please use Postscript printer.
  Click OK and you'll see a new printer called nwqueue in the list of printers.
  Select nwqueue from the list and click Test Print from the menu. Use a DOS client with PCONSOLE to check the DMPQUEUE. You should see a new print job in the queue. In caseit doesn't work, try mounting a volume from the server D74_SERVER (on which the printqueue resides).
  Now your printing should be set-up. To print /etc/passwd, type lpr -Pnwqueue /etc/passwd at your prompt.
  To print from Netscape, use the command lpr -Pnwqueue to print. Alternatively, you could always print to a file and use nprint to print it manually.
  Utility commands
  
  Recent versions of Volker's ncpfs package include a range of user and administration commands. The tools are built and installed as part of the ncpfs installation process.
  Though each has a detailed manual page, here is a summary of each from the IPX-HOWTO.
  
  ncopy (Network Copy): Allows efficient file copying using a NetWare function rather than a copy across the network.
  nsend (Network Send): Allows you to send messages to other users on a NetWare server.
  nwbols (List Bindery Objects): Allows you to list the bindery contents of a NetWareserver.
  nwboprops (List Properties of a Bindery Object): Allows you to view the properties ofa NetWare bindery object.
  nwfsinfo (Fileserver Information): Prints summary information about NetWare server.
  nwpasswd (NetWare Password): Allows you to change NetWare users password.
  nwrights (NetWare Rights): Displays the rights associated with a particular file ordirectory.
  nwuserlist (Userlist): Lists the users currently logged into a NetWare fileserver.
  pqlist (Print Queue List): Displays the contents of a NetWare print queue.
  slist (Server List): Displays a list of known NetWare fileservers.
  
  NDS and Linux
  
  A Linux distribution by Caldera features a range of commercially supportedenhancements including fully functional Novell NetWare client support. The base distribution is the well-respected Red Hat Linux. Caldera has added its Network Desktop products to it.The NetWare support provides a fully featured Novell NetWare client built on a technology licensed from Novell. The client provides full-client access to Novell 3.x and 4.x fileservers, and includes features such as NetWare Directory Service (NDS) and RSA encryption. If you work within a NetWare 4.x or NDS environment, then the Caldera NetWare Client is the only solution available. You can obtain much more information and ordering details from the Caldera Web server at target="_blank">www.caldera.com/.
  
  Useful documents
  
  To get more information on IPX and NetWare support, read the IPX-HOWTO. This documentn presumes that you understand how to build a Linux kernel with the appropriatenetworking options selected, and that you know how to use the basic networking tools such as ifconfig and route. If you do not, read the NET-3-HOWTO (NET-3-HOWTO.html). SomeotherLinux HOWTO documents that might be useful are: The Ethernet-HOWTO(Ethernet-HOWTO.html), which describes the details of configuring an Ethernet device for Linux; the PPP-HOWTO(PPP-HOWTO.html), which explains the available IPX support for version 2.2.0d andlater of the Linux PPP implementation.
  
  Latest versions of these files can be obtained fromsunsite.unc.edu/pub/Linux/docs/HOWTO/IPX-HOWTO. In your Linux box, the HOW-TOs are located in the /usr/doc/HOWTO directory in acompressed format. To view these files, type zless IPX-HOWTO.gz.
  
  Divya Mahajan
  
  五. 利用 Raid 1功能進行鏡像備份。
  把有重要數據的單獨分區進行raid 1鏡像,用兩個硬盤,對數據分區給以同樣大小的柱面數和大小附:在RedHat 6.0裡設置RAID (http://www.tt.tzptt.zj.cn/linux/useskill/raid.htm)
  《Linux 公報》……讓Linux更富魅力!
  
  目錄:
  資源
  RAID介紹
  設置RAID條帶(RAID Strip)
  設置RAID鏡象
  使用一個空閒的設備設置RAID 5
  注解
  你可以在這個地址 href="http://www.tcu-inc.com/mark/articles/Raid.html找到本文的最新版本。"target="_blank">http://www.tcu-inc.com/mark/articles/Raid.html找到本文的最新版本。
  
  資源
  target="_blank">http://ostenfeld.dk/~jakob/Software-RAID.HOWTO/
  /usr/doc/raidtools-0.90
  這些文章介紹了硬件細節,這部份內容在本文中不會涉及。
  這是DPT HOWTO的地址, target="_blank">http://www.ram.org/computing/linux/dpt_raid.html
  
  RAID介紹
  我建議你讀一讀[email protected]寫的軟件RAID HOWTO。很明顯,他是個丹麥人。丹麥是一個住著許多聰明人的世界上最好的國家。他的這篇HOWTO寫得非常好,也許我根本就沒有必要寫這篇文章。我之所以寫這篇文章是因為文檔一般來說都寫得不大容易懂,當然現在情況已有很大的改觀。本文中介紹的安裝是在RedHat 6.0上進行的,我認為在其他的Linux版本中應該也能用。我什麼時候會轉去用Debian呢?我希望能盡快。
  
  什麼是RAID?簡單的說,它可以讓你在幾個硬盤上做些有趣的事。它可以讓你把幾個硬盤合並起來,把數據分散地存放在這幾個硬盤中。它可以提高往硬盤讀寫數據的速度,也可以在硬盤上備份數據。這樣即使你有一個硬盤壞了,你還可以從其他的硬盤中恢復所有的數據。你可以讀讀軟件RAID HOWTO中有關RAID級別的部份來更好的了解不同類型的軟件RAID。
  
  為了試驗本文中的例子,你需要設置一些小的分區。我建議你設置一個1G的擴展分區,然後在這個擴展分區上建一些100兆的邏輯分區。請千萬要記住,你只能在一個無關緊要的硬盤上進行試驗。如果你毀了這個硬盤上的數據,那是你自己的錯。即使我的文章中寫得不對,你也必需對自己的所作所為負責。
  
  RAID條帶(strip RAID)
  我只准備介紹如何設置RAID條帶來存放數據。也就是說,我不會把操作系統的主要部份放在RAID條帶上。用RAID條帶來存放整個系統會帶來一些問題,所以我不准備這麼做。 簡單的說,在Linux系統上設置RAID條帶需要四個步驟。條帶把數據存放在兩個或更多的硬盤(實際上是分區)上,這些數據有一半是在一個硬盤上,另一半在另一個硬盤上。這樣可以提高硬盤讀寫的速度,因為數據是從兩個硬盤上同時讀出來的。再說一次,你可以在HOWTO讀到更詳細的內容。
  
  首先,我們要配置/dev/md0,然後我們要格式化這些分區,接下來要配置/etc/rc.d/rc.local來激活RAID,最後要配置/etc/rc.d/rc.local來把這些設備安裝到某個目錄。
  
  具體步驟
  現在,我要使用一些小竅門。我認為大多數的低端用戶並沒有兩個硬盤,所以我要使用同一個硬盤上的兩個分區而不是兩個硬盤。建立一個有兩個邏輯分區的擴展分區。這兩個分區,/dev/hda5和/dev/hda6,的大小必需一樣。在同一個硬盤上的兩個分區之間進行RAID條帶是沒有任何意義的,即使是在同一個IDE控制器的不同硬盤上這麼做也是沒有意義的。請記住,這只不過是個練習。
  
  在 /etc/raidtab中這麼寫:
  raiddev /dev/md0
  
       raid-level   0
  
       nr-raid-disks  2
  
       nr-spare-disks 0
  
       chunk-size   4
  
       persistent-superblock 1 
  
       device     /dev/hda5
  
       raid-disk    0
  
       device     /dev/hda6
  
       raid-disk    1
  
  使用以下命令格式化分區
  mkraid /dev/md0
  
  如果你在用"mkraid"命令時出了些問題,它應該會給出如何解決問題的提示。然後執行如下命令:
  mkfs -t ext2 /dev/md0
  
  接著,你可以在"/proc/mdstat"文件中查raid的狀態。
  cat /proc/mdstat
  
  執行以下命令會在/etc/rc.d/rc.local中增加一行
  echo "raidstart /dev/md0" >> /etc/rc.d/rc.local
  
  把這個命令執行一次。這可以為RAID設備建好目錄並在/etc/rc.d/rc.local中增加一條命令。
  mkdir /RAID
  
  echo "mount /dev/md0 /RAID" >> /etc/rc.d/rc.local
  
  如果你不想重啟動計算機,你現在就可以激活RAID,
  raidstart /dev/md0
  
  mount /dev/md0 /RAID
  
  你可以用此命令來檢查已經安裝的目錄。
  df
  
  RAID鏡象
  和以上的例子一樣,我要使用同一個硬盤上的兩個分區,並且我也只對數據分區進行鏡象。
   
  首先,設置/dev/md0,然後格式化分區,接著配置/etc/rc.d/rc.local來激活raid,最後配置/etc/rc.d/rc.local來把鏡象設備安裝到一個目錄下。
  
  如下設置 /etc/raidtab
  raiddev /dev/md0
  
       raid-level   1
  
       nr-raid-disks  2
  
       nr-spare-disks 0
  
       chunk-size   4
  
       persistent-superblock 1
  
       device     /dev/hda5
  
       raid-disk    0
  
       device     /dev/hda6
  
       raid-disk    1
  
  用以下命令格式化分區
  mkraid /dev/md0
  
  如果你在用"mkraid"命令時出了些問題,它應該會給出如何解決問題的提示。然後執行如下命令:
  mkfs -t ext2 /dev/md0
  
  接著,你可以在"/proc/mdstat"文件中查raid的狀態。
  
  cat /proc/mdstat
  
  執行以下命令會在/etc/rc.d/rc.local中增加一行
  echo "raidstart /dev/md0" >> /etc/rc.d/rc.local
  
  把這個命令執行一次。這可以為RAID設備建好目錄並在/etc/rc.d/rc.local中增加一條命令。
  mkdir /RAID
  
  echo "mount /dev/md0 /RAID" >> /etc/rc.d/rc.local
  
  如果你不想重啟動計算機,你現在就可以激活RAID,
  raidstart /dev/md0
  
  mount /dev/md0 /RAID
  
  你可以用此命令來檢查已經安裝的目錄。
  df
  
  使用空閒的分區設置RAID 5
  使用一個空閒的設備來試驗RAID 5是一件很酷的事。我們還是只用一個硬盤。一般來說,我都會建立一個100M的邏輯分區來進行試驗。如果你有一個1G的擴展的分區,那你就可以有10個邏輯分區來進行各種試驗。
  
  具體的步驟和以上介紹的鏡象以及條帶一樣,把配置文件按以下修改。
  
  raiddev /dev/md0
  
      raid-level   5
  
      nr-raid-disks  7
  
      nr-spare-disks 1
  
      persistent-superblock 1
  
      parity-algorithm    left-symmetric
  
      chunk-size   32
  
      device     /dev/hda5
  
      raid-disk    0
  
      device     /dev/hda6
  
      raid-disk    1
  
      device     /dev/hda7
  
      raid-disk    2
  
      device     /dev/hda8
  
      raid-disk    3
  
      device     /dev/hda9
  
      raid-disk    4
  
      device     /dev/hda10
  
      raid-disk    5
  
      device     /dev/hda11
  
      raid-disk    6
  
    ### Also, let us have a spare device 
  
      device     /dev/hda12
  
      spare-disk   0
  
  注解
  請使用/etc/rc.d/rc.local來安裝raid設備,而不要用/etc/fstab。如果你想用/etc/fstab,你盡可以試一試。這多半沒有用,但有些人就是喜歡自己試試看(就象我一樣)。 這些文檔以前寫得挺難懂得,但這些HOWTO已經更新過了,這些工具也變得更好用了。現在,在這些例子的幫助下,任何一個會用Linux的人都可以設置一個raid設備。希望這可以幫助降低RAID服務器的價錢。
  
  如果你想更好的使用軟件RAID,請用U2WSCSI控制器,象Adaptec控制器或其他的好品牌,如DPT,Mylex等。對於只需要鏡象而不考慮速度的比較便宜的raid,也可以使用IDE控制器。如果你想更進一步使用?br>布?AID,有幾個公司支持Linux的硬件RAID。

Copyright © Linux教程網 All Rights Reserved