# CLI commands
[TOC]
## Add filesystem
> Creates a new filesystem -- either blank, or from an existing snapshot.
`mfs add [-source-store <store_name>] [-store <store_name>] <fs_name> <snapshot_hash | "new">`
#### Params
- `store` _(optional)_
Specifies which block store should be used for the newly created FS.
If not specified, and only one block store exists, that block store is used.
If multiple block stores exist, this param **must** be specified.
- `source-store` _(optional)_
If a FS block hash is specified (instead of "new"), this param determines which block store should be used to fetch the FS block.
If not specified, and only one block store exists, that block store is used.
If multiple block stores exist, this param **must** be specified.
#### Examples
- **Creating a new blank filesystem named "foo"**:
`mfs add foo new`
Assuming only one block store is defined in the config, this command will create a FS like this:
```yaml
filesystems:
foo:
store: default
```
If **multiple block stores** are defined in the config, that command will produce an error. Instead, we have to specify which store to use:
`mfs add -store bar foo new`
which clarifies that we want to use the "bar" store for our new FS.
- **Creating a new filesystem named "foo" from a snapshot**:
`mfs add foo 42e52...`
If **multiple block stores** exist, the **FS store** must be specified:
`mfs add -store bar foo 42e52...`
Additionally, if **multiple block stores exist and the snapshot block is NOT contained within the FS store** _(like the above command assumes)_, the **source store** must also be specified:
`mfs add -store bar -source-store qux foo 42e52...`
## List filesystems
> Lists all filesystems _(created using `mfs add`)_.
`mfs list`
#### Example
```bash
$ mfs list
foo
bar
baz
qux
```
## Destroy filesystem
> Destroys a filesystem, including all snapshots and all file data.
`mfs destroy <fs_name>`
## Clone filesystem
> Clones a filesystem, including all snapshots and all file data.
`mfs clone <fs_name> <new_fs_name>`
#### Example
`mfs clone foo qux`
Creates a new FS named "qux" that is a clone of "foo".
## Change filesystem store
> Changes a filesystems' block store, copying all snapshots and file data to the new block store, and removing them from the old one.
`mfs change-store <fs_name> <store_name>`
#### Example
`mfs change-store foo storeBaz`
Changes FS foo's block store from its current store to "storeBaz". "storeBaz" will now contain all the snapshots and file blocks that FS "foo" has, and they are now deleted from the old store.
## Verify FS
> Verifies if the FSs' latest snapshot block and all of its file blocks exist.
`mfs verify [-check-hashes] [-all-snapshots] <fs_name>`
#### Params
- `check-hashes` _(optional)_
Additionally verifies if the saved hashes match the actual hashes of the data.
- `all-snapshots` _(optional)_
Additionally verifies all snapshots, not just the latest one.
_Note_: `check-hashes` and `all-snapshots` can be used at the same time.
#### Example
- **Verify blocks exist for the latest snapshot**:
`mfs verify foo`
- **Verify blocks exist and check all block hashes for the latest snapshot**:
`mfs verify -check-hashes foo`
- **Verify blocks exist and check all block hashes for all snapshots**:
`mfs verify -all-snapshots -check-hashes foo`
## Mount FS
> Mounts a filesystem at a path.
`mfs mount [-readonly] <fs_name> <path>`
#### Params
- `readonly` _(optional)_
Specifies that the mounted FS should not be writable.
#### Example
`mfs mount foo ~/mount` - mounts FS "foo" at ~/mount
## Unmount FS
> Unmounts a mounted filesystem, either by name or by path.
`mfs unmount <fs_name | path>`
#### Example
- **Unmount by name**:
`mfs unmount foo`
- **Unmount at path**:
`mfs unmount ~/mount`
## Save snapshot
> Saves a new snapshot of a currently mounted FS.
`mfs snapshot save <fs_name | path>`
#### Example
- **Save by FS name**:
`mfs snapshot save foo`
- **Save by path**:
`mfs snapshot save ~/mount`
## Mount snapshot read-only
> Mounts a specific snapshot as a read-only filesystem.
`mfs snapshot mount <snap_hash> <path>`
Can be unmounted using `mfs unmount <path>`.
#### Example
`mfs snapshot mount 4a123... ~/ro-mount`
## List snapshots
> Lists a filesystems' snapshots in reverse chronological order. Shows the snapshot policy, timestamp, and hash for each snapshot.
`mfs snapshot list <fs_name>`
#### Example
```bash
$ mfs snapshot list foo
hourly@2020.02.21-12:03:43 - 429ff3618b0a70d8aa38e5f40d560f3976f793cd0509923313f5aba4fcd27fab
daily@2020.02.21-11:57:49 - 0aa5e64fd137b5d537045c21a41138cfe5bb0a28885788820b5909ba35cbefd6
hourly@2020.02.21-11:57:49 - 43a6bd019b090d302e08b3e43d19d84f59be6b7c95b046e18ece1affac825dcc
latest@2020.02.20-19:41:59 - 943cf6de837e021071e1465dfc7ce3db9d41de2a7be70f6d74d77112b13954a7
hourly@2020.02.20-19:13:08 - d09995b6c749b21ad3e943fda64ba8d2f3815fea454c43f378daf84540aaaeab
```
## Delete snapshot
> Deletes a filesystems' snapshot. If the file blocks contained in the snapshot are no longer referenced anywhere, they will be deleted from the blocck store.
`mfs snapshot delete <snap_hash>`
#### Example
`mfs snapshot delete 4a123...`
## Add mount to mountset
> Adds a filesystem to the mountset, to be mounted at the specified path.
`mfs mountset add <fs_name> <path>`
#### Example
`mfs mountset add foo ~/mount`