Skip to content

Commit

Permalink
Backups: Skip unchanged albums when saving YAML backup files #4243
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Mayer <[email protected]>
  • Loading branch information
lastzero committed May 14, 2024
1 parent d5580c1 commit c73a2e3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
23 changes: 18 additions & 5 deletions internal/entity/album_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,28 @@ func (m *Album) SaveBackupYaml(backupPath string) error {
return fmt.Errorf("backup path is empty")
}

// Write metadata to YAML backup file.
if fileName, relName, err := m.YamlFileName(backupPath); err != nil {
// Get album YAML backup filename.
fileName, relName, err := m.YamlFileName(backupPath)

if err != nil {
log.Warnf("album: %s (save %s)", err, clean.Log(relName))
return err
} else if err = m.SaveAsYaml(fileName); err != nil {
log.Warnf("album: %s (save %s)", err, clean.Log(relName))
}

var action string

if fs.FileExists(fileName) {
action = "update"
} else {
action = "create"
}

// Write album metadata to YAML backup file.
if err = m.SaveAsYaml(fileName); err != nil {
log.Warnf("album: %s (%s %s)", err, action, clean.Log(relName))
return err
} else {
log.Debugf("album: saved backup file %s", clean.Log(relName))
log.Debugf("album: %sd backup file %s", action, clean.Log(relName))
}

return nil
Expand Down
23 changes: 18 additions & 5 deletions internal/entity/photo_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,28 @@ func (m *Photo) SaveSidecarYaml(originalsPath, sidecarPath string) error {
return fmt.Errorf("photo uid is empty")
}

// Write metadata to YAML sidecar file.
if fileName, relName, err := m.YamlFileName(originalsPath, sidecarPath); err != nil {
// Get photo YAML sidecar filename.
fileName, relName, err := m.YamlFileName(originalsPath, sidecarPath)

if err != nil {
log.Warnf("photo: %s (save %s)", err, clean.Log(relName))
return err
} else if err = m.SaveAsYaml(fileName); err != nil {
log.Warnf("photo: %s (save %s)", err, clean.Log(relName))
}

var action string

if fs.FileExists(fileName) {
action = "update"
} else {
action = "create"
}

// Write photo metadata to YAML sidecar file.
if err = m.SaveAsYaml(fileName); err != nil {
log.Warnf("photo: %s (%s %s)", err, action, clean.Log(relName))
return err
} else {
log.Infof("photo: saved sidecar file %s", clean.Log(relName))
log.Infof("photo: %sd sidecar file %s", action, clean.Log(relName))
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions internal/photoprism/backup_albums.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func BackupAlbums(backupPath string, force bool) (count int, err error) {
// Save albums to YAML backup files.
for _, a := range albums {
// Skip albums that have already been saved to YAML backup files.
if !force && !backupAlbumsLatest.IsZero() && !a.UpdatedAt.IsZero() &&
a.UpdatedAt.Before(backupAlbumsLatest) {
if !force && !backupAlbumsLatest.IsZero() && !a.UpdatedAt.IsZero() && !backupAlbumsLatest.Before(a.UpdatedAt) {
continue
}

Expand Down

0 comments on commit c73a2e3

Please sign in to comment.