1 /* mdb_copy.c - memory-mapped database backup tool */
3 * Copyright 2012 Howard Chu, Symas Corp.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted only as authorized by the OpenLDAP
10 * A copy of this license is available in the file LICENSE in the
11 * top-level directory of the distribution or, alternatively, at
12 * <http://www.OpenLDAP.org/license.html>.
16 #define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
30 int main(int argc,char * argv[])
34 const char *progname = argv[0], *act;
35 unsigned flags = MDB_RDONLY;
37 for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
38 if (argv[1][1] == 'n' && argv[1][2] == '\0')
39 flags |= MDB_NOSUBDIR;
44 if (argc<2 || argc>3) {
45 fprintf(stderr, "usage: %s [-n] srcpath [dstpath]\n", progname);
50 signal(SIGPIPE, sighandle);
53 signal(SIGHUP, sighandle);
55 signal(SIGINT, sighandle);
56 signal(SIGTERM, sighandle);
58 act = "opening environment";
59 rc = mdb_env_create(&env);
60 if (rc == MDB_SUCCESS) {
61 rc = mdb_env_open(env, argv[1], flags, 0);
63 if (rc == MDB_SUCCESS) {
66 rc = mdb_env_copyfd(env, MDB_STDOUT);
68 rc = mdb_env_copy(env, argv[2]);
71 fprintf(stderr, "%s: %s failed, error %d (%s)\n",
72 progname, act, rc, mdb_strerror(rc));
75 return rc ? EXIT_FAILURE : EXIT_SUCCESS;