MCPcopy Create free account
hub / github.com/F-Stack/f-stack / backupDb

Function backupDb

app/redis-6.2.6/src/db.c:467–493  ·  view source on GitHub ↗

Store a backup of the database for later use, and put an empty one * instead of it. */

Source from the content-addressed store, hash-verified

465/* Store a backup of the database for later use, and put an empty one
466 * instead of it. */
467dbBackup *backupDb(void) {
468 dbBackup *backup = zmalloc(sizeof(dbBackup));
469
470 /* Backup main DBs. */
471 backup->dbarray = zmalloc(sizeof(redisDb)*server.dbnum);
472 for (int i=0; i<server.dbnum; i++) {
473 backup->dbarray[i] = server.db[i];
474 server.db[i].dict = dictCreate(&dbDictType,NULL);
475 server.db[i].expires = dictCreate(&dbExpiresDictType,NULL);
476 }
477
478 /* Backup cluster slots to keys map if enable cluster. */
479 if (server.cluster_enabled) {
480 backup->slots_to_keys = server.cluster->slots_to_keys;
481 memcpy(backup->slots_keys_count, server.cluster->slots_keys_count,
482 sizeof(server.cluster->slots_keys_count));
483 server.cluster->slots_to_keys = raxNew();
484 memset(server.cluster->slots_keys_count, 0,
485 sizeof(server.cluster->slots_keys_count));
486 }
487
488 moduleFireServerEvent(REDISMODULE_EVENT_REPL_BACKUP,
489 REDISMODULE_SUBEVENT_REPL_BACKUP_CREATE,
490 NULL);
491
492 return backup;
493}
494
495/* Discard a previously created backup, this can be slow (similar to FLUSHALL)
496 * Arguments are similar to the ones of emptyDb, see EMPTYDB_ flags. */

Callers 1

disklessLoadMakeBackupFunction · 0.85

Calls 6

zmallocFunction · 0.85
raxNewFunction · 0.85
memsetFunction · 0.85
moduleFireServerEventFunction · 0.85
dictCreateFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected