ossobv / planb

PlanB - automating remote backups and snapshots with zfs/rsync
GNU General Public License v3.0
28 stars 3 forks source link

relativedelta ValueError on huge year-retention of 9999 (1000 works) #25

Closed wdoekes closed 6 years ago

wdoekes commented 6 years ago
  510.             self.snapshot_rotate()
...
File "/srv/virtualenvs/planb/lib/python3.5/site-packages/planb/storage/zfs.py" in snapshot_retain_yearly
  165.                                          relativedelta(years=retention+1))

File "/srv/virtualenvs/planb/lib/python3.5/site-packages/dateutil/relativedelta.py" in __rsub__
  394.         return self.__neg__().__radd__(other)

File "/srv/virtualenvs/planb/lib/python3.5/site-packages/dateutil/relativedelta.py" in __radd__
  391.         return self.__add__(other)

File "/srv/virtualenvs/planb/lib/python3.5/site-packages/dateutil/relativedelta.py" in __add__
  363.         day = min(calendar.monthrange(year, month)[1],

File "/usr/lib/python3.5/calendar.py" in monthrange
  121.     day1 = weekday(year, month, 1)

File "/usr/lib/python3.5/calendar.py" in weekday
  113.     return datetime.date(year, month, day).weekday()

Relevant code:

    def snapshot_retain_yearly(self, snapname, retention):
        try:
            dts = re.match(r'\w+-(\d+)', snapname).groups()[0]
        except AttributeError:
            return True  # Keep
        datetimestamp = datetime.strptime(dts, '%Y%m%d%H%M')
        snapdate = datetime.date(datetimestamp)
        today_a_year_ago = datetime.date(datetime.now() -
                                         relativedelta(years=retention+1))
        return snapdate >= today_a_year_ago

Using relativedelta is probably a bad idea anyway, but in this case it actually breaks things.

Limiting the year-retention to 1000 or 999 could be a workaround for now.

wdoekes commented 6 years ago
Exception Type: ValueError
Exception Value: year is out of range
Request data not supplied