Welcome to Centmin Mod Community
Register Now

Exclude a folder on tar

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

  1. pamamolf

    pamamolf Well-Known Member

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +531
    Local Time:
    6:51 PM
    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. rdan

    rdan Premium Member Premium Member

    4,365
    1,053
    113
    May 25, 2014
    Ratings:
    +1,522
    Local Time:
    12:51 AM
    Mainline
    10.2
    --exclude='*YOURFOLDERNAME*'

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

    pamamolf Well-Known Member

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +531
    Local Time:
    6:51 PM
    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. rdan

    rdan Premium Member Premium Member

    4,365
    1,053
    113
    May 25, 2014
    Ratings:
    +1,522
    Local Time:
    12:51 AM
    Mainline
    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

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +531
    Local Time:
    6:51 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Working thanks :)
     
    Last edited: Nov 18, 2014
    • Like Like x 1
  6. ndha

    ndha Member

    71
    9
    8
    Sep 28, 2014
    Ratings:
    +27
    Local Time:
    11:51 PM
    Latest
    10
    Hi @pamamolf or @RoldanLT or @eva2000
    is this still work till now??
    Cause i tried it won't work..

    Also how about if i want to exclude multiple domain folders with subfolders on it from tar??
    CD into /home/nginx/domains
    There is :
    domain1
    domain2
    domain3
    domain4
    domain5
    I want to exclude domain1, domain2, domain3, domain4 and all sub folders from tar.
    What command do i must use??
    Thanks for any kindly help..
     
  7. eva2000

    eva2000 Administrator Staff Member

    36,850
    8,065
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,423
    Local Time:
    2:51 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    should still work provided each exclude has it's own --exclude= and is relative to directory

    or use --exclude-from to point to a file path with file listing all relative excluded files/directories
    but better yet if you just want domain5, just tar that directory instead https://linux.die.net/man/1/tar

    if unsure, do the suggested step at https://community.centminmod.com/threads/guide-to-learning-more-about-centmin-mod.10838/ in setting up a test centmin mod server with test data or duplicate of your live data, and play with the tar command until you figure it out. This way you learn without fear of messing up as you are doing it on test server.
     
  8. ndha

    ndha Member

    71
    9
    8
    Sep 28, 2014
    Ratings:
    +27
    Local Time:
    11:51 PM
    Latest
    10
    Hi @eva2000 thanks for reply,
    yes i'd already test various command in test server..sadly nothing work..
    i use : --exclude="domain1" --exclude="/domain2" etc also using --exclude-from="excludedomain.txt" and put also exclude folder on it but still not excluding..
    Command 1 : --exclude="domain1" = domain1 folder still include but not subfolders on it.
    Command 2 : --exclude="/domain1" = domain1 folder still include also subfolders on it.
    Command 3 : --exclude="/domain1/" = domain1 folder still include also subfolders on it.
    Command 4 : --exclude="/domain1/*" = domain1 folder still include also subfolders on it.

    In simple words i want exclude 3 domains (including subfolders to not tar) if i had 5 or more domains within /home/nginx/domains directory..
    i still don't get what's exclude command work for it..Already Google Fu about 2 hours but still hopeless..lol..
     
  9. eva2000

    eva2000 Administrator Staff Member

    36,850
    8,065
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,423
    Local Time:
    2:51 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    I suggest keep practising as there's no better feeling that conquering some obstacle and nailing a new piece of system admin know how ;) :)
     
..