Tar command and tar for full backup and Incremental Backup

Source: Internet
Author: User

First, find out what full backup, Incremental backup, and differential backup are. In short, it can be understood as follows:

  • Full backup: Back up all files once.
  • Incremental Backup: the difference between this backup and the previous backup.
  • Differential backup: Backup Based on full backup.
A tar command

# Create a test folder and file [root @ serv01 web] # cd/data [root @ serv01 data] # ls [root @ serv01 data] # mkdir/work [root @ serv01 Data] # mkdir/work/upload [root @ serv01 data] # cd/work/upload/[root @ serv01 upload] # parts [root @ serv01 upload] # lsaa01.txt aa02.txt aa03.txt aa04.txt aa05.txt # create a compressed package [root @ serv01 data] # tar-CVF upload01.tar/work/upload/tar: removing leading '/' from Member names/work/upload // work/ Upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/upload/aa02.txt # view the files contained in the package [root @ serv01 Data] # tar-TF upload01.tarwork/upload/work/upload/aa03.txtwork/upload/aa01.txtwork/upload/aa04.txtwork/upload/aa05.txtwork/upload/aa02.txt # delete data, simulate data loss [root @ serv01 data] # rm-RF/work # decompress [root @ serv01 data] # tar-xvf upload01.tar-C/work/upload/aa03.txtwork /upload /Aa01.txtwork/upload/aa04.txtwork/upload/aa05.txtwork/upload/aa02.txt [root @ serv01 data] # ls/workupload [root @ serv01 data] # contains the file path [root] during compression @ serv01 data] # tar-cpvf upload02.tar/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/ upload/aa05.txt/work/upload/aa02.txt # the file path does not need to be specified during decompression [root @ serv01 data] # tar-xpvf upload02.tar/work/upload // work/uplo AD/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/upload/aa02.txt [root @ serv01 data] # ls/work/upload # the F parameter is not required, you can use redirection to solve [root @ serv01 data] # tar-CV upload03.tar/work/upload/tar: upload03.tar: cannot stat: No suchfile or directorytar: removing leading '/' from Member names/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/ Work/upload/aa02.txtwork/upload/00007550000000000000000000000000121766767060120445 USTAR rootrootwork/upload/aa03.txt00006440000000000000000000000000121766767060133170ustar rootrootwork/upload/aa01.txt00006440000000000000000000000000121766767060133150ustar rootrootwork/upload/aa04.txt00006440000000000000000000000000121766767060133200ustar rootrootwork/upload/aa05.txt0000644000000000000000000000 121766767060133210 USTAR rootrootwork/upload/export rootroottar: exiting with failurestatus due to previous tables [root @ serv01 data] # tar-CV/work/upload/> upload03.tartar: removing leading '/' from Member names/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/ upload/ Aa02.txt # Delete the directory [root @ serv01 data] # rm-RF/work/# decompress, specify the input source [root @ serv01 data] # tar-XV-C/<upload03.tarwork/upload/work/upload/aa03.txtwork/upload/aa01.txtwork/upload/aa04.txtwork/upload /aa02.txt # view [root @ serv01 data] # ls/work/upload [root @ serv01 data] # tar-TF upload03.tarwork/upload/work/upload/aa03.txtwork/upload/aa01.txtwork/ upload/aa04.txtwork/upload/aa05.txtwork/upload/aa02. TXT # Different Effects of test path addition [root @ serv01 data] # cd/work/[root @ serv01 work] # tar-CF upload04.tarupload/[root @ serv01 work] # tar -TF upload04.tarupload/upload/parts/aa01.txtupload/aa04.txtupload/parts/aa02.txt # decompress the package to the [root @ serv01 work] # tar-XV-C/<upload04.tarupload /upload/aa03.txtupload/aa01.txtupload/aa04.txtupload/aa05.txtupload/aa02.txt [root @ serv01 work] # ls/upload/aa01.t XT aa02.txt aa03.txt aa04.txt aa05.txt create the aa06.txt file [root @ serv01 upload] # Touch aa06.txt [root @ serv01 upload] # cd/data [root @ serv01 data] # tar-TF upload02.tartar: removing leading '/' from Member names/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/ upload/aa02.txt#increase aa06.txtto [root @ serv01 data] # tar-pvf upload02.tar-r/work/upload/ Aa06.txt/work/upload/aa06.txt [root @ serv01 data] # tar-TF upload02.tartar: removing leading '/' from Member names/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/ upload/aa02.txt/work/upload/aa06.txt # After modifying the demo file, update the compressed package # edit the file [root @ serv01 data] # Vim/work/upload/aa01.txt # update [root @ serv01 data] # tar-upvf upload02.tar/work/upload // work/ upload/aa01.txt [root @ Serv01 data] # tar-TF upload02.tartar: removing leading '/' from Member names/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/ upload/aa02.txt/work/upload/aa06.txt/work/upload/aa01.txt # delete the file, then restore [root @ serv01 data] # rm-RF/work/[root @ serv01 data] # ls/work/* ls: cannot access/work /*: no such file or directory [root @ serv01 data] # tar-xpvf upload0 2. tar/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/upload/aa02.txt/work/upload /aa06.txt/work/upload/aa01.txt # view the file just updated, no problem found [root @ serv01 data] # Cat/work/upload/aa01.txtthis is aa01.txt # Find the file ending with conf under etc, then Package [root @ serv01 data] # Find/etc/-name "*. conf "| xargs tar-pcvf test01.tar # Find the file ending with conf under etc, but it does not contain yum. conf, and then package [root @ serv01 data] # Find /Etc/-name "*. conf "! -Name "yum. conf" | xargs tar-pcvf test02.tar [root @ serv01 data] # Find/etc/-name "*. conf "! -Name yum. conf | xargs tar-pcvf test02.tar # specify the file, and then back up # Write the configuration file to file1 [root @ serv01 data] # Find/etc-name "*. conf "> file1 # view the file. You can see that the list of all configuration files already exists (note the file path) [root @ serv01 data] # Vim file1#create conf01.tar, then T specifies the file [root @ serv01 data] # tar-cpvf conf01.tar-tfile1 [root @ serv01 data] # tar-TF conf01.tar [root @ serv01 data] # ls-H conf01.tar- l-RW-r -- r -. 1 Root 250 K Aug 2 18:18 conf01.tar

