From ebbc05d52b5409914cbff76f51c662d4ab9b0014 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Tue, 22 Oct 2019 02:43:55 +0200 Subject: [PATCH] different approach --- zfs_autobackup | 115 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 32 deletions(-) diff --git a/zfs_autobackup b/zfs_autobackup index e5f0613..f1df485 100755 --- a/zfs_autobackup +++ b/zfs_autobackup @@ -842,68 +842,119 @@ def thin(schedule, snapshots): # for snapshot in list(reversed(snapshots)): #always keep latest - for snapshot in snapshots[:-1]: + for snapshot in snapshots: snapshot_time=snapshot - age=now-snapshot_time keeps="" + # just store in the correct time blocks, per period-size for ( period, ttl ) in schedule: block_nr=int(snapshot_time/period) - if age<=ttl: - if not block_nr in time_blocks[period]: - time_blocks[period][block_nr]=snapshot_time - keeps=keeps+" ({}days, block{}) ".format(int(period/(3600*24)), block_nr) + if not block_nr in time_blocks[period]: + time_blocks[period][block_nr]=[] + time_blocks[period][block_nr].append(snapshot_time) - struct=time.localtime(snapshot_time) - if keeps: - ret.append(snapshot) - print("{} {} {}days".format(time.strftime("%Y-%m-%d %H:%M:%S",struct),keeps,int(age/(3600*24)))) - # else: - # print("{}".format(time.strftime("%Y-%m-%d %H:%M:%S",struct))) + keep=set() + + #now get the oldest one within the ttl, per block + for ( period, ttl ) in schedule: + for ( block_nr, snapshots ) in time_blocks[period].items(): + for snapshot_time in sorted(snapshots): + age=now-snapshot_time + if age0.5: - msnapshots.append(now) - msnapshots=thin(schedule, msnapshots) - - sys.stdin.readline() - now=now+random.randint(0,80000) - # msnapshots.insert(0,now) +def printsnap(s): + age=now-s + struct=time.localtime(s) + return("{} {}days".format(time.strftime("%Y-%m-%d %H:%M:%S",struct),int(age/(3600*24)))) + + +def test(): + global now + a=[] + b=[] + + while True: + print("#################### {}".format(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(now)))) + + # if random.random()>0.5: + a.append(now) + a=thin(schedule,a) + # b.append(now) + # b=thin(schedule,a, oldest=False) + b=[] + + + for count in range(0,max(len(a), len(b))): + sa="" + if count