Skip to content

Commit 0b804d3

Browse files
committed
cli: fix copy to missing startup-config file
Fixes #981 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 4f31362 commit 0b804d3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/bin/copy.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,18 @@ static int copy(const char *src, const char *dst, const char *remote_user)
287287
} else {
288288
/* Direct copy for other datastores (no callbacks needed) */
289289
rc = sr_copy_config(sess, NULL, srcds->datastore, timeout * 1000);
290-
if (rc)
290+
if (rc) {
291291
emsg(sess, ERRMSG "unable to copy configuration, err %d: %s\n", rc, sr_strerror(rc));
292-
else
293-
set_owner(dstds->path, user);
292+
} else {
293+
/* Export datastore to backing file if it has one */
294+
if (dstds->path) {
295+
rc = systemf("sysrepocfg -d %s -X%s -f json", dstds->sysrepocfg, dstds->path);
296+
if (rc)
297+
fprintf(stderr, ERRMSG "failed saving %s to %s\n", srcds->name, dstds->path);
298+
else
299+
set_owner(dstds->path, user);
300+
}
301+
}
294302
}
295303
}
296304
rc = sr_disconnect(conn);

0 commit comments

Comments
 (0)