Private
(ctx context.Context, w io.Writer)
| 152 | // Private |
| 153 | |
| 154 | func (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 | |
| 187 | func (a *Application) copyVolumeData(ctx context.Context, containerName string, tw *tar.Writer, pause bool) (returnErr error) { |
| 188 | if pause { |
no test coverage detected