Backup, archive, compress Linux files tricks

Backup, archive, compress Linux files tricks

==================

Some of Linux Backup Utilities are

cpio tar gzip bzip2 xz dd rsync dump restore mt

Also exist some Backup Programs for Linux like Amanda and Bacula

Some commands you may use with the Backup Utilities above are [/dev/st0 tape exist the backup or other storage medium]

cpio
ls | cpio --create -o /dev/st0  # create an archive

cpio -i *.c -I /dev/st0   
# extract *.c files from archive if no RE all extracted

cpio -t -I /dev/st0  # list archive contents

tar
tar --create --file /dev/st0 /root  
tar -cvf /dev/st0 /root
tar cvf file.tar dir1  # "-" is optional for tar command
# create an archive

tar --extact --same-permissions --verbose --file /dev/st0
tar -xpvf /dev/st0
tar xpvf /dev/st0
# extract from archive

tar xvf /dev/st0 *.c  # restore only *.c files

tar --list --file /dev/st0  # list contents of tar backup
tar -tf /dev/st0

gzip, bzip, xz

tar zcvf source.tar.gz source  # compress as gz in combination with tar 

tar jcvf source.tar.bz2 source  # compress as bzip in combination with tar 

tar Jcvf source.tar.xz source  # compress as xz in combination with tar 

these commands are more efficient than the two together commands:
tar cvf source.tar source ; gzip -v source.tar  # because this has intermediate step but above archiving and compression happen same time

extraction
tar xzvf source.tar.gz
tar xjvf source.tar.bz2
tar xJvf source.tar.xz

modern version of tar detect compression used auto and Not needed z in extraction
tar xvf source.tar.gz

rsync  // Synchronize the two file system locations - or between the network machines(folders of)
rsync file.tar someone@backup.mydomain:/usr/local
rsync -r a-machine:/usr/local b-machive:/usr/
rsync -r --dry-run /usr/local /BACKUP/usr