- fix determination of which to keep (continued)
This commit is contained in:
19
backup.py
19
backup.py
@@ -19,28 +19,19 @@ def dates(sdate):
|
|||||||
|
|
||||||
|
|
||||||
def days(d, n=7):
|
def days(d, n=7):
|
||||||
return d[-n:]
|
return sorted({(i.year, i.month, i.day): i for i in d}.values())[-n:]
|
||||||
|
|
||||||
|
|
||||||
def weeks(d, n=4):
|
def weeks(d, n=4):
|
||||||
l = {}
|
return sorted({(i.year, i.isocalendar()[1]): i for i in d}.values())[-n:]
|
||||||
for i in d[-7*n:]:
|
|
||||||
l[(i.year, i.isocalendar()[1])] = i
|
|
||||||
return sorted(l.values())[-n:]
|
|
||||||
|
|
||||||
|
|
||||||
def months(d, n=12):
|
def months(d, n=12):
|
||||||
l = {}
|
return sorted({(i.year, i.month): i for i in d}.values())[-n:]
|
||||||
for i in d[-31*n:]:
|
|
||||||
l[(i.year, i.month)] = i
|
|
||||||
return sorted(l.values())[-n:]
|
|
||||||
|
|
||||||
|
|
||||||
def years(d, n=10):
|
def years(d, n=10):
|
||||||
l = {}
|
return sorted({i.year: i for i in d}.values())[-n:]
|
||||||
for i in d[-366*n:]:
|
|
||||||
l[i.year] = i
|
|
||||||
return sorted(l.values())[-n:]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -73,7 +64,7 @@ if __name__ == '__main__':
|
|||||||
if run:
|
if run:
|
||||||
os.makedirs(os.path.join(backup_path_full, args.source[1:]))
|
os.makedirs(os.path.join(backup_path_full, args.source[1:]))
|
||||||
rsync = 'rsync {} --delete "{}" {} "{}"'.format(args.rsync, os.path.join(args.source, ''), latest,
|
rsync = 'rsync {} --delete "{}" {} "{}"'.format(args.rsync, os.path.join(args.source, ''), latest,
|
||||||
os.path.join(backup_path_full, args.source[1:]))
|
os.path.join(backup_path_full, args.source[1:]))
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print('Running rsync: {}'.format(rsync))
|
print('Running rsync: {}'.format(rsync))
|
||||||
|
|||||||
Reference in New Issue
Block a user