Project

wolfe

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Often backup files have year, month, date and hour encoded in their filename. Wolfe uses this information to clean up such files and can be configured to keep daily/monthly backups for a certain timespans. It will always keep one backup per year.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 1.3
 Project Readme

CircleCI

Wolfe

Wolfe cleans up database (and other) backups that encode year, month, day and hour in their filename. It reads that date to decide whether a file should be removed, and can be configured to keep daily and monthly backups for given timespans.

Original code was written by @michaelem, tests and gemification by @srecnig. In case you're wondering, the name wolfe is a reference.

Requirements

Ruby 3.3 or newer.

Installation

Add wolfe to your application's Gemfile, or install it directly:

gem install wolfe

Usage

Call wolfe from the command line with a rules file as its only argument:

wolfe cleanup rules.yml

Or call it from Ruby, if you've added it to your Gemfile:

Wolfe.run_cleanup "/path/to/rules.yml"

Rules file

The rules file describes where backups are stored, how the date is encoded in the filename, and how many backups to keep per timespan.

---
backup_name:
  path: /mnt/data/backups/database
  filename: 'backup-database-%{year}-%{month}-%{day}-%{hour}.tar.gz'
  one_per_day_timespan: 15.days
  one_per_month_timespan: 1.year
  • filename must contain %{year}, %{month}, %{day} and %{hour}, in the form YYYY-MM-DD-HH. Anything before or after the date is matched literally, so suffixes like .tar.gz or .age work.
  • Timespans use Active Support's duration helpers: <number>.<unit>, where the unit is day, week, month or year (singular or plural). No spaces or Ruby code.

How backups are kept

With the example above:

  • Daily: every backup from the last 15 days is kept.
  • Monthly: for each month within the last year, the latest backup of that month is kept.
  • Yearly: for each year before that, the latest backup of that year is kept.

Set one_per_month_timespan to 0.months to keep only the daily backups. A backup older than the daily timespan is then removed once a backup exists for the next day at the same hour, so this works best with one backup per day at a fixed time. Backups taken at irregular hours, or followed by a missing day, are kept.

Two safety rules apply:

  • If the latest backup in a month is empty (0 bytes), wolfe deletes nothing from that month, so a failed backup can't cause the last good ones to be removed.
  • Backups older than 5 years are not looked at, and are never removed.

Development

bundle install
bundle exec rake test

Or with Docker:

docker build -t wolfe .
docker run --rm wolfe

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/lomography/wolfe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.