MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / backupDb

Function backupDb

src/db.cpp:650–673  ·  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

648/* Store a backup of the database for later use, and put an empty one
649 * instead of it. */
650const dbBackup *backupDb(void) {
651 dbBackup *backup = new dbBackup();
652
653 backup->dbarray = (const redisDbPersistentDataSnapshot**)zmalloc(sizeof(redisDbPersistentDataSnapshot*) * cserver.dbnum);
654 for (int i=0; i<cserver.dbnum; i++) {
655 backup->dbarray[i] = g_pserver->db[i]->createSnapshot(LLONG_MAX, false);
656 }
657
658 /* Backup cluster slots to keys map if enable cluster. */
659 if (g_pserver->cluster_enabled) {
660 backup->slots_to_keys = g_pserver->cluster->slots_to_keys;
661 memcpy(backup->slots_keys_count, g_pserver->cluster->slots_keys_count,
662 sizeof(g_pserver->cluster->slots_keys_count));
663 g_pserver->cluster->slots_to_keys = raxNew();
664 memset(g_pserver->cluster->slots_keys_count, 0,
665 sizeof(g_pserver->cluster->slots_keys_count));
666 }
667
668 moduleFireServerEvent(REDISMODULE_EVENT_REPL_BACKUP,
669 REDISMODULE_SUBEVENT_REPL_BACKUP_CREATE,
670 NULL);
671
672 return backup;
673}
674
675/* Discard a previously created backup, this can be slow (similar to FLUSHALL)
676 * Arguments are similar to the ones of emptyDb, see EMPTYDB_ flags. */

Callers 1

disklessLoadMakeBackupFunction · 0.85

Calls 4

zmallocFunction · 0.85
raxNewFunction · 0.85
moduleFireServerEventFunction · 0.85
createSnapshotMethod · 0.45

Tested by

no test coverage detected