Skip to content

Commit

Permalink
Allow more complex GFS rotation scheme. Fixes #28.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsileo committed May 8, 2013
1 parent fa848f6 commit f66a436
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
38 changes: 22 additions & 16 deletions bakthat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,29 @@ def rotate_backups(filename, destination=None, profile="default", config=CONFIG_
backups = Backups.search(filename, destination, profile=profile, config=config)
backups_date = [datetime.fromtimestamp(float(backup.backup_date)) for backup in backups]

to_delete = grandfatherson.to_delete(backups_date,
days=int(rotate.conf["days"]),
weeks=int(rotate.conf["weeks"]),
months=int(rotate.conf["months"]),
firstweekday=int(rotate.conf["first_week_day"]),
now=datetime.utcnow())
rotate_kwargs = rotate.copy()
del rotate_kwargs["first_week_day"]
for k, v in rotate_kwargs.iteritems():
rotate_kwargs[k] = int(v)
rotate_kwargs["firstweekday"] = int(rotate["first_week_day"])
rotate_kwargs["now"] = datetime.utcnow()

to_delete = grandfatherson.to_delete(backups_date, **rotate_kwargs)
for delete_date in to_delete:
backup_date = int(delete_date.strftime("%s"))
backup = Backups.search(filename, destination, backup_date=backup_date, profile=profile, config=config).get()

if backup:
real_key = backup.stored_filename
log.info("Deleting {0}".format(real_key))

storage_backend.delete(real_key)
backup.set_deleted()
deleted.append(real_key)
try:
backup_date = int(delete_date.strftime("%s"))
backup = Backups.search(filename, destination, backup_date=backup_date, profile=profile, config=config).get()

if backup:
real_key = backup.stored_filename
log.info("Deleting {0}".format(real_key))

storage_backend.delete(real_key)
backup.set_deleted()
deleted.append(real_key)
except Exception, exc:
log.error("Error when deleting {0}".format(backup))
log.exception(exc)

BakSyncer(conf).sync_auto()

Expand Down
6 changes: 6 additions & 0 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ Now you can rotate a backup set:

$ bakthat rotate_backups bakname


.. note::

Bakthat rely on the `GrandFatherSon <https://pypi.python.org/pypi/GrandFatherSon>`_ module to compute rotations, so if you need to setup more complex rotation scheme (like hourly backups), refer to the docs and change the rotation settings manually in your configuration file.


Accessing bakthat Python API
----------------------------

Expand Down

0 comments on commit f66a436

Please sign in to comment.