Created
March 27, 2015 21:02
-
-
Save kevints/b2e000b9076b8cd513dd to your computer and use it in GitHub Desktop.
Aurora Backup REPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A REPL for performing ad-hoc analysis of Aurora storage backups.""" | |
import code | |
from twitter.common import app | |
from gen.apache.aurora.storage.ttypes import Snapshot, TBinaryProtocol | |
from thrift.transport import TTransport | |
def load_backup(filename): | |
with open(filename) as f: | |
transport = TTransport.TFileObjectTransport(f) | |
protocol = TBinaryProtocol.TBinaryProtocol(transport) | |
backup = Snapshot() | |
backup.read(protocol) | |
return backup | |
def load_backups(filenames): | |
return [load_backup(fname) for fname in filenames] | |
def main(args, _): | |
backups = load_backups(args) | |
code.interact('Backups REPL', local=locals()) | |
app.set_name("backup_repl.pex") | |
app.set_usage("""backup_repl.pex [SNAPSHOT...] | |
Start a REPL for performing ad-hoc analysis of Aurora storage backups. Any files specified are | |
loaded into the ``backups'' list. | |
# Analyze a backup copied from /var/lib/mesos/scheduler_backups on a scheduler | |
% ./backup_repl.pex scheduler-backup-2013-05-22-19-03 | |
Backups REPL | |
# Or equivalently | |
>>> backup = load_backup('scheduler-backup-2013-05-22-19-03') | |
# Number of stored tasks | |
>>> len(backups[0].tasks) | |
75632 | |
# Number of stored jobs | |
>>> len(backups[0].jobs) | |
299 | |
# Backup metadata | |
>>> backups[0].schedulerMetadata | |
SchedulerMetadata(frameworkId='201104070004-0000002563-0000') | |
# Arbitrary queries | |
>>> len([t for t in backups[0].tasks if t.assignedTask.task.jobName == 'hello_world']) | |
6 | |
""") | |
app.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment