New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grandfatherson

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grandfatherson - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

23

filters.js

@@ -69,10 +69,14 @@

}
// Deduplicate datetimes with the same mask value by keeping the oldest
var sortedDateTimes = datetimes.sort(function (a,b) {
if(a.isBefore(b)) return -1;
if(a.isAfter(b)) return 1;
});
// As a safety measure, default now to the most recent date.
options.now = _.defaultTo(options.now, _.last(sortedDateTimes));
// datetimes = tuple(datetimes)
options.now = _.defaultTo(options.now, moment.utc());
// Always keep datetimes from the future
var future = _.filter(datetimes, function (dt) { return dt.isAfter(options.now); })
var future = _.filter(sortedDateTimes, function (dt) { return dt.isAfter(options.now); })

@@ -85,11 +89,6 @@ if (options.number === 0) {

var start = this.start(options)
var valid = _.compact(_.filter(datetimes, function (dt) { return dt.isBetween(start, options.now, null, '[]') }));
var valid = _.compact(_.filter(sortedDateTimes, function (dt) { return dt.isBetween(start, options.now, null, '[]') }));
// Deduplicate datetimes with the same mask value by keeping the oldest
var sortedValid = valid.sort(function (a,b) {
if(a.isBefore(b)) return -1;
if(a.isAfter(b)) return 1;
});
var kept = {};
sortedValid.map(function (dt) {
valid.map(function (dt) {
var key = self.mask(dt).toString();

@@ -96,0 +95,0 @@ kept[key] = _.defaultTo(kept[key], dt);

## [1.1.0] - 2016-10-18
### Behavior change
* Default value of `now` was changed to match the timestamp of the most recent backup. This is safer, erring on the side of retaining more data. See README for details.
### Documentation
* Document was improved to explain in more detail how the calculations work
## [1.0.0] - 2016-10-18

@@ -3,0 +13,0 @@

@@ -20,3 +20,3 @@

firstweekday : SATURDAY,
now : moment.utc(),
now : undefined, // Default is defined in the filter function. No need to duplicate it here.
});

@@ -23,0 +23,0 @@

{
"name": "grandfatherson",
"version": "1.0.0",
"version": "1.1.0",
"keywords": ["backup", "rotation", "algorithm", "snapshots" ],

@@ -5,0 +5,0 @@ "description": "Grandfather Father Son algorithm, useful for backup rotation",

@@ -47,3 +47,3 @@ # grandfatherson

* `hours` : Number of most recent one-per-hour dates to keep. Defaults to 0.
* `now` : The date to use as 'now' when calculating 'recent'. All "future" dates after this moment are kept. Expected to be a moment object. Defaults to the current moment.
* `now` : The date to use as 'now' when calculating 'recent'. All "future" dates after this moment are kept. Expected to be a moment object. Defaults to the timestamp of the newest backup.
* `firstweekday` The first day of the week to consider when calculating weekly dates to keep. Defaults to Saturday. Valid values are 0-6 (Sunday-Saturday)

@@ -53,2 +53,3 @@

### toKeep(datetimes, options)

@@ -68,2 +69,30 @@

### Backups kept on are based on the the date range, not necessarily the number.
When set you `days:7`, you are expressing to keep up to 7 backups for the last 7 days. All backups older than 7 days would be deleted, no matter how few
backups you happen to have in the last 7 days.
If there are gaps in your backups, this logic is *not* the same as "keep 7 daily backups". We make this
safer in case your backups are interrupted by calculating 'now' from the most recent backup. More on that below.
### Backups to keep start with the current unit of time.
If 'now' is set to the current moment and you say you want to keep `days: 3`, we will keep backups
for TODAY and the two days previous. (NOT yesterday and the two days previous). The same works for the current unit of time.
### Calculating `now`: Backups to delete are calculated from the newest backup.
For safety, the default value of 'now' we use is the timestamp of the newest backup.
If you are making snapshots every day and pruning them later the same day, this produces exactly the same result as setting the default value of 'now' to the current moment when rotating daily backups.
However, if you happen to expire your daily snapshots *before* making your daily snapshots, this default value will provide you one more backup rather than one less. Consider a plan
to set `days:7`. If `now` were set to the current date and the backup for today hadn't been generated, you would be pruning to 6 daily backups until the backup runs later in the day.
Since we default to setting `now` to the newest backup-- yesterdays-- we would retain 7 backups when pruning. When the backup ran later in the day, you would have 8 until the next
pruning happenings.
Also consider a case where you are backing up daily and want to keep 7 daily backups. There's a problem with the backups running and backups are offline for a week. If we used the current moment to calculate how many days of backups to keep, all the daily backups would be deleted after 7 days of backups being offline. But if 'now' were set to the date of the newest backup, you would always have the 7 most recent backups.
You can set 'now' to `moment.utc()` if you want prioritize making sure your backups are always being deleted on time and are prepared for the risk of data loss if your backup cycles don't get run but your snapshot expiration cycles do!
## Example

@@ -105,3 +134,3 @@

Incoming dates are always passed to 'moment.utc()`. If your timestamps are not in UTC, you could carefully
Incoming dates are always passed to `moment.utc()`. If your timestamps are not in UTC, you could carefully
check that the results are what you expect. There is no test coverage for not UTC time stamps.

@@ -129,2 +158,2 @@

grandfatherson is distributed under the BSD 3 clause lisence. See the
LICENSE file for more details.
[LICENSE](./LICENSE) file for more details.

@@ -6,2 +6,3 @@ "use strict";

var _ = require('lodash');
var filters = require('../filters');

@@ -94,2 +95,3 @@ var Seconds = filters.Seconds;

it('no input returns empty set', function () {

@@ -633,2 +635,18 @@ expect(Seconds.filter([], {number:0, now:now})).to.eql([]);

// If now defaulted to the current moment, all the backups would be deleted.
// By defaulting to the date of the newest backup, we would keep these "newest 3" by default instead.
it('should default "now" to the newest datetime', function () {
var datetimes = [
moment.utc({year: 2002}),
moment.utc({year: 2003}),
moment.utc({year: 2001})
];
var result = Years.filter(datetimes, {number:3});
expect(result.length).to.equal(3);
expect(_.last(result).toISOString()).to.equal(moment.utc({year: 2003}).toISOString());
});
it('for dates that end up with the same mask, return the oldest', function () {

@@ -635,0 +653,0 @@ var filtered = Years.filter(datetimes, {number:2, now:now});

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc