Esempio n. 1
0
def get_data_from_production_server():
    """Grab media files from _production server."""
    base = '%s/var' % production_config('basedir')
    dirs = ' '.join(production_config('var_dirs'))

    tmpfile = NamedTemporaryFile(delete=False)
    tmpfile.close()
    local("rm %s" % tmpfile.name)  # Remove to prevent get()'s warning

    with settings(host_string=production_config('web_host')):
        with cd(base):
            sudo("tar czvf production_var_directory.tgz %s" %
                 dirs, user='******')
            get('production_var_directory.tgz', tmpfile.name)
            sudo('rm production_var_directory.tgz')

    return tmpfile.name
Esempio n. 2
0
def copy_individual_database(dbname='default', drop_and_create_db=True):
    """Copies the production database(s) to the staging environment."""
    if not can_copy_database(dbname):
        # Doublecheck in case this is called directly
        return

    from_db = production_config('databases')[dbname]
    to_db = config('databases')[dbname]

    if confirm(("Copy data for db {db_name} from {from_host}" +
               " to {to_host}?").format(from_host=from_db['HOST'],
                                        to_host=to_db['HOST'],
                                        db_name=to_db['NAME']),
               default=False):

        filename = '{dbname}_dump.sql'.format(dbname=from_db['NAME'])

        with cd('/tmp'):
            print(green("Password for {from_db_host} is {from_db_pw}.".format(
                    from_db_host=from_db['HOST'],
                    from_db_pw=from_db['PASSWORD'])))
            local('pg_dump -c -h {dbhost} -U {dbuser} {dbname} -f {fn}'.format(
                    dbhost=from_db['HOST'], dbuser=from_db['USER'],
                    dbname=from_db['NAME'], fn=filename))

            if drop_and_create_db:
                drop_database(dbname)
                create_individual_database(dbname)

            print(green("Password for {to_db_host} is {to_db_pw}.".format(
                    to_db_host=to_db['HOST'], to_db_pw=to_db['PASSWORD'])))
            local('psql -h {host} -U {user} {db_name} < {fn}'.format(
                    host=to_db['HOST'], user=to_db['USER'],
                    db_name=to_db['NAME'],
                    fn=filename))

            local('rm %s' % filename)