Skip to content

Commit

Permalink
=> openzfs#2668: turbo/issue-2666 - Allow for "zfs receive" to skip e…
Browse files Browse the repository at this point in the history
…xisting snapshots

by adding the option "-s" to zfs receive.

Signed-off-by: Turbo Fredriksson <[email protected]>

Closes: openzfs#2666
  • Loading branch information
FransUrbo committed Sep 5, 2014
1 parent c3d879d commit 8cfa625
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
11 changes: 7 additions & 4 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ get_usage(zfs_help_t idx)
case HELP_PROMOTE:
return (gettext("\tpromote <clone-filesystem>\n"));
case HELP_RECEIVE:
return (gettext("\treceive [-vnFu] <filesystem|volume|"
return (gettext("\treceive [-vnFus] <filesystem|volume|"
"snapshot>\n"
"\treceive [-vnFu] [-d | -e] <filesystem>\n"));
"\treceive [-vnFus] [-d | -e] <filesystem>\n"));
case HELP_RENAME:
return (gettext("\trename [-f] <filesystem|volume|snapshot> "
"<filesystem|volume|snapshot>\n"
Expand Down Expand Up @@ -3853,7 +3853,7 @@ zfs_do_send(int argc, char **argv)
}

/*
* zfs receive [-vnFu] [-d | -e] <fs@snap>
* zfs receive [-vnFus] [-d | -e] <fs@snap>
*
* Restore a backup stream from stdin.
*/
Expand All @@ -3864,8 +3864,11 @@ zfs_do_receive(int argc, char **argv)
recvflags_t flags = { 0 };

/* check options */
while ((c = getopt(argc, argv, ":denuvF")) != -1) {
while ((c = getopt(argc, argv, ":denuvFs")) != -1) {
switch (c) {
case 's':
flags.skip = B_TRUE;
break;
case 'd':
flags.isprefix = B_TRUE;
break;
Expand Down
3 changes: 3 additions & 0 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ typedef struct recvflags {

/* do not mount file systems as they are extracted (private) */
boolean_t nomount;

/* skip existing snapshots */
boolean_t skip;
} recvflags_t;

extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t *,
Expand Down
13 changes: 12 additions & 1 deletion lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2825,7 +2825,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
* away (and have therefore specified -F and removed any
* snapshots).
*/
if (stream_wantsnewfs) {
if (stream_wantsnewfs && !flags->skip) {
if (!flags->force) {
zcmd_free_nvlists(&zc);
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
Expand Down Expand Up @@ -2913,6 +2913,17 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
zc.zc_begin_record = drr_noswap->drr_u.drr_begin;
zc.zc_cookie = infd;
zc.zc_guid = flags->force;

if (zfs_dataset_exists(hdl, zc.zc_value, ZFS_TYPE_SNAPSHOT) &&
flags->skip) {
(void) printf("skipping snapshot %s - %s already exists\n",
drrb->drr_toname, zc.zc_value);
(void) fflush(stdout);

zcmd_free_nvlists(&zc);
return (recv_skip(hdl, infd, flags->byteswap));
}

This comment has been minimized.

Copy link
@behlendorf

behlendorf Sep 10, 2014

Isn't this case already handled slightly farther down at line 2983. Existing snapshots should be skipped.

This comment has been minimized.

Copy link
@FransUrbo

FransUrbo via email Sep 10, 2014

Author Owner
if (flags->verbose) {
(void) printf("%s %s stream of %s into %s\n",
flags->dryrun ? "would receive" : "receiving",
Expand Down
19 changes: 15 additions & 4 deletions man/man8/zfs.8
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ zfs \- configures ZFS file systems

.LP
.nf
\fBzfs\fR \fBreceive | recv\fR [\fB-vnFu\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
\fBzfs\fR \fBreceive | recv\fR [\fB-vnFus\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
.fi

.LP
.nf
\fBzfs\fR \fBreceive | recv\fR [\fB-vnFu\fR] [\fB-d\fR|\fB-e\fR] \fIfilesystem\fR
\fBzfs\fR \fBreceive | recv\fR [\fB-vnFus\fR] [\fB-d\fR|\fB-e\fR] \fIfilesystem\fR
.fi

.LP
Expand Down Expand Up @@ -3001,11 +3001,11 @@ or the origin's origin, etc.
.ne 2
.mk
.na
\fB\fBzfs receive\fR [\fB-vnFu\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR
\fB\fBzfs receive\fR [\fB-vnFus\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR
.ad
.br
.na
\fB\fBzfs receive\fR [\fB-vnFu\fR] [\fB-d\fR|\fB-e\fR] \fIfilesystem\fR\fR
\fB\fBzfs receive\fR [\fB-vnFus\fR] [\fB-d\fR|\fB-e\fR] \fIfilesystem\fR\fR
.ad
.sp .6
.RS 4n
Expand Down Expand Up @@ -3101,6 +3101,17 @@ then the receiving system must have that feature enabled as well. See
\fBzpool-features\fR(5) for details on ZFS feature flags and the
\fBembedded_data\fR feature.
.RE

.sp
.ne 2
.mk
.na
\fB\fB-s\fR\fR
.ad
.sp .6
.RS 4n
Skip existing snapshots in a stream.
.RE
.RE

.sp
Expand Down

0 comments on commit 8cfa625

Please sign in to comment.