summaryrefslogtreecommitdiff
path: root/src/redis.c
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-05-09 12:06:06 -0400
committerMatt Stancliff <matt@genges.com>2015-01-28 11:18:16 -0500
commit145473acc5798a499a0f37e42df48a014a3955c1 (patch)
treede2924dd84e586447c0fe289cd8b7d9ff4a17086 /src/redis.c
parent9802ec3c83cf6b61edad50bc41ddb3f6fdb13c6f (diff)
downloadredis-145473acc5798a499a0f37e42df48a014a3955c1.tar.gz
Convert check-dump to Redis check-rdb mode
redis-check-dump is now named redis-check-rdb and it runs as a mode of redis-server instead of an independent binary. You can now use 'redis-server redis.conf --check-rdb' to check the RDB defined in redis.conf. Using argument --check-rdb checks the RDB and exits. We could potentially also allow the server to continue starting if the RDB check succeeds. This change also enables us to use RDB checking programatically from inside Redis for certain failure conditions.
Diffstat (limited to 'src/redis.c')
-rw-r--r--src/redis.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/redis.c b/src/redis.c
index 13df8d28e..24739cc3c 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -3550,6 +3550,17 @@ int checkForSentinelMode(int argc, char **argv) {
return 0;
}
+/* Returns 1 if there is --check-rdb among the arguments or if
+ * argv[0] is exactly "redis-check-rdb". */
+int checkForCheckRDBMode(int argc, char **argv) {
+ int j;
+
+ if (strstr(argv[0],"redis-check-rdb") != NULL) return 1;
+ for (j = 1; j < argc; j++)
+ if (!strcmp(argv[j],"--check-rdb")) return 1;
+ return 0;
+}
+
/* Function called at startup to load RDB or AOF file in memory. */
void loadDataFromDisk(void) {
long long start = ustime();
@@ -3766,6 +3777,11 @@ int main(int argc, char **argv) {
while(j != argc) {
if (argv[j][0] == '-' && argv[j][1] == '-') {
/* Option name */
+ if (!strcmp(argv[j], "--check-rdb")) {
+ /* Argument has no options, need to skip for parsing. */
+ j++;
+ continue;
+ }
if (sdslen(options)) options = sdscat(options,"\n");
options = sdscat(options,argv[j]+2);
options = sdscat(options," ");
@@ -3791,9 +3807,17 @@ int main(int argc, char **argv) {
redisLog(REDIS_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis");
}
+ if (checkForCheckRDBMode(argc, argv)) {
+ redisLog(REDIS_WARNING, "Checking RDB file %s", server.rdb_filename);
+ redisLog(REDIS_WARNING, "To check different RDB file: "
+ "redis-check-rdb --dbfilename <dump.rdb>");
+ exit(redis_check_rdb(server.rdb_filename));
+ }
+
server.supervised = redisIsSupervised(server.supervised_mode);
int background = server.daemonize && !server.supervised;
if (background) daemonize();
+
initServer();
if (background || server.pidfile) createPidFile();
redisSetProcTitle(argv[0]);