diff options
Diffstat (limited to 'build_vxworks/util/db_hotbackup.c')
-rw-r--r-- | build_vxworks/util/db_hotbackup.c | 127 |
1 files changed, 99 insertions, 28 deletions
diff --git a/build_vxworks/util/db_hotbackup.c b/build_vxworks/util/db_hotbackup.c index a58c7b58..77e391e0 100644 --- a/build_vxworks/util/db_hotbackup.c +++ b/build_vxworks/util/db_hotbackup.c @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved. * * $Id$ */ @@ -15,19 +15,27 @@ #ifndef lint static const char copyright[] = - "Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.\n"; + "Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.\n"; #endif enum which_open { OPEN_ORIGINAL, OPEN_HOT_BACKUP }; int db_hotbackup_env_init __P((DB_ENV **, - char *, char **, char ***, char *, enum which_open, int)); + char *, char *, char **, char ***, char *, enum which_open, int)); int db_hotbackup_main __P((int, char *[])); int db_hotbackup_usage __P((void)); int db_hotbackup_version_check __P((void)); void __db_util_msg __P((const DB_ENV *, const char *)); +void handle_event __P((DB_ENV *, u_int32_t, void *)); const char *progname; +/* + * Hot backup returns DB_EXIT_FAILCHK (3) if it detects that a panic was due to + * another process having crashed or exited from the environment uncleanly. That + * value can be used to indicate that the error is "expected", or at least, not + * due to a problem with db_hotbackup itself. + */ +int failchk_count; void __db_util_msg(dbenv, msgstr) const DB_ENV *dbenv; @@ -37,6 +45,35 @@ void __db_util_msg(dbenv, msgstr) printf("%s: %s\n", progname, msgstr); } +void handle_event(dbenv, event, info) + DB_ENV *dbenv; + u_int32_t event; + void *info; +{ + DB_EVENT_MUTEX_DIED_INFO *mtxdied; + DB_EVENT_FAILCHK_INFO *crash; + + switch (event) { + case DB_EVENT_MUTEX_DIED: + mtxdied = info; + dbenv->errx(dbenv, "DB_EVENT_MUTEX_DIED %.*s", + sizeof(mtxdied->desc), mtxdied->desc); + failchk_count++; + break; + + case DB_EVENT_FAILCHK_PANIC: + crash = info; + dbenv->errx(dbenv, "DB_EVENT_FAILCHK_PANIC %s %.*s", + db_strerror(crash->error), + sizeof(crash->symptom), crash->symptom); + failchk_count++; + break; + default: + break; + } + COMPQUIET(dbenv, NULL); +} + int db_hotbackup(args) char *args; @@ -63,7 +100,8 @@ db_hotbackup_main(argc, argv) u_int data_cnt, data_next; int ch, checkpoint, db_config, debug, env_copy, exitval; int ret, update, verbose; - char *backup_dir, **data_dir, *home, *log_dir, *passwd; + char *backup_dir, **data_dir; + char *home, *home_blob_dir, *log_dir, *passwd; char home_buf[DB_MAXPATHLEN], time_buf[CTIME_BUFLEN]; u_int32_t flags; @@ -77,12 +115,13 @@ db_hotbackup_main(argc, argv) * don't want to care about. There isn't enough output for the calls * to matter. */ - setbuf(stdout, NULL); + (void)setvbuf(stdout, NULL, _IONBF, 0); if ((progname = __db_rpath(argv[0])) == NULL) progname = argv[0]; else ++progname; + failchk_count = 0; if ((ret = db_hotbackup_version_check()) != 0) return (ret); @@ -93,10 +132,10 @@ db_hotbackup_main(argc, argv) checkpoint = db_config = data_cnt = data_next = debug = exitval = update = verbose = 0; data_dir = NULL; - backup_dir = home = passwd = NULL; + backup_dir = home = home_blob_dir = passwd = NULL; log_dir = NULL; __db_getopt_reset = 1; - while ((ch = getopt(argc, argv, "b:cDd:Fgh:l:P:uVv")) != EOF) + while ((ch = getopt(argc, argv, "b:cDd:Fgh:i:l:P:uVv")) != EOF) switch (ch) { case 'b': backup_dir = optarg; @@ -134,6 +173,9 @@ db_hotbackup_main(argc, argv) case 'h': home = optarg; break; + case 'i': + home_blob_dir = optarg; + break; case 'l': log_dir = optarg; break; @@ -235,8 +277,7 @@ db_hotbackup_main(argc, argv) } if (backup_dir == NULL) { fprintf(stderr, "%s: %s", DB_STR("5031", - "no target backup directory specified\n"), - progname); + "no target backup directory specified\n"), progname); exitval = db_hotbackup_usage(); goto clean; } @@ -249,7 +290,7 @@ db_hotbackup_main(argc, argv) } /* Open the source environment. */ - if (db_hotbackup_env_init(&dbenv, home, + if (db_hotbackup_env_init(&dbenv, home, home_blob_dir, (db_config || log_dir != NULL) ? &log_dir : NULL, &data_dir, passwd, OPEN_ORIGINAL, verbose) != 0) goto err; @@ -258,8 +299,8 @@ db_hotbackup_main(argc, argv) if ((ret = dbenv->get_open_flags(dbenv, &flags)) != 0) goto err; if (flags & DB_PRIVATE) { - fprintf(stderr, "%s: %s", progname, DB_STR("5129", - "Cannot copy data from a PRIVATE environment\n")); + fprintf(stderr, "%s: %s", progname, DB_STR("5140", +"The environment does not exist or cannot be opened. \"-F\" is required.\n")); goto err; } } @@ -267,8 +308,7 @@ db_hotbackup_main(argc, argv) if (log_dir != NULL) { if (db_config && __os_abspath(log_dir)) { fprintf(stderr, "%s: %s", progname, DB_STR("5033", - "DB_CONFIG must not contain an absolute " - "path for the log directory\n")); + "DB_CONFIG must not contain an absolute path for the log directory\n")); goto err; } } @@ -325,8 +365,8 @@ db_hotbackup_main(argc, argv) printf(DB_STR_A("5040", "%s: run catastrophic recovery\n", "%s"), backup_dir); } - if (db_hotbackup_env_init(&dbenv, - backup_dir, NULL, NULL, passwd, OPEN_HOT_BACKUP, verbose) != 0) + if (db_hotbackup_env_init(&dbenv, backup_dir, NULL, + NULL, NULL, passwd, OPEN_HOT_BACKUP, verbose) != 0) goto err; /* @@ -352,7 +392,7 @@ db_hotbackup_main(argc, argv) err: exitval = 1; } - if (dbenv != NULL && (ret = dbenv->close(dbenv, 0)) != 0) { + if (dbenv != NULL && ret == 0 && (ret = dbenv->close(dbenv, 0)) != 0) { exitval = 1; fprintf(stderr, "%s: dbenv->close: %s\n", progname, db_strerror(ret)); @@ -380,7 +420,8 @@ clean: if (passwd != NULL) free(passwd); - return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE); + return (failchk_count != 0 ? DB_EXIT_FAILCHK : + exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE); } /* @@ -388,9 +429,9 @@ clean: * Open a database environment. */ int -db_hotbackup_env_init(dbenvp, home, log_dirp, data_dirp, passwd, which, verbose) +db_hotbackup_env_init(dbenvp, home, blob_dir, log_dirp, data_dirp, passwd, which, verbose) DB_ENV **dbenvp; - char *home, **log_dirp, ***data_dirp, *passwd; + char *home, *blob_dir, **log_dirp, ***data_dirp, *passwd; enum which_open which; int verbose; { @@ -410,20 +451,38 @@ db_hotbackup_env_init(dbenvp, home, log_dirp, data_dirp, passwd, which, verbose) return (1); } + if ((ret = dbenv->set_event_notify(dbenv, handle_event)) != 0) { + fprintf(stderr, "%s: DB_ENV->set_event_notify: %s\n", + progname, db_strerror(ret)); + return (1); + } if (verbose) { (void)dbenv->set_verbose(dbenv, DB_VERB_BACKUP, 1); dbenv->set_msgcall(dbenv, __db_util_msg); } dbenv->set_errfile(dbenv, stderr); - setbuf(stderr, NULL); + (void)setvbuf(stderr, NULL, _IONBF, 0); dbenv->set_errpfx(dbenv, progname); + /* Always enable logging blobs. */ + if ((ret = dbenv->log_set_config(dbenv, DB_LOG_BLOB, 1)) != 0) { + dbenv->err(dbenv, ret, "DB_ENV->log_set_config"); + return (1); + } + /* Any created intermediate directories are created private. */ if ((ret = dbenv->set_intermediate_dir_mode(dbenv, "rwx------")) != 0) { dbenv->err(dbenv, ret, "DB_ENV->set_intermediate_dir_mode"); return (1); } + /* Set the blob directory. */ + if (blob_dir != NULL && + (ret = dbenv->set_blob_dir(dbenv, blob_dir)) != 0) { + dbenv->err(dbenv, ret, "DB_ENV->set_blob-dir"); + return (1); + } + /* * If a log directory has been specified, and it's not the same as the * home directory, set it for the environment. @@ -452,7 +511,8 @@ db_hotbackup_env_init(dbenvp, home, log_dirp, data_dirp, passwd, which, verbose) * trim the home directory from the data directory * passed in. */ - (void) sprintf(buf, "%s/%s", home, home); + (void) snprintf(buf, sizeof(buf), "%s/%s", + home, home); homehome = 0; (void)__os_exists(dbenv->env, buf, &homehome); @@ -484,9 +544,9 @@ db_hotbackup_env_init(dbenvp, home, log_dirp, data_dirp, passwd, which, verbose) * fails, we create a private environment and try again. */ if ((ret = dbenv->open(dbenv, home, DB_USE_ENVIRON, 0)) != 0 && - (ret == DB_VERSION_MISMATCH || - (ret = dbenv->open(dbenv, home, DB_CREATE | - DB_INIT_LOG | DB_INIT_TXN | DB_PRIVATE | DB_USE_ENVIRON, + (ret == DB_VERSION_MISMATCH || ret == DB_REP_LOCKOUT || + (ret = dbenv->open(dbenv, home, DB_CREATE | DB_INIT_LOG | + DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0)) { dbenv->err(dbenv, ret, "DB_ENV->open: %s", home); return (1); @@ -501,9 +561,19 @@ db_hotbackup_env_init(dbenvp, home, log_dirp, data_dirp, passwd, which, verbose) "%s\n"), progname); return (db_hotbackup_usage()); } else { - fprintf(stderr, "%s: %s", DB_STR("5058", + /* + * Do we have -l and an existing DB_CONFIG? + * That is a usage problem, but for backward + * compatibility, keep going if log_dir happens + * to be the same as the DB_CONFIG path. + */ + (void)snprintf(buf, sizeof(buf), "%s%c%s", + home, PATH_SEPARATOR[0], "DB_CONFIG"); + if (__os_exists(dbenv->env, buf, NULL) == 0) + fprintf(stderr, + "%s: %s", DB_STR("5141", "use of -l with DB_CONFIG file is deprecated\n"), - progname); + progname); } } if (data_dirp != NULL && *data_dirp == NULL) @@ -542,7 +612,8 @@ int db_hotbackup_usage() { (void)fprintf(stderr, "usage: %s [-cDuVv]\n\t%s\n", progname, - "[-d data_dir ...] [-h home] [-l log_dir] [-P password] -b backup_dir"); + "[-d data_dir ...] [-i home_blob_dir] [-h home] [-l log_dir] " + "[-P password] -b backup_dir"); return (EXIT_FAILURE); } |