MCPcopy
hub / github.com/basecamp/once / backupToWriter

Method backupToWriter

internal/docker/application_backup.go:154–185  ·  view source on GitHub ↗

Private

(ctx context.Context, w io.Writer)

Source from the content-addressed store, hash-verified

152// Private
153
154func (a *Application) backupToWriter(ctx context.Context, w io.Writer) error {
155 containerName, err := a.ContainerName(ctx)
156 if err != nil {
157 return fmt.Errorf("getting container name: %w", err)
158 }
159
160 found, hookErr := a.tryHookScript(ctx, containerName, "pre-backup")
161 if !found && hookErr != nil {
162 return fmt.Errorf("checking for pre-backup hook: %w", hookErr)
163 }
164
165 vol, err := a.Volume(ctx)
166 if err != nil {
167 return fmt.Errorf("getting volume: %w", err)
168 }
169
170 gw := gzip.NewWriter(w)
171 defer gw.Close()
172 tw := tar.NewWriter(gw)
173 defer tw.Close()
174
175 if err := writeTarEntry(tw, backupAppSettingsEntry, []byte(a.Settings.Marshal())); err != nil {
176 return fmt.Errorf("writing application settings: %w", err)
177 }
178
179 if err := writeTarEntry(tw, backupVolSettingsEntry, []byte(vol.Settings.Marshal())); err != nil {
180 return fmt.Errorf("writing volume settings: %w", err)
181 }
182
183 needsPause := !found || hookErr != nil
184 return a.copyVolumeData(ctx, containerName, tw, needsPause)
185}
186
187func (a *Application) copyVolumeData(ctx context.Context, containerName string, tw *tar.Writer, pause bool) (returnErr error) {
188 if pause {

Callers 1

BackupToFileMethod · 0.95

Calls 7

ContainerNameMethod · 0.95
tryHookScriptMethod · 0.95
VolumeMethod · 0.95
copyVolumeDataMethod · 0.95
writeTarEntryFunction · 0.85
CloseMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected