]> git.sur5r.net Git - openldap/blob - libraries/libmdb/mdb_copy.c
Add mdb_copy for backing up a DB environment
[openldap] / libraries / libmdb / mdb_copy.c
1 /* mdb_copy.c - memory-mapped database backup tool */
2 /*
3  * Copyright 2012 Howard Chu, Symas Corp.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.
9  *
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>.
13  */
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <time.h>
17 #include "mdb.h"
18
19 int main(int argc,char * argv[])
20 {
21         int rc;
22         MDB_env *env;
23         char *envname = argv[1];
24
25         if (argc != 3) {
26                 fprintf(stderr, "usage: %s srcpath dstpath\n", argv[0]);
27                 exit(EXIT_FAILURE);
28         }
29
30         rc = mdb_env_create(&env);
31
32         rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
33         if (rc) {
34                 printf("mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
35         } else {
36                 rc = mdb_env_copy(env, argv[2]);
37                 if (rc)
38                         printf("mdb_env_copy failed, error %d %s\n", rc, mdb_strerror(rc));
39         }
40         mdb_env_close(env);
41
42         return rc ? EXIT_FAILURE : EXIT_SUCCESS;
43 }