Skip to content

Commit 000a986

Browse files
move setting of self.previous to method at init-time so .symlink() can create previous symlink if rotate disabled
1 parent d1def11 commit 000a986

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mongodb_consistent_backup/Rotate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def __init__(self, config, state_root, state_bkp):
1717
self.max_backups = self.config.rotate.max_backups
1818
self.max_days = self.config.rotate.max_days
1919

20-
self.latest = state_bkp.get()
2120
self.previous = None
2221
self.backups = self.backups_by_unixts()
22+
self.latest = state_bkp.get()
2323

2424
self.base_dir = os.path.join(self.config.backup.location, self.config.backup.name)
2525
self.latest_symlink = os.path.join(self.base_dir, "latest")
@@ -36,6 +36,8 @@ def backups_by_unixts(self):
3636
backup = self.state_root.backups[name]
3737
backup_time = backup["updated_at"]
3838
backups[backup_time] = backup
39+
if not self.previous or backup_time > self.previous["updated_at"]:
40+
self.previous = backup
3941
return backups
4042

4143
def remove(self, ts):
@@ -59,8 +61,6 @@ def rotate(self):
5961
now = int(time())
6062
for ts in sorted(self.backups.iterkeys(), reverse=True):
6163
backup = self.backups[ts]
62-
if not self.previous:
63-
self.previous = backup
6464
if self.max_backups == 0 or kept_backups < self.max_backups:
6565
if self.max_secs > 0 and (now - ts) > self.max_secs:
6666
logging.info("Backup %s exceeds max age %.2f days, removing backup" % (backup["name"], self.max_days))

0 commit comments

Comments
 (0)