in s3plugin/s3plugin.go [322:354]
func DeleteBackup(c *cli.Context) error {
timestamp := c.Args().Get(1)
if timestamp == "" {
return errors.New("delete requires a <timestamp>")
}
if !IsValidTimestamp(timestamp) {
msg := fmt.Sprintf("delete requires a <timestamp> with format "+
"YYYYMMDDHHMMSS, but received: %s", timestamp)
return fmt.Errorf(msg)
}
date := timestamp[0:8]
// note that "backups" is a directory is a fact of how we save, choosing
// to use the 3 parent directories of the source file. That becomes:
// <s3folder>/backups/<date>/<timestamp>
config, sess, err := readConfigAndStartSession(c)
if err != nil {
return err
}
deletePath := filepath.Join(config.Options.Folder, "backups", date, timestamp)
bucket := config.Options.Bucket
gplog.Debug("Delete location = s3://%s/%s", bucket, deletePath)
service := s3.New(sess)
iter := s3manager.NewDeleteListIterator(service, &s3.ListObjectsInput{
Bucket: aws.String(bucket),
Prefix: aws.String(deletePath),
})
batchClient := s3manager.NewBatchDeleteWithClient(service)
return batchClient.Delete(aws.BackgroundContext(), iter)
}