2014-01-29 09:41:47 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
|
|
# for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
#
|
|
|
|
|
|
|
|
# A script that copies a core file and binary to GCS
|
|
|
|
# We expect the dumps to be located in /tmp/coredump_PID directory
|
|
|
|
# After we copy out the core files we delete the dumps localy
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import tarfile
|
2014-01-29 11:45:36 +00:00
|
|
|
import utils
|
2014-01-29 09:41:47 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
GCS_FOLDER = 'dart-crashes'
|
|
|
|
|
2014-07-25 11:47:59 +00:00
|
|
|
def CreateTarball(input_dir, tarname):
|
|
|
|
print 'Creating tar file: %s' % tarname
|
2014-01-29 09:41:47 +00:00
|
|
|
tar = tarfile.open(tarname, mode='w:gz')
|
2014-07-25 11:47:59 +00:00
|
|
|
tar.add(input_dir)
|
2014-01-29 09:41:47 +00:00
|
|
|
tar.close()
|
|
|
|
|
|
|
|
def CopyToGCS(filename):
|
|
|
|
gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4())
|
|
|
|
cmd = ['gsutil', 'cp', filename, gs_location]
|
2014-07-25 11:47:59 +00:00
|
|
|
print 'Running command: %s' % cmd
|
2014-01-29 09:41:47 +00:00
|
|
|
subprocess.check_call(cmd)
|
|
|
|
archived_filename = '%s%s' % (gs_location, filename.split('/').pop())
|
2014-07-25 11:47:59 +00:00
|
|
|
print 'Dump now available in %s' % archived_filename
|
2014-01-29 09:41:47 +00:00
|
|
|
|
|
|
|
def Main():
|
2014-01-29 11:45:36 +00:00
|
|
|
if utils.GuessOS() != 'linux':
|
|
|
|
print 'Currently only archiving crash dumps on linux'
|
|
|
|
return 0
|
2014-01-29 09:41:47 +00:00
|
|
|
print 'Looking for crash dumps'
|
|
|
|
num_dumps = 0
|
|
|
|
for v in os.listdir('/tmp'):
|
|
|
|
if v.startswith('coredump'):
|
2014-07-25 11:47:59 +00:00
|
|
|
fullpath = '/tmp/%s' % v
|
2014-01-29 09:41:47 +00:00
|
|
|
if os.path.isdir(fullpath):
|
|
|
|
num_dumps += 1
|
|
|
|
tarname = '%s.tar.gz' % fullpath
|
|
|
|
CreateTarball(fullpath, tarname)
|
|
|
|
CopyToGCS(tarname)
|
|
|
|
os.unlink(tarname)
|
|
|
|
shutil.rmtree(fullpath)
|
2014-07-25 11:47:59 +00:00
|
|
|
print 'Found %s core dumps' % num_dumps
|
2014-01-29 09:41:47 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(Main())
|