Skip to content

Instantly share code, notes, and snippets.

@dotmanila
Created August 29, 2015 02:44
Show Gist options
  • Save dotmanila/41f28a4ceb5838c531a4 to your computer and use it in GitHub Desktop.
Save dotmanila/41f28a4ceb5838c531a4 to your computer and use it in GitHub Desktop.
Check create timestamp of binary logs
#!/usr/bin/python
import os, time
from struct import unpack
from datetime import datetime
d = '/home/mysql/backup_data/backup_str/binlogs'
x = 180
oldest = int(time.time())-(90*24*60*60)
l = os.listdir(d)
l.sort()
for f in l:
b = open(os.path.join(d, f), 'rb')
if b.read(4) != '\xfebin': continue
b.seek(4)
ts = unpack('I', b.read(4))[0]
print "%s %s" % (str(f), str(datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')))
#print "%s %d" % (f, ts)
b.close()
if ts >= oldest:
print "Reached our threshold, quitting\n"
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment