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
$



[Update]


I tried it with macOS Monterey (macOS 12).

This trick is still alive!

(I tried to mount only the user area according to the changes after Big Sur/File System).



Example.


1.There are three snapshots that are older than 24 hours.


# ref. After "Big Sur", /System/Volumes/Data is a user area that can be rewritten... 

$ sw_vers

ProductName: macOS

ProductVersion: 12.0.1

BuildVersion: 21A559 

$ date

Sun Nov 28 10:55:40 JST 2021


$ tmutil listlocalsnapshots /System/Volumes/Data

Snapshots for disk /System/Volumes/Data:

com.apple.TimeMachine.2021-11-27-071917.local **Over 24h

com.apple.TimeMachine.2021-11-27-091918.local  **Over 24h

com.apple.TimeMachine.2021-11-27-103436.local  **Over 24h

com.apple.TimeMachine.2021-11-27-113253.local

com.apple.TimeMachine.2021-11-27-130050.local

com.apple.TimeMachine.2021-11-27-153557.local

com.apple.TimeMachine.2021-11-27-165513.local

com.apple.TimeMachine.2021-11-27-183404.local

com.apple.TimeMachine.2021-11-27-193419.local

com.apple.TimeMachine.2021-11-27-203421.local

com.apple.TimeMachine.2021-11-27-213428.local

com.apple.TimeMachine.2021-11-27-223438.local

com.apple.TimeMachine.2021-11-27-233441.local

com.apple.TimeMachine.2021-11-28-003449.local

com.apple.TimeMachine.2021-11-28-024156.local


2.Mount just one of them. (com.apple.TimeMachine.2021-11-27-081918.local)


$ mkdir /var/tmp/2021-11-27-081918

$ mount_apfs -o nobrowse -s com.apple.TimeMachine.2021-11-27-081918.local /System/Volumes/Data /var/tmp/2021-11-27-081918

mount_apfs: snapshot implicitly mounted readonly


$ mount

..

com.apple.TimeMachine.2021-11-27-081918.local@/dev/disk1s1 on /private/var/tmp/2021-11-27-081918 (apfs, local, nodev, nosuid, read-only, journaled, nobrowse, mounted by hoge)


$ df

..

com.apple.TimeMachine.2021-11-27-081918.local@/dev/disk1s1 1953595632 649392544 1264217568    34% 1420277 6321087840    0%   /private/var/tmp/2021-11-27-081918


3.Create new snapshot and automatically delete by deleted(8), then Mounted snapshot is not deleted.


$ tmutil localsnapshot

NOTE: local snapshots are considered purgeable and may be removed at any time by deleted(8).

Created local snapshot with date: 2021-11-28-105622


$ tmutil listlocalsnapshots /System/Volumes/Data

Snapshots for disk /System/Volumes/Data:

com.apple.TimeMachine.2021-11-27-081918.local **mounted snapshot is not deleted

com.apple.TimeMachine.2021-11-27-113253.local

com.apple.TimeMachine.2021-11-27-130050.local

com.apple.TimeMachine.2021-11-27-153557.local

com.apple.TimeMachine.2021-11-27-165513.local

com.apple.TimeMachine.2021-11-27-183404.local

com.apple.TimeMachine.2021-11-27-193419.local

com.apple.TimeMachine.2021-11-27-203421.local

com.apple.TimeMachine.2021-11-27-213428.local

com.apple.TimeMachine.2021-11-27-223438.local

com.apple.TimeMachine.2021-11-27-233441.local

com.apple.TimeMachine.2021-11-28-003449.local

com.apple.TimeMachine.2021-11-28-024156.local

com.apple.TimeMachine.2021-11-28-105622.local


 

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。