天天看點

Linux 上使用 backup-manager 進行系統備份Linux 上使用 backup-manager 進行系統備份

無論簡單與否,我們都有機會去了解這麼一件事,那就是備份的重要性從來都不可以被低估。考慮到備份的方法真的多如牛毛,你可能想要知道怎樣來有效地為你的系統選擇正确的工具和和合适的政策。

是什麼讓備份管理器在衆多的備份工具或備份政策中脫穎而出呢?讓我來簡單介紹一些它的與衆不同的特性吧:

簡單的設計與管理:配置檔案易于讀懂和編輯,即便是初學者也很容易上手。

一勞永逸:它在配置好後就可以通過cron周期性運作。

支援多種協定遠端備份:無縫整合多種傳輸協定、應用和雲後端(如,ftp,scp,ssh-gpg,rsync,aws s3等等)來傳輸生成的歸檔包到一組遠端主機。

支援資料庫備份:包括支援開箱即用備份mysql/mariadb和postgresql資料庫。

支援加密:備份過程中支援基于gpg檔案的加密。

<a target="_blank"></a>

備份管理器的安裝是快速而無痛的,因為它就包含在大多數linux發行版的基礎軟體庫中。

# aptitude install backup-manager

在基于debian的系統中安裝時,會提示你輸入要存放備份歸檔檔案的目錄。如果選擇的目錄不存在,那麼當你首次運作備份管理器時它會自動建立。

選擇ok并按Enter鍵。

Linux 上使用 backup-manager 進行系統備份Linux 上使用 backup-manager 進行系統備份

在下一步中,會詢問你要備份的所有目錄(用空格分隔)。建議,但不是嚴格要求,列出同一父目錄中的幾個子目錄,而不要僅僅輸入父目錄。

你可以跳過該步驟并在以後對配置檔案中bm_tarball_directoriesb變量進行設定。否則的話,就請盡可能多地添加你想要的目錄,然後選擇ok:

Linux 上使用 backup-manager 進行系統備份Linux 上使用 backup-manager 進行系統備份

# yum install backup-manager

備份管理器的主配置檔案是/etc/backup-manager.conf。該檔案被劃分為幾個章節,裡面定義了備份方法和相關的變量(或“鍵值”),這些配置讓備份管理器成為一個多樣化的工具,可以廣泛地應付各種狀況。

出于示範目的,我們将考慮以下環境:

每周對/etc,/home以及/var/log目錄進行一次完整備份(我們将在下面通過cron設定備份的頻率)。

通過ssh傳輸.tar.gz備份歸檔檔案到兩台不同主機dev1和dev3上指定的目标目錄。

通過ssh備份本地mysql資料庫到相同目标主機。

用你喜愛的文本編輯器打開/etc/backup-manager.conf檔案,并編輯以下變量。如果你願意,你大可不必理會那些#開頭的行。在本文中,它隻是用作說明的注釋:

# specify the backup method(s) that will be used.

# tarball: takes a list of directories and builds the corresponding tarballs.

# mysql: archives mysql databases using mysqldump. to restore the database, you # need to use the same tool manually.

export bm_archive_method="tarball mysql"

# where to store the backups.

export bm_repository_root="/var/archives"

# the following directive indicates backup-manager to name

# the generated files after the directory that was backed up.

export bm_tarball_nameformat="long"

# define the compression type for the generated files.

export bm_tarball_filetype="tar.gz"

# list the directories that you want to backup.

export bm_tarball_directories="/etc /home /var/log"

# exclude some subdirectories or file extensions.

export bm_tarball_blacklist="/var/log/myotherapp.log *.mp3 *.mp4"

# list the database(s) that you want to backup, separated by spaces.

export bm_mysql_databases="mysql mybase wordpress dotclear phpbb2"

# mysql username.

export bm_mysql_adminlogin="root"

# mysql password for username.

export bm_mysql_adminpass="mypassword"

# add support for drop statements (optional).

export bm_mysql_safedumps="true"

# the hostname or ip address where the database(s) reside.

export bm_mysql_host="localhost"

# port where mysql server is listening.

export bm_mysql_port="3306"

# compression type (optional).

export bm_mysql_filetype="gzip"

# do not archive remote hosts, but only localhost.

bm_tarball_over_ssh="false"

# user account for ssh upload.

export bm_upload_ssh_user="root"

# absolute path of the user's private key for passwordless ssh login.

export bm_upload_ssh_key="/root/.ssh/id_rsa"

# remote hosts (make sure you have exported your public key to them):

export bm_upload_ssh_hosts="dev1 dev3"

# remote destination for uploading backups. if it doesn't exist,

# this directory will be created automatically the first time

# backup-manager runs.

export bm_upload_ssh_destination="/var/archives/backups/$hostname"

要手動運作備份管理器,請輸入以下指令。你也可以選擇添加‘-v’辨別以便一步一步詳細檢查運作過程。

# backup-manager

bm_tarball_directories列出的目錄将作為tarball備份到bm_repository_root目錄,然後通過ssh傳輸到bm_upload_ssh_destination指定的主機dev1和dev3。

Linux 上使用 backup-manager 進行系統備份Linux 上使用 backup-manager 進行系統備份

正如你在上面圖檔中看到的那樣,備份管理器在運作的時候建立了一個名為/root/.back-manager_my.cnf的檔案,mysql密碼通過bm_mysql_adminpass指定。那樣,mysqldump可以驗證到mysql伺服器,而不必在指令行以明文格式接受密碼,那樣會有安全風險。

一旦決定哪一天是進行每周備份的最佳日子(最佳時間),你可以讓cron來為你運作備份管理器。

打開root的crontab檔案(注意,你必須以root登入):

# crontab -e

假定你想要在星期天的上午5:15分運作備份管理器,那麼就添加下面這行。

15 05 * * 0 /usr/sbin/backup-manager &gt; /dev/null 2&gt;&amp;1

在本文中,我已經展示了備份管理器這個備份工具是怎樣的簡單而強大,并且易于使用。在你的備份政策中,你可能還有其它幾個選項需要考慮,請參閱手冊頁或使用者手冊,裡面也包含了幾個部署執行個體和建議。

希望此文對你有所幫助,請在下面随意提問和評論。

原文釋出時間:2014-01-03

本文來自雲栖合作夥伴“linux中國”