dar でバックアップ&リストア

電脳備忘録

今後仕事でwebサーバーのバックアップについて議題になったとき、いつでも対応できるようにCentOSで可能なバックアップ方法を調べて、dar(Disk Archive)というソフトをインストールしてテストサーバで動作確認をしたときのメモ。

お約束

参照は自己責任でお願いします。

darのインストール

# wget http://jaist.dl.sourceforge.net/sourceforge/dar/dar-2.3.10.tar.gz
# tar zxvf dar-2.3.10.tar.gz
# cd dar-2.3.10
# ./configure # make
# make install-strip

ルバックアップ

/home /var /etc /usr /lib 以下のディレクトリを/backupディレクトりにbackup-full.x.darという名前でフルバックアップ

# dar -R / -c /backup/backup-full -g home -g var -g etc -g usr -g lib
WARNING! File modified while reading it for backup: /var/lib/mysql/ibdata1
--------------------------------------------
132966 inode(s) saved
with 3951 hard link(s) recorded
1 inode(s) changed at the moment of the backup
0 inode(s) not saved (no inode/file change)
0 inode(s) failed to save (filesystem error)
20 inode(s) ignored (excluded by filters)
0 inode(s) recorded as deleted from reference backup
--------------------------------------------
Total number of inodes considered: 132987
--------------------------------------------

You have new mail in /var/spool/mail/root WARNING!となっていますが、どうやら読んでいる間に/var/lib/mysql/ibdata1ファイルが変更されたようです。

差分バックアップ

/home /var /etc /usr /lib 以下のディレクトリを/backupディレクトりにbackup-diff.x.darという名前で差分バックアップ

# dar -R / -c /backup/backup-diff -A /backup/backup-full -g home -g var -g etc -g usr -g lib
WARNING! File modified while reading it for backup: /var/lib/mysql/ibdata1
--------------------------------------------
10 inode(s) saved
with 3951 hard link(s) recorded
1 inode(s) changed at the moment of the backup
132956 inode(s) not saved (no inode/file change)
0 inode(s) failed to save (filesystem error)
20 inode(s) ignored (excluded by filters)
0 inode(s) recorded as deleted from reference backup
--------------------------------------------
Total number of inodes considered: 132987
--------------------------------------------

やはり読んでいる間に/var/lib/mysql/ibdata1ファイルが変更された旨のメッセージが表示されますが、これはテストサーバにインストールしているzabbixが常にデータベースにアクセスしているからだと思われます。

リストア(フル)

フルバックアップと差分バックアップからリストアを実施
フルバックアップファイルをリストア

# dar -R / -x /backup/backup-full
/etc/initlog.conf is about to be overwritten, OK ? [return = OK | Esc = cancel]
Continuing...
/etc/warnquota.conf is about to be overwritten, OK ? [return = OK | Esc = cancel]
.
中略
.
--------------------------------------------
136917 inode(s) restored
0 inode(s) not restored (not saved in archive)
0 inode(s) ignored (excluded by filters)
0 inode(s) less recent than the one on filesystem
0 inode(s) failed to restore (filesystem error)
0 inode(s) deleted
--------------------------------------------
Total number of inodes considered: 136917
--------------------------------------------

差分バックアップファイルをリストア

# dar -R / -x /backup/backup-diff
/etc/sysconfig/networking/profiles/default/hosts is about to be overwritten, OK ? [return = OK | Esc = cancel]
Continuing...
/etc/sysconfig/networking/devices/ifcfg-eth0 is about to be overwritten, OK ? [return = OK | Esc = cancel]
.
中略
.
--------------------------------------------
3961 inode(s) restored
132956 inode(s) not restored (not saved in archive)
0 inode(s) ignored (excluded by filters)
0 inode(s) less recent than the one on filesystem
0 inode(s) failed to restore (filesystem error)
0 inode(s) deleted
--------------------------------------------
Total number of inodes considered: 136917
--------------------------------------------

リストア(一部)

フルバックアップと差分バックアップから /var ディレクトリのみリストアする場合
(フルバックアップファイル)

# dar -R / -x /backup/backup-full -g var
/var/gdm/.gdmfifo is about to be overwritten, OK ? [return = OK | Esc = cancel]
Continuing...
/var/gdm/.cookie is about to be overwritten, OK ? [return = OK | Esc = cancel]
.
中略
.
--------------------------------------------
7944 inode(s) restored
0 inode(s) not restored (not saved in archive)
4 inode(s) ignored (excluded by filters)
0 inode(s) less recent than the one on filesystem
0 inode(s) failed to restore (filesystem error)
0 inode(s) deleted
--------------------------------------------
Total number of inodes considered: 7948
--------------------------------------------

(差分バックアップファイル)

# dar -R / -x /backup/backup-diff -g var
/var/log/Xorg.0.log is about to be overwritten, OK ? [return = OK | Esc = cancel]
Continuing...
/var/log/gdm/:0.log is about to be overwritten, OK ? [return = OK | Esc = cancel]
.
中略
.
--------------------------------------------
10 inode(s) restored
7934 inode(s) not restored (not saved in archive)
4 inode(s) ignored (excluded by filters)
0 inode(s) less recent than the one on filesystem
0 inode(s) failed to restore (filesystem error)
0 inode(s) deleted
--------------------------------------------
Total number of inodes considered: 7948
--------------------------------------------

圧縮する場合

gzipで圧縮してバックアップ

# dar -R / -z -c /backup/backup-full -g home -g var -g etc -g usr -g lib
At least one slice of an old archive with the same name remains in the directory  /backup. It is advised to remove all the old archive's slices before creating an archive of same name. Can I remove these old slices? [return = OK | Esc = cancel]
Continuing...
--------------------------------------------
132966 inode(s) saved
with 3951 hard link(s) recorded
0 inode(s) changed at the moment of the backup
0 inode(s) not saved (no inode/file change)
0 inode(s) failed to save (filesystem error)
20 inode(s) ignored (excluded by filters)
0 inode(s) recorded as deleted from reference backup
--------------------------------------------
Total number of inodes considered: 132986
--------------------------------------------

オプション

-c バックアップファイルの指定。
-x リストアするバックアップファイルを指定。
-R  ルートディレクトリ。
-g  バックアップするディレクトリ。
-Rで指定したディレクトリからの相対パス。
-A [/path] 差分バックアップで参照するファイル。
-z [level] gzip圧縮(levelを省略した場合は9)。
-y [level] bzip2圧縮(levelを省略した場合は9)。

(圧縮は必要なライブラリがインストールされていること)
このほかのオプションは dar -h で確認すること。
サーバがハード的に故障したときのことを考慮して、バックアップ先はRAID機能を持った外部ストレージに設定しておくのが無難かもしれませんね。死活監視等もっと冗長性を考慮したやり方があると思いますが、私の今の知識ではこの辺が限界かな・・・。もっと勉強しないと・・・。

広告

ブログの維持費に充てるでございます・・・。