Tools Index

Tar

1. Create Backup

To create a simple compressed tar;

        $ tar -czvf tar_name.tar.gz /path/to/archive
        

Script core/scripts/backup-system.sh use tldp server backup and restore as a reference.

        #!/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 .
        

2. View content of tar

List files inside tar;

        $tar -tvf backup.tar.gz
        

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

        $ tar -ztvpf full-backup-11-November-2045.tar.gz > file.lst
        

3. Extract content from tar

If you want to extrat to different directory;

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

If path is fine, extract everything;

        $ tar --xattrs -xpvf full-backup-11-November-2045.tar.gz
        

Extract just one file;

        $ tar --extract --file=core.tar.gz libidn#1.32-1.pkg.tar.gz
        

4. Add content to tar

Only uncompressed tar can append files without having to extract and compress again.

First create a tar with all files in the current directory;

        $ tar cpf core.tar *.tar.gz
        

List files before appending new file and after;

        $ tar -tvf core.tar
        $ tar --append --file=core.tar libidn#1.32-1.pkg.tar.gz
        $ tar -tvf core.tar
        

5. Remove content of tar

        $ tar -tvf core.tar
        $ tar --delete --file=core.tar libidn#1.32-1.pkg.tar.gz
        $ tar -tvf core.tar
        
Tools Index

This is part of the Tribu System Documentation. Copyright (C) 2020 Tribu Team. See the file Gnu Free Documentation License for copying conditions.