1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(backup): Add backup/restore to the server

This commit is contained in:
Dmitry Salakhov 2021-04-06 22:08:43 +12:00
parent c04bbb5775
commit a3ec2f8e85
65 changed files with 2394 additions and 564 deletions

View file

@ -1,6 +1,7 @@
package snapshot
import (
"context"
"log"
"time"
@ -16,10 +17,11 @@ type Service struct {
snapshotIntervalInSeconds float64
dockerSnapshotter portainer.DockerSnapshotter
kubernetesSnapshotter portainer.KubernetesSnapshotter
shutdownCtx context.Context
}
// NewService creates a new instance of a service
func NewService(snapshotInterval string, dataStore portainer.DataStore, dockerSnapshotter portainer.DockerSnapshotter, kubernetesSnapshotter portainer.KubernetesSnapshotter) (*Service, error) {
func NewService(snapshotInterval string, dataStore portainer.DataStore, dockerSnapshotter portainer.DockerSnapshotter, kubernetesSnapshotter portainer.KubernetesSnapshotter, shutdownCtx context.Context) (*Service, error) {
snapshotFrequency, err := time.ParseDuration(snapshotInterval)
if err != nil {
return nil, err
@ -30,6 +32,7 @@ func NewService(snapshotInterval string, dataStore portainer.DataStore, dockerSn
snapshotIntervalInSeconds: snapshotFrequency.Seconds(),
dockerSnapshotter: dockerSnapshotter,
kubernetesSnapshotter: kubernetesSnapshotter,
shutdownCtx: shutdownCtx,
}, nil
}
@ -43,7 +46,7 @@ func (service *Service) Start() {
service.startSnapshotLoop()
}
func (service *Service) stop() {
func (service *Service) Stop() {
if service.refreshSignal == nil {
return
}
@ -55,7 +58,7 @@ func (service *Service) stop() {
// SetSnapshotInterval sets the snapshot interval and resets the service
func (service *Service) SetSnapshotInterval(snapshotInterval string) error {
service.stop()
service.Stop()
snapshotFrequency, err := time.ParseDuration(snapshotInterval)
if err != nil {
@ -132,9 +135,12 @@ func (service *Service) startSnapshotLoop() error {
if err != nil {
log.Printf("[ERROR] [internal,snapshot] [message: background schedule error (endpoint snapshot).] [error: %s]", err)
}
case <-service.shutdownCtx.Done():
log.Println("[DEBUG] [internal,snapshot] [message: shutting down snapshotting]")
ticker.Stop()
return
case <-service.refreshSignal:
log.Println("[DEBUG] [internal,snapshot] [message: shutting down Snapshot service]")
log.Println("[DEBUG] [internal,snapshot] [message: shutting down snapshotting]")
ticker.Stop()
return
}