about summary refs log blame commit diff stats
path: root/tools/tar.html
blob: dfcd3a0a9a8e0155f4b52c40fae79351cba5487f (plain) (tree)
1
2
3
4
5
6
7
8
9
10



                              
                          


           

                                            

 
                                              
 








                                                                            
                                                                                                          

                                                                                                     


















                                                                                
                                 
                               


                                








                            
                                                    













                                                                      
                                                            


















                                                                     
                                                  

















                                                                          
                                                    






                                                               

                                            
           


                                                       


                                                                                                                        
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>Tar</title>
    </head>
    <body>

        <a href="index.html">Tools Index</a>
        <h1>Tar</h1>


        <h2 id="tarbkup">1. Create Backup</h2>

        <p>To create a simple compressed tar;</p>

        <pre>
        $ tar -czvf tar_name.tar.gz /path/to/archive
        </pre>

        <p>Script
        <a href="scripts/backup-system.sh">core/scripts/backup-system.sh</a>
        use tldp
        <a href="http://tldp.org/LDP/lame/LAME/linux-admin-made-easy/server-backup.html">server backup</a>
        and
        <a href="http://tldp.org/LDP/lame/LAME/linux-admin-made-easy/server-restore.html">restore</a>
        as a reference.</p>

        <pre>
        #!/bin/sh

        echo -n "root directory you want backup (/mnt/): "
        read ROOT_DIR

        echo -n "where you want to save (/home/user): "
        read DEST_DIR

        echo -n "backup name (system_name): "
        read BCK_NAME

        echo $DES_DIR
        echo $ROOT_DIR

        tar --xattrs -zcpf $DEST_DIR/$BCK_NAME-`date '+%Y-%j-%H-%M-%S'`.tar.gz \
            --directory=$ROOT_DIR \
            --exclude=usr/ports \
            --exclude=usr/src \
            --exclude=var/run \
            --exclude=var/lock \
            --exclude=srv \
            --exclude=mnt \
            --exclude=home \
            --exclude=dev \
            --exclude=run \
            --exclude=tmp \
            --exclude=proc \
            --exclude=sys .
        </pre>

        <h2 id="tarview">2. View content of tar</h2>

        <p>List files inside tar;</p>

        <pre>
        $tar -tvf backup.tar.gz
        </pre>

        <p>To restore is better to use first t flag and then x,
        this prevents any --absolute-paths problem;<p>

        <pre>
        $ tar -ztvpf full-backup-11-November-2045.tar.gz &gt; file.lst
        </pre>

        <h2 id="tarextract">3. Extract content from tar</h2>

        <p>If you want to extrat to different directory;</p>

        <pre>
        $ tar xf full-backup-11-November-2045.tar.gz --directory=/mnt
        </pre>

        <p>If path is fine, extract everything;</p>

        <pre>
        $ tar --xattrs -xpvf full-backup-11-November-2045.tar.gz
        </pre>

        <p>Extract just one file;</p>

        <pre>
        $ tar --extract --file=core.tar.gz libidn#1.32-1.pkg.tar.gz
        </pre>

        <h2 id="taradd">4. Add content to tar</h2>

        <p>Only uncompressed tar can append files without having
        to extract and compress again.</p>

        <p>First create a tar with all files in the current directory;</p>

        <pre>
        $ tar cpf core.tar *.tar.gz
        </pre>

        <p>List files before appending new file and after;</p>

        <pre>
        $ tar -tvf core.tar
        $ tar --append --file=core.tar libidn#1.32-1.pkg.tar.gz
        $ tar -tvf core.tar
        </pre>

        <h2 id="tarrm">5. Remove content of tar</h2>

        <pre>
        $ tar -tvf core.tar
        $ tar --delete --file=core.tar libidn#1.32-1.pkg.tar.gz
        $ tar -tvf core.tar
        </pre>

        <a href="index.html">Tools Index</a>

        <p>
        This is part of the Tribu System Documentation.
        Copyright (C) 2020
        Tribu Team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a> for copying conditions.</p>
    </body>
</html>