2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
11 static const char copyright[] =
12 "@(#) Copyright (c) 1997\n\
13 Sleepycat Software Inc. All rights reserved.\n";
14 static const char sccsid[] = "@(#)db_checkpoint.c 10.11 (Sleepycat) 8/27/97";
17 #ifndef NO_SYSTEM_INCLUDES
18 #include <sys/types.h>
36 #include "common_ext.h"
38 char *check __P((DB_ENV *, long, long));
39 int checkpoint __P((DB_ENV *, char *, int));
40 DB_ENV *db_init __P((char *));
41 int logpid __P((char *, int));
42 int main __P((int, char *[]));
43 void onint __P((int));
44 void siginit __P((void));
45 void usage __P((void));
48 time_t now; /* Checkpoint time. */
50 *progname = "db_checkpoint"; /* Program name. */
61 long kbytes, minutes, seconds;
62 int ch, rval, verbose;
65 home = logfile = NULL;
68 while ((ch = getopt(argc, argv, "h:k:L:p:v")) != EOF)
74 get_long(optarg, 1, LONG_MAX, &kbytes);
80 get_long(optarg, 1, LONG_MAX, &minutes);
95 if (kbytes == 0 && minutes == 0) {
96 warnx("at least one of -k and -p must be specified");
100 /* Initialize the environment. */
101 dbenv = db_init(home);
103 if (logfile != NULL && logpid(logfile, 1)) {
104 (void)db_appexit(dbenv);
109 * If we have only a time delay, then we'll sleep the right amount
110 * to wake up when a checkpoint is necessary. If we have a "kbytes"
111 * field set, then we'll check every 30 seconds.
114 seconds = kbytes != 0 ? 30 : minutes * 60;
115 while (!interrupted) {
116 (void)__db_sleep(seconds, 0);
120 printf("checkpoint: %s", ctime(&now));
122 rval = txn_checkpoint(dbenv->tx_info, kbytes, minutes);
129 "checkpoint did not finish, retrying");
130 (void)__db_sleep(2, 0);
131 rval = txn_checkpoint(dbenv->tx_info, 0, 0);
137 if (logfile != NULL && logpid(logfile, 0))
141 (void)signal(interrupted, SIG_DFL);
142 (void)raise(interrupted);
146 return (db_appexit(dbenv) || rval ? 1 : 0);
151 * Initialize the environment.
159 if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) {
163 dbenv->db_errfile = stderr;
164 dbenv->db_errpfx = progname;
166 if ((errno = db_appinit(home, NULL, dbenv,
167 DB_INIT_LOG | DB_INIT_TXN | DB_INIT_MPOOL | DB_USE_ENVIRON)) != 0)
168 err(1, "db_appinit");
170 if (memp_register(dbenv->mp_info,
171 DB_FTYPE_BTREE, __bam_pgin, __bam_pgout) ||
172 memp_register(dbenv->mp_info,
173 DB_FTYPE_HASH, __ham_pgin, __ham_pgout)) {
174 (void)db_appexit(dbenv);
176 "db_appinit: failed to register access method functions");
186 * Log that we're running.
189 logpid(fname, is_open)
197 if ((fp = fopen(fname, "w")) == NULL) {
203 "%s: %lu %s", progname, (u_long)getpid(), ctime(&now));
212 * Initialize the set of signals for which we want to clean up.
213 * Generally, we try not to leave the shared regions locked if
220 (void)signal(SIGHUP, onint);
222 (void)signal(SIGINT, onint);
224 (void)signal(SIGKILL, onint);
226 (void)signal(SIGTERM, onint);
231 * Interrupt signal handler.
237 if ((interrupted = signo) == 0)
238 interrupted = SIGINT;
244 (void)fprintf(stderr,
245 "usage: db_checkpoint [-v] [-h home] [-k kbytes] [-L file] [-p min]\n");