{backup,snapshot}: Log and display in control
This commit is contained in:
parent
3b112f1b8e
commit
630da9e12f
17 changed files with 294 additions and 44 deletions
|
|
@ -1,51 +0,0 @@
|
|||
package dis
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// ShouldPrune determines if a file with the provided modtime
|
||||
func (dis *Distillery) ShouldPrune(modtime time.Time) bool {
|
||||
return time.Since(modtime) > time.Duration(dis.Config.MaxBackupAge)*24*time.Hour
|
||||
}
|
||||
|
||||
// PruneBackups prunes all backups older than the maximum backup age
|
||||
func (dis *Distillery) PruneBackups(io stream.IOStream) error {
|
||||
sPath := dis.SnapshotManager().ArchivePath()
|
||||
|
||||
// list all the files
|
||||
entries, err := dis.Core.Environment.ReadDir(sPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
// skip directories
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
// grab info about the file
|
||||
info, err := entry.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check if it should be pruned!
|
||||
if !dis.ShouldPrune(info.ModTime()) {
|
||||
continue
|
||||
}
|
||||
|
||||
// assemble path, and then remove the file!
|
||||
path := filepath.Join(sPath, entry.Name())
|
||||
io.Printf("Removing %s cause it is older than %d days", path, dis.Config.MaxBackupAge)
|
||||
|
||||
if err := dis.Core.Environment.Remove(path); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -73,6 +73,7 @@ func (dis *Distillery) cInstances(thread int32) *instances.Instances {
|
|||
|
||||
func (dis *Distillery) cSnapshotManager(thread int32) *snapshots.Manager {
|
||||
return component.PutComponent(&dis.pool, thread, dis.Core, func(snapshots *snapshots.Manager, thread int32) {
|
||||
snapshots.SQL = dis.cSQL(thread)
|
||||
snapshots.Instances = dis.cInstances(thread)
|
||||
snapshots.Snapshotable = dis.cSnapshotable(thread)
|
||||
snapshots.Backupable = dis.cBackupable(thread)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue