Copies Db betweem servers, ie develop to qa.
        Should be called by function from function defined in project fabfile.
        Example usage:

        def copy_db_between_servers(source_server, destination_server):

            source_env = {}
            destination_env = {}

            def populate_env_dict(server, local_env):
                app_dir = 'nutrimom'
                if server == 'nm-dev':
                    user = 'nutrimom-dev'
                    prefix = "dev"
                    environment = 'devel'
                    host_string = 'dev.arabel.la'
                elif server == 'nm-qa':
                    user = 'nutrimom-qa'
                    prefix = "qa"
                    environment = 'qa'
                    host_string = 'qa.arabel.la'
                elif server.startswith('nm-f'):
                    if server in ['nm-f1', 'nm-f2', 'nm-f3', 'nm-f4', 'nm-f5']:
                        user = 'nutrimom-' + server.split('-')[1]
                        prefix = user.split('-')[1]
                        environment = prefix
                        host_string = 'dev.arabel.la'
                else:
                    print ("supported params: nm-dev, nm-qa, nm-fx")
                    sys.exit()

                local_env['app_dir'] = app_dir
                local_env['remote_user'] = user
                local_env['remote_path'] = '/home/%s/www/' % (user)
                local_env['dir'] = '/home/%s/Envs/%s' % (user, app_dir)
                local_env['python'] = '/home/%s/Envs/%s/bin/python' % (user, app_dir)
                local_env['pip'] = '/home/%s/Envs/%s/bin/pip' % (user, app_dir)
                local_env['prefix'] = prefix
                local_env['environment'] = environment
                local_env['host_string'] = host_string
                local_env['is_feature'] = False
                return local_env

            source_env = populate_env_dict(source_server, source_env)
            destination_env = populate_env_dict(destination_server, destination_env)

            copy_db(source_env, destination_env)

def copy_db(source_env, destination_env):
    """
        Copies Db betweem servers, ie develop to qa.
        Should be called by function from function defined in project fabfile.
        Example usage:

        def copy_db_between_servers(source_server, destination_server):

            source_env = {}
            destination_env = {}

            def populate_env_dict(server, local_env):
                app_dir = 'nutrimom'
                if server == 'nm-dev':
                    user = 'nutrimom-dev'
                    prefix = "dev"
                    environment = 'devel'
                    host_string = 'dev.arabel.la'
                elif server == 'nm-qa':
                    user = 'nutrimom-qa'
                    prefix = "qa"
                    environment = 'qa'
                    host_string = 'qa.arabel.la'
                elif server.startswith('nm-f'):
                    if server in ['nm-f1', 'nm-f2', 'nm-f3', 'nm-f4', 'nm-f5']:
                        user = 'nutrimom-' + server.split('-')[1]
                        prefix = user.split('-')[1]
                        environment = prefix
                        host_string = 'dev.arabel.la'
                else:
                    print ("supported params: nm-dev, nm-qa, nm-fx")
                    sys.exit()

                local_env['app_dir'] = app_dir
                local_env['remote_user'] = user
                local_env['remote_path'] = '/home/%s/www/' % (user)
                local_env['dir'] = '/home/%s/Envs/%s' % (user, app_dir)
                local_env['python'] = '/home/%s/Envs/%s/bin/python' % (user, app_dir)
                local_env['pip'] = '/home/%s/Envs/%s/bin/pip' % (user, app_dir)
                local_env['prefix'] = prefix
                local_env['environment'] = environment
                local_env['host_string'] = host_string
                local_env['is_feature'] = False
                return local_env

            source_env = populate_env_dict(source_server, source_env)
            destination_env = populate_env_dict(destination_server, destination_env)

            copy_db(source_env, destination_env)
    """
    env.update(source_env)
    local_file_path = _get_db()

    # put the file on external file system
    # clean external db
    # load database into external file system
    env.update(destination_env)

    with cd(env.remote_path):
        sudo('mkdir -p backups', user=env.remote_user)
        sudo(env.python + ' manage.py dump_database | gzip > backups/' + _sql_paths('local', datetime.now()))
        put(local_file_path, 'backups', use_sudo=True)
        sudo(env.python + ' manage.py clear_database', user=env.remote_user)
        if local_file_path.endswith('.gz'):  # the path is the same here and there
            sudo('gzip -dc %s | %s manage.py dbshell' % (local_file_path, env.python), user=env.remote_user)
        else:
            sudo('%s manage.py dbshell < %s ' % (env.python, local_file_path), user=env.remote_user)