Kraymer / cronicle

Use cron to rotate files and keep time-spaced copies using symlinks.
MIT License
35 stars 3 forks source link
backup backup-utility cron

.. image:: http://github.com/kraymer/cronicle/workflows/build/badge.svg :target: https://github.com/kraymer/cronicle/actions .. image:: https://codecov.io/gh/Kraymer/cronicle/branch/master/graph/badge.svg?token=eku8LDViVP :target: https://codecov.io/gh/Kraymer/cronicle .. image:: https://img.shields.io/github/v/release/kraymer/cronicle.svg :target: https://github.com/Kraymer/cronicle/releases .. image:: https://pepy.tech/badge/cronicle :target: https://pepy.tech/project/cronicle

cronicle :hourglass_flowing_sand::arrows_counterclockwise::floppy_disk:

**/ˈkɹɒnɪkəl/** :

1. *n.* a factual written account of important events in the order
   of their occurrence
2. *n.* software to archive the *N* most recent backups of a file in
   a folder named after the job frequency. Recommended use is to
   trigger it via a cron job.

Originally, cronicle has been conceived as a solution to this particular serverfault <https://serverfault.com> question : How to keep: daily backups for a week, weekly for a month, monthly for a year, and yearly after that <https://serverfault.com/questions/575163/how-to-keep-daily-backups-for-a-week-weekly-for-a-month-monthly-for-a-year-a>.

|asciicast|

Features

Usage

In order to manage a file backups with cronicle, you must have a section in the config.yaml that matches the backups names. Under it you can then define values (number of archives to keep) for the five kinds of periodic archives : hourly, daily, weekly, monthly, yearly.

Or define a custom periodicity using the pipe syntax eg bimonthly|60: 3 to keep archives every two months over the last six months.

Example

If you have dumps of a database in a ~/dumps directory named like mydb-20170101.dump, mydb-20170102.dump, and want to keep each dump for 7 days plus go back up to two months ; a working ${HOME}/.config/cronicle/config.yaml content would be :

::

/home/johndoe/dumps/mydb-*.dump:
    daily: 7
    monthly: 2

Next cronicle call will result in the creation of folders DAILY and MONTHLY in /home/johndoe/dumps/, each folder containing symlinks to the .dump files.

Installation

cronicle is written for Python 2.7 <https://www.python.org/downloads/> and Python 3 <https://www.python.org/downloads/>, is tested on Linux and Mac OS X.

Install with pip <https://pip.pypa.io/en/stable/>__ via pip install cronicle command.

cron triggering

For a no-brainer use, I recommend to run cronicle via cron, just after the command in charge of performing the backup. A crontab example :

::

@daily pg_dump -Fc mydb > /home/johndoe/dumps/mydb-`date +%F`.dump
@daily cronicle -r /home/johndoe/dumps/mydb-`date +%F`.dump

If used with the config.yaml as defined in the previous section, this daily call to cronicle guarantees that you will keep at most 9 database dumps (7 latest daily + 2 monthly).

.. |asciicast| image:: https://raw.githubusercontent.com/Kraymer/cronicle/master/docs/cronicle_screenshot.png :target: https://asciinema.org/a/155861