BUP 並不單純是 Git, 而是一款基於 Git 的軟件. 一般情況下, 我使用 rsync 來備份我的文件, 而且迄今為止一直工作的很好. 唯一的不足就是無法把文件恢復到某個特定的時間點. 因此, 我開始尋找替代品, 結果發現了 BUP, 一款基於 git 的軟件, 它將數據存儲在一個倉庫中, 並且有將數據恢復到特定時間點的選項.
要使用 BUP, 你先要初始化一個空的倉庫, 然後備份所有文件. 當 BUP 完成一次備份是, 它會創建一個還原點, 你可以過後還原到這裡. 它還會創建所有文件的索引, 包括文件的屬性和驗校和. 當要進行下一個備份時, BUP 會對比文件的屬性和驗校和, 只保存發生變化的數據. 這樣可以節省很多空間.
安裝 BUP (在 CentOS 6 & 7 上測試通過)
首先確保你已經安裝了 RPMFORGE 和 EPEL 倉庫
- [techarena51@vps ~]$ sudo yum groupinstall "Development Tools"
- [techarena51@vps ~]$ sudo yum install python python-devel
- [techarena51@vps ~]$ sudo yum install fuse-python pyxattr pylibacl
- [techarena51@vps ~]$ sudo yum install perl-Time-HiRes
- [techarena51@vps ~]$ git clone git://github.com/bup/bup
- [techarena51@vps ~]$ cd bup
- [techarena51@vps ~]$ make
- [techarena51@vps ~]$ make test
- [techarena51@vps ~]$ sudo make install
對於 debian/Ubuntu 用戶, 你可以使用 "apt-get build-dep bup". 要獲得更多的信息, 可以查看 https://github.com/bup/bup
在 CentOS 7 上, 當你運行 "make test" 時可能會出錯, 但你可以繼續運行 "make install".
第一步時初始化一個空的倉庫, 就像 git 一樣.
- [techarena51@vps ~]$ bup init
默認情況下, bup 會把倉庫存儲在 "~/.bup" 中, 但你可以通過設置環境變量 "export BUP_DIR=/mnt/user/bup" 來改變設置.
然後, 創建所有文件的索引. 這個索引, 就像之前講過的那樣, 存儲了一系列文件和它們的屬性及 git 目標 id (sha1 哈希表). (屬性包括了軟鏈接, 權限和不可改變字節)
- bup index /path/to/file
- bup save -n nameofbackup /path/to/file
-
- #Example
- [techarena51@vps ~]$ bup index /var/www/html
- Indexing:7973,done(4398 paths/s).
- bup: merging indexes (7980/7980),done.
-
- [techarena51@vps ~]$ bup save -n techarena51 /var/www/html
-
- Reading index:28,done.
- Saving:100.00%(4/4k,28/28 files),done.
- bloom: adding 1 file (7 objects).
- Receiving index from server:1268/1268,done.
- bloom: adding 1 file (7 objects).
"BUP save" 會把所有內容分塊, 然後把它們作為對象儲存. "-n" 選項指定備份名.
你可以查看備份列表和已備份文件.
- [techarena51@vps ~]$ bup ls
- local-etc techarena51 test
- #Check for a list of backups available for my site
- [techarena51@vps ~]$ bup ls techarena51
- 2014-09-24-0644162014-09-24-071814 latest
- #Check for the files available in these backups
- [techarena51@vps ~]$ bup ls techarena51/2014-09-24-064416/var/www/html
- apc.php techarena51.com wp-config-sample.php wp-load.php
在同一個服務器上備份文件從來不是一個好的選擇. BUP 允許你遠程備份網頁文件, 但你必須保證你的 SSH 密鑰和 BUP 都已經安裝在遠程服務器上.
- bup index path/to/dir
- bup save-r remote-vps.com -n backupname path/to/dir
例子: 備份 "/var/www/html" 文件夾
- [techarena51@vps ~]$bup index /var/www/html
- [techarena51@vps ~]$ bup save -r [email protected]:-n techarena51 /var/www/html
- Reading index:28,done.
- Saving:100.00%(4/4k,28/28 files),done.
- bloom: adding 1 file (7 objects).
- Receiving index from server:1268/1268,done.
- bloom: adding 1 file (7 objects).
恢復備份
登入遠程服務器並輸入下面的命令
- [techarena51@vps ~]$bup restore -C ./backup techarena51/latest
-
- #Restore an older version of the entire working dir elsewhere
- [techarena51@vps ~]$bup restore -C /tmp/bup-out/testrepo/2013-09-29-195827
- #Restore one individual file from an old backup
- [techarena51@vps ~]$bup restore -C /tmp/bup-out/testrepo/2013-09-29-201328/root/testbup/binfile1.bin
唯一的缺點是你不能把文件恢復到另一個服務器, 你必須通過 SCP 或者 rsync 手動復制文件.
通過集成的 web 服務器查看備份.
- bup web
- #specific port
- bup web :8181
你可以使用 shell 腳本來運行 bup, 並建立一個每日運行的定時任務.
- #!/bin/bash
-
- bup index /var/www/html
- bup save -r [email protected]:-n techarena51 /var/www/html
BUP 並不完美, 但它的確能夠很好地完成任務. 我當然非常願意看到這個項目的進一步開發, 希望以後能夠增加遠程恢復的功能.
你也許喜歡閱讀使用inotify-tools實時文件同步:
RHCE系列之實時同步----Rsync+Inotify-Tools http://www.linuxidc.com/Linux/2014-06/103806.htm
inotify-tools+rsync實時同步文件安裝和配置 http://www.linuxidc.com/Linux/2012-06/63624.htm
Linux git命令參數及用法詳解 http://www.linuxidc.com/Linux/2012-01/51205.htm
Fedora通過Http Proxy下載Git http://www.linuxidc.com/Linux/2009-12/23170.htm
在Ubuntu Server上安裝Git http://www.linuxidc.com/Linux/2009-06/20421.htm
服務器端Git倉庫的創建(Ubuntu) http://www.linuxidc.com/Linux/2011-02/32542.htm
Linux下Git簡單使用教程(以Android為例) http://www.linuxidc.com/Linux/2010-11/29883.htm
Git權威指南 PDF高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm
Git 的詳細介紹:請點這裡
Git 的下載地址:請點這裡