37baabe134
* EE-384: add endpoint to set auto backup (#224) * EE-383: add endpoint to fetch backup settings (#231) * add get backup settings handler * add api docs desc * EE-382: restore from s3 (#233) * EE-381: add GET backup status handler (#234) * EE-385: Add S3 backup execute handler (#237) * add s3 backup execute handler * refactories inside `./api/backup/backup_scheduler.go` and `./api/backup/backup_scheduler.go` * fix tests * EE-375: added backup to S3 form * EE-376: added restore from S3 form * EE-377: Update Home screen to display last backup run status * update backup service with back end endpoints. * restart admin monitor during s3 restores * use go 1.13 * go 1.13 compatibility * EE-375: added cron-validator lib * EE-375: using enum to compare form types * EE-375: validate cron rule field * try fix windows build * EE-375 EE-376 backup and restore forms validation changes * fix(autobackup): update autobackup settings validation rules (#260) * fix(autobackup): automate backup to s3 fe update (#261) * EE-292: fixed typo in property. * EE-292: updated auto backup front end validation. * EE-292: updated lib to validate cron rule in front end * fix dependencies * bumped libcompose version Co-authored-by: Hui <arris_li@hotmail.com> Co-authored-by: Felix Han <felix.han@portainer.io> Co-authored-by: fhanportainer <79428273+fhanportainer@users.noreply.github.com>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package s3backup
|
|
|
|
import (
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/bolt/errors"
|
|
"github.com/portainer/portainer/api/bolt/internal"
|
|
)
|
|
|
|
const (
|
|
bucketName = "s3backup"
|
|
statusKey = "lastRunStatus"
|
|
settingsKey = "settings"
|
|
)
|
|
|
|
type Service struct {
|
|
connection *internal.DbConnection
|
|
}
|
|
|
|
// NewService creates a new service and ensures corresponding bucket exist
|
|
func NewService(connection *internal.DbConnection) (*Service, error) {
|
|
err := internal.CreateBucket(connection, bucketName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Service{
|
|
connection: connection,
|
|
}, nil
|
|
}
|
|
|
|
// GetStatus returns the status of the last scheduled backup run
|
|
func (s *Service) GetStatus() (portainer.S3BackupStatus, error) {
|
|
var status portainer.S3BackupStatus
|
|
err := internal.GetObject(s.connection, bucketName, []byte(statusKey), &status)
|
|
if err == errors.ErrObjectNotFound {
|
|
return status, nil
|
|
}
|
|
|
|
return status, err
|
|
}
|
|
|
|
// DropStatus deletes the status of the last sheduled backup run
|
|
func (s *Service) DropStatus() error {
|
|
return internal.DeleteObject(s.connection, bucketName, []byte(statusKey))
|
|
}
|
|
|
|
// UpdateStatus upserts a status of the last scheduled backup run
|
|
func (s *Service) UpdateStatus(status portainer.S3BackupStatus) error {
|
|
return internal.UpdateObject(s.connection, bucketName, []byte(statusKey), status)
|
|
}
|
|
|
|
// UpdateSettings updates stored s3 backup settings
|
|
func (s *Service) UpdateSettings(settings portainer.S3BackupSettings) error {
|
|
return internal.UpdateObject(s.connection, bucketName, []byte(settingsKey), settings)
|
|
}
|
|
|
|
// GetSettings returns stored s3 backup settings
|
|
func (s *Service) GetSettings() (portainer.S3BackupSettings, error) {
|
|
var settings portainer.S3BackupSettings
|
|
err := internal.GetObject(s.connection, bucketName, []byte(settingsKey), &settings)
|
|
if err == errors.ErrObjectNotFound {
|
|
return settings, nil
|
|
}
|
|
|
|
return settings, err
|
|
}
|