Product SiteDocumentation Site

9.10. 備份

備份是管理員的主要責任之一,它是個複雜的主題,涉及難以掌握的強大工具。
Many programs exist, such as amanda, bacula, or BackupPC. Those are client/server systems featuring many options, whose configuration is rather difficult. Some of them provide user-friendly web interfaces to mitigate this. For non-enterprise systems, administrators might want to check out rsnapshot or rdiff-backup. Users can easily create backups of their filesystems with timeshift, fsarchiver, duplicity, or even dd.
Debian contains dozens of other backup software covering all possible use cases, as you can easily confirm with apt-cache search backup.
與其逐一介紹它們,本章將經由 Falcot 公司管理者的角度,設定備份的策略。
Falcot 公司的備份有兩個目標:無誤地復原被刪除的檔案,以及快速地復原硬碟毀損的電腦 (伺服器或桌面)。

9.10.1. 使用 rsync 備份

以磁帶備份太慢且太貴,現在採用備份在專屬伺服器的硬碟策略,以 RAID (見 節 12.1.1, “軟 RAID”) 軟體保護資料在硬碟毀損時不致遺失。桌面電腦沒有個別備份的策略,使用者應在部份的檔案伺服器備份其資料。rsync 命令 (取自同名的套件) 用於逐日備份這些伺服器。
受限於可用的硬碟空間,無法執行完整的逐日備份。所以,rsync 命令優先於以硬連結複製內容,避免使用太多的硬碟空間。rsync 祗處理上次備份後,再被修改的檔案。以這個機制可使用較小的空間備份。因為所有的備份已經立即可得與可用 (例如,在同個網路的不同資料夾共享),可快速地比對兩個指定日期。
這種備份機制可以輕易地經由 dirvish 程式執行。使用備份的儲存空間 (“空” 的),放置含時間戳記的備份檔案 (在 dirvish 文件中,這些檔案被稱為 “vaults”)。
主要的組態在 /etc/dirvish/master.conf 檔案內。設定備份儲存空間的位置,管理 “vaults” 清單,以及備份到期的預設值。其他的組態位在 bank/vault/dirvish/default.conf 檔案內,包括對應檔案集的特殊組態。

範例 9.3. /etc/dirvish/master.conf 檔案

bank:
    /backup
exclude:
    lost+found/
    core
    *~
Runall:
    root    22:00
expire-default: +15 days
expire-rule:
#   MIN HR    DOM MON       DOW  STRFTIME_FMT
    *   *     *   *         1    +3 months
    *   *     1-7 *         1    +1 year
    *   *     1-7 1,4,7,10  1
The bank setting indicates the directory in which the backups are stored. The exclude setting allows you to indicate files (or file types) to exclude from the backup. The Runall is a list of file sets to backup with a time-stamp for each set, which allows you to assign the correct date to the copy, in case the backup is not triggered at precisely the assigned time. You have to indicate a time just before the actual execution time (according to /etc/cron.d/dirvish). Finally, the expire-default and expire-rule settings define the expiration policy for backups. The above example keeps forever backups that are generated on the first Sunday of each quarter, deletes after one year those from the first Sunday of each month, and after 3 months those from other Sundays. Other daily backups are kept for 15 days. The order of the rules does matter, Dirvish uses the last matching rule, or the expire-default one if no other expire-rule matches.

範例 9.4. /backup/root/dirvish/default.conf 檔案

client: rivendell.falcot.com
tree: /
xdev: 1
index: gzip
image-default: %Y%m%d
exclude:
    /var/cache/apt/archives/*.deb
    /var/cache/man/**
    /tmp/**
    /var/tmp/**
    *.bak
以上的例子指定需備份的檔案:在機器 rivendell.falcot.com (在地備份時,祗由 hostname 命令指定在地機器的名稱) 內的檔案,尤其是在根目錄之下的檔案 (tree: /),除了列在 exclude 內的檔案。備份將限制在一個檔案系統的內容 (xdev: 1)。將不包括來自掛載點的檔案。將生成一個儲存檔案索引 (index: gzip),以及根據現在日期生成的映像檔 (image-default: %Y%m%d)。
There are many options available, all documented in the dirvish.conf(5) manual page. Once these configuration files are setup, you have to initialize each file set with the dirvish --vault vault --init command. From there on the daily invocation of dirvish-runall will automatically create a new backup copy just after having deleted those that expired.

9.10.2. 供備份恢復系統

Desktop computers, which are not backed up, will be easy to reinstall from custom DVD-ROMs/USB sticks prepared with simple-cdd (see 節 12.3.3, “Simple-CDD: The All-In-One Solution”). Since this performs an installation from scratch, it loses any customization that can have been made after the initial installation. This is fine since the systems are all hooked to a central LDAP directory for accounts and most desktop applications are preconfigured thanks to dconf (see 節 13.3.1, “GNOME” for more information about this).
Falcot Corp 的管理者知道該公司備份政策的限制。未以防火牆保護備份伺服器,而是把它放在另個房間,以免在災難來臨時與主伺服器同歸一燼。而且,每週以 DVD-ROM 做增量備份 — 祗備份修改過的檔案。