1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2021 by Allan Jude.
16#
17
18. $STF_SUITE/include/libtest.shlib
19
20#
21# Description:
22# zdb -r <dataset> <path> <destination>
23# Will extract <path> (relative to <dataset>) to the file <destination>
24# Similar to -R, except it does the work for you to find each record
25#
26# Strategy:
27# 1. Create a pool
28# 2. Write some data to a file
29# 3. Append to the file so it isn't an divisible by 2
30# 4. Extract the file
31# 5. Compare the file to the original
32#
33
34function cleanup
35{
36	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
37	rm $tmpfile
38}
39
40log_assert "Verify zdb -r <dataset> <path> <dest> extract the correct data."
41log_onexit cleanup
42init_data=$TESTDIR/file1
43tmpfile="$TEST_BASE_DIR/zdb-recover"
44write_count=8
45blksize=131072
46verify_runnable "global"
47verify_disk_count "$DISKS" 2
48
49default_mirror_setup_noexit $DISKS
50file_write -o create -w -f $init_data -b $blksize -c $write_count
51log_must echo "zfs" >> $init_data
52sync_pool $TESTPOOL
53
54output=$(zdb -r $TESTPOOL/$TESTFS file1 $tmpfile)
55log_must cmp $init_data $tmpfile
56
57log_pass "zdb -r <dataset> <path> <dest> extracts the correct data."
58