about summary refs log tree commit diff stats
path: root/tools/tar.html
blob: 1cafbb6acfda728a1061c66ad848ff80da2551f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!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 c9-doc Manual.
        Copyright (C) 2016
        c9 team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a> for copying conditions.</p>
    </body>
</html>