最後更新: 2015-04-09
btrfs-snapshot-rotation
btrfs-snapshot: Take and rotate snapshots on a btrfs file system
Program: bash
HomePage: https://github.com/mmehnert/btrfs-snapshot-rotation
原理:
# Clean up older snapshots: for i in `ls $TARGET|sort |grep @${SNAP}|head -n -${max_snap}`; do cmd="btrfs subvolume delete $TARGET/$i" if [ -z $QUIET ]; then echo $cmd fi $cmd >/dev/null done # Create new snapshot: cmd="btrfs subvolume snapshot -r $SOURCE $TARGET/`date "+%F--%H-%M-%S-@${SNAP}"`" if [ -z $QUIET ]; then echo $cmd fi $cmd >/dev/null
Usage
btrfs-snapshot source target snap_name count [-q]
source: Path to make snapshot of
target: Snapshot directory
snap_name: Base name for snapshots, to be appended to date "+%F--%H-%M-%S"
count: Number of snapshots in the timestamp-@snap_name format to (keep at one time for a given snap_name.)
[-q]: Be quiet.
準備
mount -t btrfs /dev/xxx /backup
cd /backup
btrfs sub create sync_root
mkdir backup_root
crontab
# 對 sync_root 建立 readonly snapshot 並 mount 到 backup_root
btrfs-snapshot /backup/sync_root /backup/backup_root daily 14 -q
path store
2015-04-09--11-52-50-@daily
2015-04-09--11-52-51-@daily
2015-04-09--11-52-57-@daily
2015-04-09--11-53-00-@daily
2015-04-09--11-53-01-@daily
2015-04-09--11-53-02-@daily
2015-04-09--11-53-03-@daily
2015-04-09--11-53-04-@daily
2015-04-09--11-53-05-@daily
2015-04-09--11-53-19-@daily
2015-04-09--11-53-33-@daily
2015-04-09--11-53-46-@daily
2015-04-09--11-53-56-@daily
2015-04-09--11-55-03-@daily
附加檔案 | 大小 |
---|---|
btrfs-snapshot-rotation-master.zip | 2.08 KB |