Systolls Index

2. Tar

2.1. Create Backup

Script in 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=srv \
            --exclude=var/ports \
            --exclude=var/run \
            --exclude=usr/src \
            --exclude=mnt \
            --exclude=home \
            --exclude=dev \
            --exclude=run \
            --exclude=tmp \
            --exclude=proc \
            --exclude=sys .
        

1.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
        

1.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
        

1.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
        

1.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
        
Systolls Index

This is part of the c9-doc Manual. Copyright (C) 2016 Silvino Silva. See the file Gnu Free Documentation License for copying conditions.