MCPcopy Create free account
hub / github.com/apecloud/myduckserver / executeBackup

Method executeBackup

pgserver/backup_handler.go:91–126  ·  view source on GitHub ↗
(backupConfig *BackupConfig)

Source from the content-addressed store, hash-verified

89}
90
91func (h *ConnectionHandler) executeBackup(backupConfig *BackupConfig) (string, error) {
92 sqlCtx, err := h.duckHandler.sm.NewContextWithQuery(context.Background(), h.mysqlConn, "")
93 if err != nil {
94 return "", fmt.Errorf("failed to create context for query: %w", err)
95 }
96
97 if err := stopAllReplication(sqlCtx); err != nil {
98 return "", fmt.Errorf("failed to stop replication: %w", err)
99 }
100
101 if err := doCheckpoint(sqlCtx); err != nil {
102 return "", fmt.Errorf("failed to do checkpoint: %w", err)
103 }
104
105 err = h.restartServer(true)
106 if err != nil {
107 return "", err
108 }
109
110 msg, err := backupConfig.StorageConfig.UploadFile(
111 h.server.Provider.DataDir(), backupConfig.DbName+".db", backupConfig.RemotePath)
112 if err != nil {
113 return "", err
114 }
115
116 err = h.restartServer(false)
117 if err != nil {
118 return "", fmt.Errorf("backup finished: %s, but failed to restart server: %w", msg, err)
119 }
120
121 if err = startAllReplication(sqlCtx); err != nil {
122 return "", fmt.Errorf("backup finished: %s, but failed to start replication: %w", msg, err)
123 }
124
125 return msg, nil
126}
127
128func (h *ConnectionHandler) restartServer(readOnly bool) error {
129 provider := h.server.Provider

Callers 1

runMethod · 0.95

Calls 6

restartServerMethod · 0.95
stopAllReplicationFunction · 0.85
doCheckpointFunction · 0.85
startAllReplicationFunction · 0.85
DataDirMethod · 0.65
UploadFileMethod · 0.45

Tested by

no test coverage detected