Two tar commands-full backup and Incremental Backup

[Root @ serv01 data] # ls/work/upload/aa01.txt aa02.txt aa03.txt aa04.txt aa05.txt aa06.txt [root @ serv01 data] # rm-RF upload01.tar # This is full backup, unable to implement the Incremental backup function [root @ serv01 data] # tar-cpvf upload01.tar/work/upload/# G specify the flag file [root @ serv01 data] # tar-G flag -cpvfupload01.tar/work /upload/tar: /work/upload: directory is new/work/upload // work/upload/aa01.txt/work/upload/aa02.txt/work/upload/aa03.txt/work/upload/aa04.txt/work/upload/aa05.txt/work /upload/aa06.txt [root @ serv01 data] # Vim flag # create a file [root @ serv01 data] # Touch/work/upload/aa07.txt # change the file [root @ serv01 data] # vim/work/upload/aa02.txt [root @ serv01 data] # tar-G flag -cpvfupload02.tar/work/upload // work/upload/aa02.txt/work/upload/ aa07.txt [root @ serv01 data] # tar-TPF upload02.tar/work/upload // work/upload/aa02.txt/work/upload/aa07.txt [root @ serv01 data] # Touch/work/ upload/aa08.txt [root @ serv01 data] # rm-RF/work/upload [root @ serv01 data] # ls/work/upload/aa02.txt aa03.txt aa04.txt aa05.txt aa06.txt aa07.txt aa08.txt [root @ serv01 data] # tar-G flag -cpvfupload03.tar/work/upload // work/upload/aa08.txt # restore full backup, successive recovery # data loss [root @ serv01 data] # rm-RF/work/* [root @ serv01 data] # ls/work/# restore full backup [root @ serv01 Data] # tar-G flag -xpvfupload01.tar/work/upload // work/upload/aa01.txt/work/upload/aa02.txt/work/upload/aa03.txt/work/upload/aa04.txt/work/upload/ aa05.txt/work/upload/aa06.txt # The data returned [root @ serv01 data] # ls/work/upload/aa01.txt aa02.txt aa03.txt aa04.txt aa05.txt aa06.txt1_aa02.txt file, the content is not found in [root @ serv01 data] # Cat/work/upload/aa02.txt.pdf restore the file, from the upload02.tar file [root @ serv01 data] # tar-G flag -xpvfupload02.tar/work/upload//aa02.txt/work/upload/aa07.txt1_aa02.txt file, the content is returned. [root @ serv01 data] # Cat/work/upload/aa02.txthello world‑restore the file, and [root @ serv01 data] # tar-G flag -xpvfupload03.tar/work/upload/tar: deleting '/work/upload/aa01.txt'/work/upload/aa08.txt [root @ serv01 data] # ls/work/upload/aa02.txt aa03.txt aa04.txt aa05.txt aa06.txt aa07.txt aa08.txt

My mailbox: wgbno27@163.com Sina Weibo: @ wentasy27 public platform: justoracle (No.: justoracle) database technology exchange group: 336882565 (when adding group verification from csdn XXX) Oracle Exchange discussion group: https://groups.google.com/d/forum/justoracleBy Larry Wen
 
@ Wentasy blog is for your reference only. Welcome to visit. I hope to criticize and correct any mistakes. If you need to repost the original blog post, please indicate the source. Thank you for the [csdn blog]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.