Table of Contents

Команда cpio

Создание архива

# cd /; find etc/ | cpio -o | bzip2 -c > /mnt/etc.cpio.bz2

# cd /; find etc/ -name '*,v' | sed -e 's/RCS\///' -e 's/,v//' | cpio -o | bzip2 -c > /mnt/etc.cpio.bz2

# cd /; find etc/ -ctime -1 | cpio -o | bzip2 -c | ssh archiveserver "cat > etc.cpio.bz2"

Просмотр содержимого архива

# bzcat /mnt/etc.cpio.bz2 | cpio -t

Распаковка отдельных файлов/каталогов архива

# cd /tmp; bzcat /mnt/etc.cpio.bz2 | cpio -id etc/clamav/clamd.conf

# cd /tmp; bzcat /mnt/etc.cpio.bz2 | cpio -id -E filelist.txt

Распаковка всего архива

# cd /tmp; bzcat /mnt/etc.cpio.bz2 | cpio -id

Варианты использования

Сценарий: бэкап фотографий из Apple iPhoto

[~ ] $ cat Pictures/backup/backup.sh 
#!/bin/sh

# Archive size
# export as=734003200 #CD
# export as=700000000 #CD
# export as=4831838208 #DVD
export as=8500000000 #DVDRDL

# Backup list file name
export bf=backup/backup`date "+%Y-%m-%d_%H-%M-%S"`_${as}.txt

export IFS=""

cd ~/Pictures
[ -e backup/full.txt ] && rm backup/full.txt
mkfifo backup/full.txt

find iPhoto\ Library -type f -exec ls -l {} \; > backup/full.txt &

cat backup/backup*.txt | fgrep -v -f - backup/full.txt | 
(
        s=0
        while read f
        do
                echo $f >> $bf
                s=$(($s+`echo "$f" | awk '{print $5}'`))
                test $s -gt $as && break 
        done
        test $s -gt $as && {
                echo "Success create list for archive"
                echo "File name: $bf"
                echo "Archive size: $s"
                sed 's/.*\(iPhoto Library.*\)/\1/' ${bf} | cpio -o > ${bf}.cpio
        } || {
                echo "No enought files for archive"
                echo "Need $as exists $s"
                rm $bf
        }
)
[ -e backup/full.txt ] && rm backup/full.txt