-->

2020/01/09

Managing lifetime of APFS snapshot (Catalina) ..[Update Monterey]

APFS snapshots are great!... If you haven't tried macOS recovery from APFS snapshot, please try it (macOS recovery-> Restore from Time Machine-> select local snapshot), it may rollback to old system just in a minute!
But macOS (Catalina) keeps the "APFS snapshot" for Only 24 hours and then deletes it automatically, It cannot be directly controlled by the user.

However, we can extend/control the Lifetime of APFS snapshots by taking advantage of the property that "Mounted APFS snapshots are not deleted".

Remark.
"tmutil mountlocalsnapshots" command doesn't seem to be the case (automatically deleted even if mounted..).
The following is valid only with the “mount_apfs” command.

Example.
1.There are two snapshots that are older than 24 hours.
$ tmutil listlocalsnapshots /
com.apple.TimeMachine.2020-01-08-004327 **Over 24h 
com.apple.TimeMachine.2020-01-08-015245 **Over 24h 
com.apple.TimeMachine.2020-01-08-050434
com.apple.TimeMachine.2020-01-08-062935
com.apple.TimeMachine.2020-01-08-073858
com.apple.TimeMachine.2020-01-08-094946
com.apple.TimeMachine.2020-01-08-120712
com.apple.TimeMachine.2020-01-08-130215
com.apple.TimeMachine.2020-01-08-150315
com.apple.TimeMachine.2020-01-08-170418
com.apple.TimeMachine.2020-01-08-194014
com.apple.TimeMachine.2020-01-08-204437
com.apple.TimeMachine.2020-01-08-214559
com.apple.TimeMachine.2020-01-08-224630
com.apple.TimeMachine.2020-01-08-234634
2.Mount just one of them. (com.apple.TimeMachine.2020-01-08-015245)
$ mkdir /var/tmp/2020-01-08-015245
$ mount_apfs -o nobrowse -s com.apple.TimeMachine.2020-01-08-015245 / /var/tmp/2020-01-08-015245
mount_apfs: snapshot implicitly mounted readonly
$

$ mount
...
com.apple.TimeMachine.2020-01-08-015245@/dev/disk1s1 on /private/var/tmp/2020-01-08-015245 (apfs, local, nodev, nosuid, read-only, journaled, nobrowse, mounted by hoge)
$

$ df
...
com.apple.TimeMachine.2020-01-08-015245@/dev/disk1s1  489825072  323761528  154301464    68%  1455542 9223372036853320265    0%   /private/var/tmp/2020-01-08-015245
3.Create new snapshot and automatically delete old one, then Mounted snapshot is not deleted.
$ tmutil localsnapshot /
Created local snapshot with date: 2020-01-09-025905
$

$ tmutil listlocalsnapshots /
com.apple.TimeMachine.2020-01-08-015245 **mounted snapshot is not deleted
com.apple.TimeMachine.2020-01-08-025856
com.apple.TimeMachine.2020-01-08-050434
com.apple.TimeMachine.2020-01-08-062935
com.apple.TimeMachine.2020-01-08-073858
com.apple.TimeMachine.2020-01-08-094946
com.apple.TimeMachine.2020-01-08-120712
com.apple.TimeMachine.2020-01-08-130215
com.apple.TimeMachine.2020-01-08-150315
com.apple.TimeMachine.2020-01-08-170418
com.apple.TimeMachine.2020-01-08-194014
com.apple.TimeMachine.2020-01-08-204437
com.apple.TimeMachine.2020-01-08-214559
com.apple.TimeMachine.2020-01-08-224630
com.apple.TimeMachine.2020-01-08-234634
com.apple.TimeMachine.2020-01-09-025905
$

フォロワー