MCPcopy Create free account
hub / github.com/docker/docker-agent / backupDatabase

Function backupDatabase

pkg/session/store.go:561–591  ·  view source on GitHub ↗

backupDatabase moves the database file (and related WAL files) to a backup

(path string)

Source from the content-addressed store, hash-verified

559
560// backupDatabase moves the database file (and related WAL files) to a backup
561func backupDatabase(path string) error {
562 backupPath := path + ".bak"
563
564 slog.Info("Backing up database", "from", path, "to", backupPath)
565
566 // Move the main database file
567 if err := os.Rename(path, backupPath); err != nil {
568 if os.IsNotExist(err) {
569 // No database file to backup, that's fine
570 return nil
571 }
572 return fmt.Errorf("failed to move database file: %w", err)
573 }
574
575 // Also move WAL and SHM files if they exist (SQLite WAL mode artifacts)
576 walPath := path + "-wal"
577 if _, err := os.Stat(walPath); err == nil {
578 if err := os.Rename(walPath, backupPath+"-wal"); err != nil {
579 slog.Warn("Failed to move WAL file", "error", err)
580 }
581 }
582
583 shmPath := path + "-shm"
584 if _, err := os.Stat(shmPath); err == nil {
585 if err := os.Rename(shmPath, backupPath+"-shm"); err != nil {
586 slog.Warn("Failed to move SHM file", "error", err)
587 }
588 }
589
590 return nil
591}
592
593// AddSession adds a new session to the store, including any messages
594func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) error {

Callers 2

NewSQLiteSessionStoreFunction · 0.85
TestBackupDatabaseFunction · 0.85

Calls 2

InfoMethod · 0.80
WarnMethod · 0.80

Tested by 1

TestBackupDatabaseFunction · 0.68