jgehrcke / timegaps Goto Github PK
View Code? Open in Web Editor NEWAccept or reject items based on age categorization (command line program, runs on Python 2/3, Unix, and Windows).
License: Other
Accept or reject items based on age categorization (command line program, runs on Python 2/3, Unix, and Windows).
License: Other
crontab:
@hourly pg_dump -Fc > backup/db-$(date -Isecond).dump; timegaps --delete hours24,days7,weeks4,months6 backup/*.dump
This immediately deletes the files created a millisecond before. The directory backup
will be empty for ever.
That's confusing.
I found the solution: You need to add recent
.
Example:
@hourly pg_dump -Fc > backup/db-$(date -Isecond).dump; timegaps --delete recent1,hours24,days7,weeks4,months6 backup/*.dump
The "first time user experience" could get improved.
Why not switch to
if "recent" is missing, all recent file are kept?
$ pip install timegaps
Downloading/unpacking timegaps
Downloading timegaps-0.1.0.zip (40kB): 40kB downloaded
Running setup.py (path:/private/var/folders/b6/7mmmgl3x71bd8d9t_ts2g2ldcrykkj/T/pip_build_murphyke/timegaps/setup.py) egg_info for package timegaps
Traceback (most recent call last):
File "", line 17, in
File "/private/var/folders/b6/7mmmgl3x71bd8d9t_ts2g2ldcrykkj/T/pip_build_murphyke/timegaps/setup.py", line 28, in
long_description=open("README.rst", "rb").read().decode('utf-8'),
IOError: [Errno 2] No such file or directory: 'README.rst'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 17, in
File "/private/var/folders/b6/7mmmgl3x71bd8d9t_ts2g2ldcrykkj/T/pip_build_murphyke/timegaps/setup.py", line 28, in
long_description=open("README.rst", "rb").read().decode('utf-8'),
IOError: [Errno 2] No such file or directory: 'README.rst'
Okay so a number of years ago we switched from "keep youngest item per category" (first release of timegaps im 2014) to "keep oldest item per category (in master
branch since 2014, not released) as of the discussion in #3.
We were pretty confident that changing the approach made sense, also supported by @lapseofreason who wrote in 2017:
“It might be worthwhile to look at how the retention policy of btrbk. It implements a similar retention policy for btrfs snaphots. They seem to have come across the same problem and have [changed the retention policy] digint/btrbk@bd34d9f) to keeping the first backup in each bucket in version 0.23.
In 2014 I wrote
“Update: In my thought experiments I came across another constellation that might lead to unexpected results also with the accept-oldest-approach. I need to come up with a more systematic approach.”
Sadly I didn't note down details, but I believed past Jan-Philip and was not confident making another release w/o much more exhaustive and systematic testing. Around Christmas 2017 I did more systematic testing based on certain invariants and indeed I found a conceptual problem with the "accept oldest item in category" approach, also leading to data loss. I never took the time to publicly document this because I wanted to further simplify the test that failed. Didn't happen in more than a year so now I simply note the details of the exact experiment that failed.
With the 'simple' keep-oldest-item approach the following experiment revealed a problem:
Have 7779000 / 300 = 25931
items spread across a timeline of about 3 months with a time delta of precisely 5 minutes between adjacent items.
Set reference time arbitrarily, generate items:
reftime = 1514000000.0
modtimes = (reftime - n * 300 for n in range(0, 25930+1))
items = [FilterItem(modtime=t) for t in modtimes]
With these rules (arbitrarily chosen):
recent12,hours24,days7,weeks5,months2
Expected item count: 50
After the first run exactly 50 items remained.
Simulate the following:
reftime
into the future add a new item.Check for invariant: after every timegaps run see if the number of accepted items is still 50.
The check for the invariant failed for run 288 where only 49 items remained.
I'm generating backups every 5 minutes.
Using the following command:
timegaps -d recent12,hours24,days7,weeks4,months3 *.Fc
I am seeing a rolling set of 13 files. Timegaps doesn't seem to be keeping the hourly files. I was hoping to keep 12 files for the most recent hour, then 1 file per hour for the most recent day, etc, etc. Is my usage correct?
I like the idea of a stand-alone tool to decide about file deletion. But the rules can be more flexible.
Currently the rule "days20" would keep one per day for 20 days. If i want to keep 4 per day, i cant.
Coming from btrfs-sxbackup im used to rules like this:
4d:8/d, 1w:4/d, 2w:daily, 1m:weekly, 3m:2/m, 12m:none
which translates to:
If younger than 4 Days, keep everything
For older than 4 days, keep 8 per Day
For older than 1 Week, keep 4 per Day
For older than 2 Weeks, keep 1 per Day
For older than 1 Month, keep 2 per Month
for older than 12 months, keep none.
As Btrfs-SXBackup is written in python too, maybe those rules can be easily ported over?
When using the --time-from-string parameter and not all input lines are in the expected match format timegaps exits with error
ERROR: Error while parsing time from item string. Error: time data u'pool/test@2018-03-29__14-11-35' does not match format 'storagepool/test@backup_%Y-%m-%d__%H-%M-%S'
As it happens that I have regular zfs snapshots with name 2018-03-29__14-30-00
but also other named snapshots when offsite-backup-script transferes snapshots to another system and creates a snapshot before transfering with name backup_2018-03-29__18-00-00
For this cases it would probably be usefull to have a --ignore-invalid-items parameter where the backup_... snapshots would be simply keept/accepted.
My command is as follows:
sudo zfs list -r -H -t snapshot -o name pool/test | timegaps --stdin --time-from-string "pool/test@%Y-%m-%d__%H-%M-%S" recent2,hours10,days30,weeks12,months14,years3
Probably also a --time-from-string-regex would be a solution - so User can use wildcards + date patterns for item selection.
Interested in what you think about my usecase.
Greetings
Wolfgang
I ran timegaps in a crontab, and the stripped-down environment caused timegaps to emit this error message:
ERROR: Please explicitly specify the codec that should be used for decoding data read from stdin, and for encoding data that is to be written to stdout: set environment variable PYTHONIOENCODING. Example: export PYTHONIOENCODING=UTF-8.
I am up and running by defining PYTHONIOENCODING
for the crontab timegaps command.
However, I found the error confusing because it referred to stdout and stdin and made me wonder if timegaps was not seeing the file arguments and silently attempting to default to stdin mode. Apologies if you find such a terrible speculation insulting ;-)
Maybe the message could be modified to indicate that the codec is also used for command line processing, if that is what is happening. Unless the user has specified --stdin
, there's no need to mention it in the error message, but I would understand if you wanted to have a one-size-fits-all error message.
Usecase - productive ZFS server makes snapshots via cronjob every 0 and 30 minutes after the hour and only once a day these snapshots are transfered offsite to another server with zfs send command.
After transfering snapshots to offsite system I would like to clear some snapshots on productive system. But I must assure to keep (in any case) the last snapshot for the next incremental zfs send - so a keeplast1 would be needed.
Another usecase from this would be that on the productive Server I would like to assure to keep the latest 10 snapshots in any case (independed of creation time).
Everything after the 10 recent snapshots can be thinned out with hours,days,weeks etc.
So categorie keeplast would be helpfull.
Probably a helpful source would be the program Restic Backup
I use Restic for some other backups and that's where I'm used to have a keep-last parameter.
Again ;-) interessted in your thoughts.
Greetings Wolfgang
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.