Esempio n. 1
0
def backup():
    """Creates the buckup and uploads"""
    now = datetime.now()
    archive_name = DB_NAME + '_db' if DB_NAME else ARCHIVE_NAME
    filename = archive_name + now.strftime('_%Y%m%d_%H%M%S')

    command = '{0} -h {1} -u {2} -p {3}'.format(MYSQL_DUMP_CMD, MYSQL_HOST,
                                                MYSQL_USER, MYSQL_PASSWORD)
    if DB_NAME:
        command += ' --databases {4} > {5}'.format(
            DB_NAME, DUMP_BASE_DIR + filename + '.sql')
    else:
        command += ' --all-databases > {5}'.format(DUMP_BASE_DIR + filename +
                                                   '.sql')

    file_location = create_db_dump(command, filename)
    file_key_suffix = utils.get_file_key(file_key=FILE_KEY, db_name=DB_NAME)
    file_key = r'%s/%s' % (file_key_suffix, filename + '.tar.gz')

    conn.upload_file_to_cloud(bucket=BUCKET_NAME,
                              media_location=file_location,
                              file_key=file_key)

    if DELETE_DUMP:
        os.remove(file_location)
        logger.info('''Removed the dump from local directory ({}).'''.format(
            file_location))

    logger.info('Sucessfully uploaded the Dump.')
Esempio n. 2
0
def backup():
    """
    Creates the buckup and uploads
    """
    now = datetime.now()
    archive_name = DB_NAME + '_db' if DB_NAME else ARCHIVE_NAME
    filename = archive_name + now.strftime('_%Y%m%d_%H%M%S')
    if DB_NAME:
        command = '{0} -Fc {1} -f {2}'.format(
            POSTGRES_DUMP_CMD, DB_NAME, DUMP_BASE_DIR + filename + '.sql')
    else:
        command = '{0} -f {1}'.format(POSTGRES_DUMP_CMD + 'all',
                                      DUMP_BASE_DIR + filename + '.sql')

    file_location = create_db_dump(command, filename)
    file_key_suffix = utils.get_file_key(file_key=FILE_KEY, db_name=DB_NAME)
    file_key = r'%s/%s' % (file_key_suffix, filename + '.tar.gz')

    conn.upload_file_to_cloud(bucket=BUCKET_NAME,
                              media_location=file_location,
                              file_key=file_key)

    if DELETE_DUMP:
        os.remove(file_location)
        os.remove(DUMP_BASE_DIR + filename + '.sql')
        logger.info(
            '''Removed the dump from local directory ({}, {}).'''.format(
                DUMP_BASE_DIR + filename + '.sql', file_location))

    logger.info('Sucessfully uploaded the Dump.')
Esempio n. 3
0
def backup():
    """Creates the buckup and uploads"""
    now = datetime.now()
    filename = ARCHIVE_NAME + now.strftime('_%Y%m%d_%H%M%S')

    command = REDIS_SAVE_CMD

    file_location = create_redis_dump(command, filename)
    file_key_suffix = utils.get_file_key(file_key=FILE_KEY)
    file_key = r'%s/%s' % (file_key_suffix, filename + '.tar.gz')

    conn.upload_file_to_cloud(
        bucket=BUCKET_NAME,
        media_location=file_location,
        file_key=file_key
    )

    logger.info('Sucessfully uploaded the Dump.')
Esempio n. 4
0
 def __init__(self, conn, service_name, bucket, file_key, db_name=None):
     self.conn = conn
     self.service_name = service_name
     self.bucket = bucket
     self.file_key_suffix = utils.get_file_key(file_key=file_key,
                                               db_name=db_name)