]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_-e.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_-e.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
9 #
10 # A full copy of the text of the CDDL should have accompanied this
11 # source.  A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16
17 #
18 # Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
19 #
20
21 . $STF_SUITE/include/libtest.shlib
22
23 #
24 # DESCRIPTION:
25 # ZFS receive '-e' option can be used to discard all but the last element of
26 # the sent snapshot's file system name
27 #
28 # STRATEGY:
29 # 1. Create a filesystem with children and snapshots
30 # 2. Verify 'zfs receive -e' rejects invalid options
31 # 3. Verify 'zfs receive -e' can receive the root dataset
32 # 4. Verify 'zfs receive -e' can receive a replication stream
33 # 5. Verify 'zfs receive -e' can receive an incremental replication stream
34 #
35
36 verify_runnable "both"
37
38 function cleanup
39 {
40         destroy_pool "$poolname"
41         log_must rm -f "$vdevfile"
42         log_must rm -f "$streamfile"
43 }
44
45 log_assert "ZFS receive '-e' option can be used to discard all but the last"\
46         "element of the sent snapshot's file system name"
47 log_onexit cleanup
48
49 poolname="$TESTPOOL-zfsrecv"
50 recvfs="$poolname/recv"
51 vdevfile="$TEST_BASE_DIR/vdevfile.$$"
52 streamfile="$TEST_BASE_DIR/streamfile.$$"
53
54 #
55 # 1. Create a filesystem with children and snapshots
56 # NOTE: set "mountpoint=none" just to speed up the test process
57 #
58 log_must truncate -s $MINVDEVSIZE "$vdevfile"
59 log_must zpool create -O mountpoint=none "$poolname" "$vdevfile"
60 log_must zfs create -p "$poolname/fs/a/b"
61 log_must zfs create "$recvfs"
62 log_must zfs snapshot -r "$poolname@full"
63 log_must zfs snapshot -r "$poolname@incr"
64
65 #
66 # 2. Verify 'zfs receive -e' rejects invalid options
67 #
68 log_must eval "zfs send $poolname/fs@full > $streamfile"
69 log_mustnot eval "zfs receive -e < $streamfile"
70 log_mustnot eval "zfs receive -e $recvfs@snap < $streamfile"
71 log_mustnot eval "zfs receive -e $recvfs/1/2/3 < $streamfile"
72 log_mustnot eval "zfs receive -A -e $recvfs < $streamfile"
73 log_mustnot eval "zfs receive -e -d $recvfs < $streamfile"
74
75 #
76 # 3. 'zfs receive -e' can receive the root dataset
77 #
78 recvfs_rootds="$recvfs/rootds"
79 log_must zfs create "$recvfs_rootds"
80 log_must eval "zfs send $poolname@full > $streamfile"
81 log_must eval "zfs receive -e $recvfs_rootds < $streamfile"
82 log_must datasetexists "$recvfs_rootds/$poolname"
83 log_must snapexists "$recvfs_rootds/$poolname@full"
84
85 #
86 # 4. 'zfs receive -e' can receive a replication stream
87 #
88 recvfs_fs="$recvfs/fs"
89 log_must zfs create "$recvfs_fs"
90 log_must eval "zfs send -R $poolname/fs/a@full > $streamfile"
91 log_must eval "zfs receive -e $recvfs_fs < $streamfile"
92 log_must datasetexists "$recvfs_fs/a"
93 log_must datasetexists "$recvfs_fs/a/b"
94 log_must snapexists "$recvfs_fs/a@full"
95 log_must snapexists "$recvfs_fs/a/b@full"
96
97 #
98 # 5. 'zfs receive -e' can receive an incremental replication stream
99 #
100 log_must eval "zfs send -R -i full $poolname/fs/a@incr > $streamfile"
101 log_must eval "zfs receive -e $recvfs_fs < $streamfile"
102 log_must snapexists "$recvfs_fs/a@incr"
103 log_must snapexists "$recvfs_fs/a/b@incr"
104
105 log_pass "ZFS receive '-e' discards all but the last element of the sent"\
106         "snapshot's file system name as expected"