Skip to main content

Use cron to rotate backup files!

Project description

https://github.com/kraymer/cronicle/workflows/build/badge.svghttps://github.com/kraymer/cronicle/actions https://coveralls.io/repos/github/Kraymer/cronicle/badge.svg?branch=masterhttps://coveralls.io/github/Kraymer/cronicle?branch=master https://img.shields.io/github/v/release/kraymer/cronicle.svghttps://github.com/Kraymer/cronicle/releases

cronicle

/ˈ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 question : How to keep: daily backups for a week, weekly for a month, monthly for a year, and yearly after that.

asciicast

Features

  • simplicity: add one line to your crontab and you’re done

  • files rotation: keep the N most recent versions of a file

  • space efficient: use symlinks in target directories to store a single occurence of each backup instead of performing copies. When removing a link, remove the underlying file if no other link point to it.

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 and Python 3, is tested on Linux and Mac OS X.

Install with pip via pip install git+https://github.com/Kraymer/cronicle.git 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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cronicle-0.4.0.tar.gz (9.3 kB view hashes)

Uploaded Source

Built Distribution

cronicle-0.4.0-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page