mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-12-05 17:18:02 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c666d0c88 | ||
|
|
a0402b407d | ||
|
|
3193e88fc0 | ||
|
|
c391230be6 | ||
|
|
f946f36fb0 |
@@ -503,15 +503,35 @@ func (s *script) pruneOldBackups() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(s.c.BackupArchive); !os.IsNotExist(err) {
|
if _, err := os.Stat(s.c.BackupArchive); !os.IsNotExist(err) {
|
||||||
candidates, err := filepath.Glob(
|
globPattern := path.Join(
|
||||||
path.Join(s.c.BackupArchive, fmt.Sprintf("%s*", s.c.BackupPruningPrefix)),
|
s.c.BackupArchive,
|
||||||
|
fmt.Sprintf("%s*", s.c.BackupPruningPrefix),
|
||||||
)
|
)
|
||||||
|
globMatches, err := filepath.Glob(globPattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"pruneOldBackups: error looking up matching files, starting with: %w", err,
|
"pruneOldBackups: error looking up matching files using pattern %s: %w",
|
||||||
|
globPattern,
|
||||||
|
err,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var candidates []string
|
||||||
|
for _, candidate := range globMatches {
|
||||||
|
fi, err := os.Lstat(candidate)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"pruneOldBackups: error calling Lstat on file %s: %w",
|
||||||
|
candidate,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
|
||||||
|
candidates = append(candidates, candidate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var matches []string
|
var matches []string
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
fi, err := os.Stat(candidate)
|
fi, err := os.Stat(candidate)
|
||||||
@@ -522,16 +542,15 @@ func (s *script) pruneOldBackups() error {
|
|||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if fi.ModTime().Before(deadline) {
|
||||||
if fi.Mode() != os.ModeSymlink && fi.ModTime().Before(deadline) {
|
|
||||||
matches = append(matches, candidate)
|
matches = append(matches, candidate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(matches) != 0 && len(matches) != len(candidates) {
|
if len(matches) != 0 && len(matches) != len(candidates) {
|
||||||
var removeErrors []error
|
var removeErrors []error
|
||||||
for _, candidate := range matches {
|
for _, match := range matches {
|
||||||
if err := os.Remove(candidate); err != nil {
|
if err := os.Remove(match); err != nil {
|
||||||
removeErrors = append(removeErrors, err)
|
removeErrors = append(removeErrors, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user