-
Notifications
You must be signed in to change notification settings - Fork 5
Snapshots HOWTO
Clone the kernel sources from github.
# git clone -b ovl_snapshot https://github.com/amir73il/linux.git
Build the kernel with overlayfs module and choose to enable overlayfs snapshots feature:
Overlay filesystem support (OVERLAY_FS) [N/m/y/?] (NEW) m Overlayfs snapshot support (Experimental) (OVERLAY_FS_SNAPSHOT) [N/y/?] (NEW) y
Clone the helper scripts from github.
# git clone https://github.com/amir73il/overlayfs.git # cd overlayfs/scripts # make install install -m 755 mount.snapshot /sbin install -m 755 umount.snapshot /sbin install -m 755 ovlsnapshot /sbin
Follow the steps below to setup and start using overlayfs snapshots.
The instruction below use the environment variable $MNT to represent a directory to snapshot. For example, you could set:
# MNT=/mnt/xfs/tests # mkdir $MNT
Following are some examples of using the ovlsnapshot helper script.
Run "ovlsnapshot" with no arguments to get the script usage message:
ovlsnapshot v0.1 (overlay snapshot management script) usage: ovlsnapshot help [cmd] usage: ovlsnapshot version overlay snapshot commands: usage: ovlsnapshot {status|list} [<path>|-a] usage: ovlsnapshot {umount|mount} [<path>|-a] usage: ovlsnapshot {create|take} <path>[@[/]<snapshot-name>] (default-name=<date.time>) usage: ovlsnapshot {delete|remove} <path>@[/]<snapshot-name> usage: ovlsnapshot {clean} <path> snapshot command parameter may be given in ZFS style <path>@<snapshot-name> and it may be given as the snapshot directory path <path>@/<snapshot-name>. If <snapshot-name> part is omitted, command may apply to all snapshots (e.g. umount). overlay snapshot test commands: usage: ovlsnapshot {test|tests} <path> [test-number] [file-size-mb]
To mount a snapshot mount of directory $MNT, use the command "ovlsnapshot mount $MNT".
# ovlsnapshot mount $MNT snapshot /mnt/xfs/tests@ was mounted .
The same can be achieved with the native mount command, which invokes the mount helper mount.snapshot.
# mount -t snapshot snapshot $MNT
In both cases the result is a snapshot mount at path $MNT@/_
# mount |grep snapshot /mnt/xfs/tests on /mnt/xfs/tests@/_ type snapshot (rw,noatime,nosnapshot)
At this point, the snapshot mount has no snapshots and all operations on snapshot mount pass through to the underlying fs.
To take a snapshot named 'Sunday' of $MNT, use the command "ovlsnapshot take $MNT@Sunday".
# ovlsnapshot take $MNT@Sunday snapshot /mnt/xfs/tests@Sunday was created . # ovlsnapshot take $MNT@Monday snapshot /mnt/xfs/tests@Monday was created . # mount |grep snapshot /mnt/xfs/tests on /mnt/xfs/tests@/_ type snapshot (rw,noatime,snapshot=Monday/_) /mnt/xfs/tests@Monday on /mnt/xfs/tests@/Monday/_ type overlay (ro,noatime,lowerdir=/mnt/xfs/tests,upperdir=Monday/u,workdir=Monday/w,redirect_dir=origin,index=on,nfs_export=on) /mnt/xfs/tests@Sunday on /mnt/xfs/tests@/Sunday/_ type overlay (ro,noatime,lowerdir=Sunday/u:Monday/_,redirect_dir=origin,index=on,nfs_export=nested)
In the example above, the snapshot mount with read-write access is mounted at $MNT@/_. The read-only snapshot overlays of Sunday and Monday are mounted at $MNT@/Sunday/_ and $MNT@/Monday/_.
Changes made in the snapshot mount will not appear in the snapshot overlays. Changes made directly in $MNT directory may appear in the snapshot overlays.
To view the status of snapshots on $MNT, use the command "ovlsnapshot list $MNT".
# ovlsnapshot list $MNT overlay snapshot /mnt/xfs/tests@Monday is mounted. /mnt/xfs/tests filesystem disk usage: 810M 41G 2% /mnt/xfs/tests directory disk usage: 11M /mnt/xfs/tests snapshots disk usage: 4.0K . Snapshots list at '/mnt/xfs/tests': ------------------------- * = current, M = mounted, D = deleted Status Name Disk-usage -------------------------- *M Monday 0 M Sunday 0 .
After taking snapshots, the snapshot mount and all snapshot overlays are mounted.
To unmount the snapshot mount and all snapshot overlays of $MNT, use the command "ovlsnapshot umount $MNT".
To mount the snapshot mount and all snapshot overlays of $MNT, use the command "ovlsnapshot mount $MNT".
# ovlsnapshot umount $MNT snapshot /mnt/xfs/tests@Monday was unmounted . # ovlsnapshot mount $MNT snapshot /mnt/xfs/tests@Monday was mounted .
The same can be achieved with the native mount/umount commands. The mount helpers mount.snapshot and umount.snapshot take care of mounting and unmounting the snapshot mount and all of the snapshot overlays.
# umount $MNT@/_ # mount |grep snapshot # mount -t snapshot snapshot $MNT # mount |grep snapshot /mnt/xfs/tests@Monday on /mnt/xfs/tests@/Monday/_ type overlay (ro,noatime,lowerdir=/mnt/xfs/tests,upperdir=Monday/u,workdir=Monday/w,redirect_dir=origin,index=on,nfs_export=on) /mnt/xfs/tests@Sunday on /mnt/xfs/tests@/Sunday/_ type overlay (ro,noatime,lowerdir=Sunday/u:Monday/_,redirect_dir=origin,index=on,nfs_export=nested) /mnt/xfs/tests on /mnt/xfs/tests@/_ type snapshot (rw,noatime,snapshot=Monday/_)
Deleting a snapshot is a subtle business, because the upper dir of each overlay is required for composing the snapshot overlay of older snapshots and all snapshot overlays depend on the current snapshot overlay.
Therefore, there are two delete commands with slightly different semantics. When the snapshot mount and overlays are mounted, use the command "ovlsnapshot delete $MNT@Sunday" to unmount the Sunday snapshot overlay and mark it for deletion. After a snapshot is deleted, its content is not lost, but its status in the list command will show as D (deleted) and its snapshot overlay will no longer be mounted on subsequent snapshot mount command.
# ovlsnapshot delete $MNT@Sunday snapshot /mnt/xfs/tests@Sunday was deleted . # ovlsnapshot list $MNT overlay snapshot /mnt/xfs/tests@Monday is mounted. /mnt/xfs/tests filesystem disk usage: 810M 41G 2% /mnt/xfs/tests directory disk usage: 11M /mnt/xfs/tests snapshots disk usage: 4.0K . Snapshots list at '/mnt/xfs/tests': ------------------------- * = current, M = mounted, D = deleted Status Name Disk-usage -------------------------- *M Monday 0 D Sunday 0 .
Use the command "ovlsnapshot remove $MNT@Sunday" to permanently delete the content of the Sunday snapshot. To maintain the snapshot dependencies, only the oldest snapshot can be removed. Merging snapshots is not yet supported.
# ovlsnapshot remove $MNT@Sunday snapshot /mnt/xfs/tests@Sunday was removed . # ovlsnapshot list $MNT overlay snapshot /mnt/xfs/tests@Monday is not mounted. /mnt/xfs/tests filesystem disk usage: 810M 41G 2% /mnt/xfs/tests directory disk usage: 11M /mnt/xfs/tests snapshots disk usage: 4.0K . Snapshots list at '/mnt/xfs/tests': ------------------------- * = current, M = mounted, D = deleted Status Name Disk-usage -------------------------- * Monday 0 . # ovlsnapshot remove $MNT@Monday snapshot /mnt/xfs/tests@Monday was removed . # ovlsnapshot list $MNT No overlay snapshots at '/mnt/xfs/tests'. .
Use the command "ovlsnapshot clean $MNT" to permanently delete all snapshots of $MNT.
# ovlsnapshot clean $MNT snapshot /mnt/xfs/tests@Sunday was removed snapshot /mnt/xfs/tests@Monday was removed all snapshots at '/mnt/xfs/tests' removed .
The command "ovlsnapshot tests $MNT" runs a few simple overlayfs snapshots sanity tests.
# ovlsnapshot tests $MNT ovlsnapshot: umount: snapshot /mnt/xfs/tests@ is not mounted! snapshot /mnt/xfs/tests@ was mounted . Running snapshot test 1: ------------------------ Appending 1M zeros to 1M.1 oflag=direct Writing 1M random data to 1 files . Files in snapshot mount: A/a.txt:aligator B/b.txt:bizon C/c.txt:camel . 1M.1: OK . snapshot /mnt/xfs/tests@1 was created . Create test: ------------ Creating d.txt Creating e.txt . Files in snapshot mount: A/a.txt:aligator B/b.txt:bizon C/c.txt:camel D/d.txt:dodo E/e.txt:emu . A/a.txt: OK B/b.txt: OK C/c.txt: OK D/d.txt: OK E/e.txt: OK . Files in snapshot 1: A/a.txt:aligator B/b.txt:bizon C/c.txt:camel . 1M.1: OK . overlay snapshot /mnt/xfs/tests@1 is mounted. /mnt/xfs/tests filesystem disk usage: 811M 41G 2% /mnt/xfs/tests directory disk usage: 12M /mnt/xfs/tests snapshots disk usage: 8.0K . Snapshots list at '/mnt/xfs/tests': ------------------------- * = current, M = mounted, D = deleted Status Name Disk-usage -------------------------- *M 1 4.0K . ...
Visit the Snapshots testing page for instructions how to run the unionmount snapshot testsuite.