Skip to content

Commit

Permalink
respect previous backup time
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Kostin committed Dec 28, 2023
1 parent f44ee37 commit cd375a7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/backup/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,47 @@ func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate, t
prevBackupType := ""
lastBackup := time.Now()
lastFullBackup := time.Now()

remoteBackups, err := b.GetRemoteBackups(ctx, true)
if err != nil {
return err
}
backupTemplateName, err := b.ch.ApplyMacros(ctx, b.cfg.General.WatchBackupNameTemplate)
if err != nil {
return err
}
backupTemplateNamePrepR := regexp.MustCompile(`\{type\}|\{time:[\S\s]+\}`)
backupTemplateNameR := regexp.MustCompile(backupTemplateNamePrepR.ReplaceAllString(backupTemplateName, `\S+`))

for _, remoteBackup := range remoteBackups {
if remoteBackup.Broken == "" && backupTemplateNameR.MatchString(remoteBackup.BackupName) {
prevBackupName = remoteBackup.BackupName
if strings.Contains(remoteBackup.BackupName, "increment") {
prevBackupType = "increment"
lastBackup = remoteBackup.CreationDate
} else {
prevBackupType = "full"
lastBackup = remoteBackup.CreationDate
lastFullBackup = remoteBackup.CreationDate
}
}
}
if prevBackupName != "" {
now := time.Now()
timeBeforeDoBackup := int(b.cfg.General.WatchDuration.Seconds() - now.Sub(lastBackup).Seconds())
timeBeforeDoFullBackup := int(b.cfg.General.FullDuration.Seconds() - now.Sub(lastFullBackup).Seconds())
if timeBeforeDoBackup > 0 && timeBeforeDoFullBackup > 0 {
b.log.Infof("Wainting %d seconds until continue doing backups due watch interval", timeBeforeDoBackup)
time.Sleep(b.cfg.General.WatchDuration - now.Sub(lastBackup))
}
lastBackup = time.Now()
if b.cfg.General.FullDuration.Seconds()-time.Now().Sub(lastFullBackup).Seconds() <= 0 {
backupType = "full"
} else {
backupType = "increment"
}
}

createRemoteErrCount := 0
deleteLocalErrCount := 0
var createRemoteErr error
Expand Down

0 comments on commit cd375a7

Please sign in to comment.