File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_use_snapshots.mdwn
Revision 1.1: download - view: text, annotated - select for diffs
Thu Jun 27 18:03:10 2013 UTC (9 months, 3 weeks ago) by jdf
Branches: MAIN
CVS tags: HEAD
Add a small tutorial on how to use fss(4).

# How to use snapshots with NetBSD

Snapshots using fss(4) aren't a new thing in NetBSD, they have been supported 
since NetBSD 2.0. But their concept and usage is rather unintuitive from what 
you might know from other snapshotting mechanisms such as zfs', so here is a 
tutorial on how to use them.

## What is a snapshot?

A snapshot is a consistent view on a filesystem at a certain point in time.
This means, you take a snapshot of a filesystem, then create a new file or 
change an existing one, and if you look at the snapshot, it will show you the 
old version of the file or the directory without this file.

## What is a snapshot not?

A snapshot is no filesystem versioning! Snapshots by fss are read-only 
*views*, and you cannot revert the filesystem back to a snapshot without 
copying all the files on filesystem layer. You can only mount the 
snapshot to see what the filesystem looked like back then, but not more.

## How to create snapshots?

Snapshots are configured using the tool fssconfig(8). To create a 
snapshot, you have to enter the snapshot device you want to use 
(`/dev/fssX`), the filesystem you want to snapshot and the place of the 
snapshot file (which can even lie on the filesystem it is snapshotting). 
So, if you want to create a snapshot of filesystem `/`, you would e.g. 
enter:

    # fssconfig -c fss0 / /root/backup

Then you get a snapshot in `/root/backup`. You can then mount that 
snapshot somewhere, and in that mount, you have a view of the filesystem 
at the point of creating the snapshot:

    # mount /dev/fss0 /mnt

When you are done with the snapshot, you unmount it and unconfigure the snapshot:

    # umount /dev/fss0
    # fssconfig -u fss0

## How to use snapshots?

To use a snapshot, you just configure it again with the same parameters 
as the first time, but now without creating it:

    # fssconfig fss0 / /root/backup
    # mount /dev/fss0 /mnt

If you want to use the snapshot only once, you can use the option `-x` 
when creating it. Then the snapshot will only be available for this one 
single time, and is deleted afterwards.

    # fssconfig -cx fss0 / /root/backup

## Usage example

What is this even good for if I can't even write to it?
You can use it e.g. for saving files before doing an upgrade or other 
critical changes. When the upgrade goes wrong, you just have to copy 
back the files from the snapshot to the real filesystem.

So, all in all, an example of how to use a snapshot to save and rescue a 
system:

    # fssconfig -c fss0 / /root/backup
	# fssconfig -u fss0
	# rm /etc/rc.conf
	# shutdown -r now
	[...system will not start again, but drop you to a single-user shell...]
	# mount -o rw /
	# fssconfig -x fss0 / /root/backup # The snapshot will be deleted afterwards.
	# mount /dev/fss0 /mnt
	# cp /mnt/etc/rc.conf /etc/rc.conf
	# shutdown -r now
	[be happy about the login prompt again]


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb