def get(self): """ .. http:get:: /databaseBackup Get a tar copy of the database. **Example request**: .. sourcecode:: http GET /databaseBackup HTTP/1.1 **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: application/json :statuscode 200: Database backup successfully returned :statuscode 400: database backup failed to be generated """ name = '{}.{}'.format( str(next.utils.datetimeNow().strftime("%Y-%m-%d_%H:%M:%S")), 'tar.gz') location = make_mongodump(name) zip_file = file(location) return Response(zip_file, mimetype='application/octet-stream', headers={ 'Content-Disposition': 'attachment;filename={}'.format(name) })
def get(self): """ .. http:get:: /databaseBackup Get a tar copy of the database. **Example request**: .. sourcecode:: http GET /databaseBackup HTTP/1.1 **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: application/json :statuscode 200: Database backup successfully returned :statuscode 400: database backup failed to be generated """ exp_uid_list = request.args.getlist("exp_uid") ## returns a list print exp_uid_list name = "{}.{}".format(str(next.utils.datetimeNow().strftime("%Y-%m-%d_%H:%M:%S")), "tar.gz") location = make_mongodump(name, exp_uid_list) zip_file = file(location) return Response( zip_file, mimetype="application/octet-stream", headers={"Content-Disposition": "attachment;filename={}".format(name)}, )
NEXT_BACKEND_GLOBAL_HOST = os.environ.get('NEXT_BACKEND_GLOBAL_HOST', 'localhost') AWS_BUCKET_NAME = os.environ.get('AWS_BUCKET_NAME','next-database-backups') timestamp = utils.datetimeNow() print "[ %s ] starting backup of MongoDB to S3..." % str(timestamp) print "[ %s ] constants.AWS_ACCESS_ID = %s" % (str(timestamp),constants.AWS_ACCESS_ID) tar_file = '' try: tar_file = sys.argv[1] except: tar_file = 'mongo_dump_{hostname}_{timestamp}.tar.gz'.format( hostname=NEXT_BACKEND_GLOBAL_HOST, timestamp= timestamp.strftime("%Y-%m-%d_%H:%M:%S") ) tar_filename = db_lib.make_mongodump(tar_file) from boto.s3.connection import S3Connection from boto.s3.key import Key import boto # boto.set_stream_logger('boto') try: conn = S3Connection(constants.AWS_ACCESS_ID,constants.AWS_SECRET_ACCESS_KEY) b = conn.get_bucket(AWS_BUCKET_NAME) k = Key(b) k.key = tar_file bytes_saved = k.set_contents_from_filename( tar_filename ) timestamp = utils.datetimeNow() print "[ %s ] done with backup of MongoDB to S3... %d bytes saved" % (str(timestamp),bytes_saved)