Skip to content

Commit 8fcd61b

Browse files
timestamp option
1 parent 611c72b commit 8fcd61b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

rotate_backups/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171
:class:`~dateutil.relativedelta.relativedelta` objects as values. This
7272
dictionary is generated based on the tuples in :data:`ORDERED_FREQUENCIES`.
7373
"""
74-
75-
TIMESTAMP_PATTERN = re.compile(r'''
74+
TIMESTAMP = r'''
7675
# Required components.
7776
(?P<year>\d{4} ) \D?
7877
(?P<month>\d{2}) \D?
@@ -83,7 +82,8 @@
8382
(?P<minute>\d{2}) \D?
8483
(?P<second>\d{2})?
8584
)?
86-
''', re.VERBOSE)
85+
'''
86+
8787
"""
8888
A compiled regular expression object used to match timestamps encoded in
8989
filenames.
@@ -197,6 +197,7 @@ def load_config_file(configuration_file=None, expand=True):
197197
options = dict(include_list=split(items.get('include-list', '')),
198198
exclude_list=split(items.get('exclude-list', '')),
199199
io_scheduling_class=items.get('ionice'),
200+
timestamp=items.get('timestamp'),
200201
strict=coerce_boolean(items.get('strict', 'yes')),
201202
prefer_recent=coerce_boolean(items.get('prefer-recent', 'no')))
202203
# Don't override the value of the 'removal_command' property unless the
@@ -254,6 +255,10 @@ def __init__(self, rotation_scheme, **options):
254255
options.update(rotation_scheme=rotation_scheme)
255256
super(RotateBackups, self).__init__(**options)
256257

258+
@cached_property(writable=True)
259+
def timestamp(self):
260+
return TIMESTAMP
261+
257262
@mutable_property
258263
def config_file(self):
259264
"""
@@ -557,15 +562,19 @@ def collect_backups(self, location):
557562
location = coerce_location(location)
558563
logger.info("Scanning %s for backups ..", location)
559564
location.ensure_readable()
565+
pattern=re.compile(self.timestamp, re.VERBOSE)
560566
for entry in natsort(location.context.list_entries(location.directory)):
561-
match = TIMESTAMP_PATTERN.search(entry)
567+
# match = TIMESTAMP_PATTERN.search(entry)
568+
match = pattern.search( entry)
562569
if match:
563570
if self.exclude_list and any(fnmatch.fnmatch(entry, p) for p in self.exclude_list):
564571
logger.verbose("Excluded %s (it matched the exclude list).", entry)
565572
elif self.include_list and not any(fnmatch.fnmatch(entry, p) for p in self.include_list):
566573
logger.verbose("Excluded %s (it didn't match the include list).", entry)
567574
else:
568575
try:
576+
# for group in match.groups('0'):
577+
# print group
569578
backups.append(Backup(
570579
pathname=os.path.join(location.directory, entry),
571580
timestamp=datetime.datetime(*(int(group, 10) for group in match.groups('0'))),

rotate_backups/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ def main():
214214
selected_locations = []
215215
# Parse the command line arguments.
216216
try:
217-
options, arguments = getopt.getopt(sys.argv[1:], 'M:H:d:w:m:y:I:x:jpri:c:r:uC:nvqh', [
217+
options, arguments = getopt.getopt(sys.argv[1:], 'M:H:d:w:m:y:tI:x:jpri:c:r:uC:nvqh', [
218218
'minutely=', 'hourly=', 'daily=', 'weekly=', 'monthly=', 'yearly=',
219-
'include=', 'exclude=', 'parallel', 'prefer-recent', 'relaxed',
219+
'timestamp=', 'include=', 'exclude=', 'parallel', 'prefer-recent', 'relaxed',
220220
'ionice=', 'config=', 'use-sudo', 'dry-run', 'removal-command=',
221221
'verbose', 'quiet', 'help',
222222
])
@@ -233,6 +233,8 @@ def main():
233233
rotation_scheme['monthly'] = coerce_retention_period(value)
234234
elif option in ('-y', '--yearly'):
235235
rotation_scheme['yearly'] = coerce_retention_period(value)
236+
elif option in ('-t', '--timestamp'):
237+
kw['timestamp'].append(value)
236238
elif option in ('-I', '--include'):
237239
kw['include_list'].append(value)
238240
elif option in ('-x', '--exclude'):

0 commit comments

Comments
 (0)