For example we want to sync the epel repo for offline use

If you are on CENTOS 7 you can just type:

# yum install epel-release

If you are on Red Hat Enterprise Linux 7 add the EPEL repo this way:

# wget
# rpm -ivh epel-release-latest-7.noarch.rpm

Install the reposync utility which is included in 'yum-utils':

# yum install yum-utils createrepo

Create an offline copy with the latest files only ('-n' option):

# reposync -n --repoid=epel --download_path=/data

Create repomd (xml-rpm-metadata) repository

# createrepo /data/epel

When you later want to update the repo then just resync it:

# reposync -n --repoid=epel --download_path=/data

Remove older rpm's from the updated repo:

# repomanage -k1 -c -o /data/epel/ |xargs rm

Run createrepo with the --update flag to speed things up

# createrepo --update /var/www/html/repo