Join the community today
Become a Member

Exclude a folder on tar

Discussion in 'System Administration' started by pamamolf, Nov 17, 2014.

  1. pamamolf

    pamamolf Well-Known Member

    2,726
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    7:11 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi
    I want to backup the contents of the folder:
    Code:
    /home/username/public_html/
    Inside public_html is a folder named uploads that i want to exclude from tar (completely exclude this folder and all files in it and all subfolders in it)

    So i cd here:
    Code:
    cd /home/username
    Then i found from Google many recommendations like:
    Code:
    tar -cpvzf /home/username/sitefiles.tgz  --exclude=/home/username/public_html/uploads public_html
    or
    Code:
    tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=/home/username/public_html/uploads
    or
    Code:
    tar --exclude=/home/username/public_html/uploads -cpvzf /home/username/sitefiles.tgz public_html 
    or
    Code:
    tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=./home/username/public_html/uploads
    or
    Code:
    tar -cpvzf /home/username/sitefiles.tgz public_html --exclude="/home/username/public_html/uploads"
    No way to get this folder excluded as i can see from ssh when i run the commands.... :(

    Any ideas?
     
  2. RoldanLT

    RoldanLT Well-Known Member

    3,901
    949
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,298
    Local Time:
    12:11 PM
    1.11
    10.2
    --exclude='*YOURFOLDERNAME*'

    So to exclude uploads directory:
    --exclude='*uploads*'
     
  3. pamamolf

    pamamolf Well-Known Member

    2,726
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    7:11 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Like this without giving a path?

    Code:
    tar -cpvzf /home/username/sitefiles.tgz public_html --exclude='*uploads*'
     
  4. RoldanLT

    RoldanLT Well-Known Member

    3,901
    949
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,298
    Local Time:
    12:11 PM
    1.11
    10.2
    Like this:
    Code:
    tar -cf "/home/username/sitefiles.tgz" "/home/username/public_html" --exclude='*uploads*'
     
    • Like Like x 1
  5. pamamolf

    pamamolf Well-Known Member

    2,726
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    7:11 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Working thanks :)
     
    Last edited: Nov 18, 2014
    • Like Like x 1