雖說Linux很難中勒索,但備份不嫌多,多一項快照也無妨,災難復原時直接恢復到任一時間點就行。

安裝snapper
#yum install -y snapper
建立設定檔
#snapper -c backup create-config /btrfs/backup
修改設定檔
#vim /etc/snapper/configs/backup

設定檔參考這裡:用 snapper 轻松玩转 Btrfs 的快照功能
主要設定保留時間,這台只是備份主機,沒要留太久

TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="4" 
TIMELINE_LIMIT_DAILY="5"
TIMELINE_LIMIT_WEEKLY="2"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"

啟動服務

#sudo systemctl enable snapper-timeline.service snapper-timeline.timer snapper-cleanup.service snapper-cleanup.timer
#sudo systemctl start snapper-timeline.service snapper-timeline.timer snapper-cleanup.service snapper-cleanup.timer

create一個試試

#snapper -c backup create -d test
IO Error
#getenforce
Enforcing
#setenforce 0

發現SELinux造成錯誤,關掉後成功,並有自動快照了。有時間再研究怎麼解決SELinux權限問題。

[root@smb configs]# snapper -c backup list
Type | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+---------------------------------+------+----------+-------------+---------
single | 0 | | | root | | current |
single | 1 | | Sun 09 Dec 2018 07:13:51 PM CST | root | timeline | timeline |
single | 2 | | Sun 09 Dec 2018 08:13:09 PM CST | root | timeline | timeline |
single | 3 | | Sun 09 Dec 2018 09:15:33 PM CST | root | timeline | timeline |

查詢快照使用空間套件:btrfs-du

#sudo wget https://raw.githubusercontent.com/nachoparker/btrfs-du/master/btrfs-du -O /usr/local/sbin/btrfs-du
#sudo chmod +x /usr/local/sbin/btrfs-du
#sudo btrfs-du /btrfs/backup/
Subvolume Total Exclusive ID
─────────────────────────────────────────────────────────────────────────────────────────
backup 0Bytes 0Bytes 257
.snapshots 0Bytes 0Bytes 719
.snapshots/1/snapshot 0Bytes 0Bytes 990
.snapshots/2/snapshot 0Bytes 0Bytes 991
.snapshots/3/snapshot 0Bytes 0Bytes 992
.snapshots/4/snapshot 0Bytes 0Bytes 993
─────────────────────────────────────────────────────────────────────────────────────────
Total exclusive data 0Bytes