Tar command and tar for full backup and Incremental Backup

Source: Internet
Author: User

Run the tar command and run the tar command to implement full backup and Incremental backup. First, find out what full backup, Incremental backup, and differential backup are. In short, it can be understood as follows: Full backup: A backup is performed on all files. Incremental Backup: the difference between this backup and the previous backup. Differential backup: Backup Based on full backup. A tar command [plain] # 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] # touchaa0133, 52.16.txt [root @ serv01 upload] # ls aa01.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 compressed package included file [root @ serv01 data] # tar-tf upload01.tar work/upload/aa03.txt work/upload/aa01.txt work/upload/aa04.txt work/upload/aa05.txt work/ 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.txt work/upload/aa01.txt work/upload/aa04.txt work/upload/aa05.txt work/upload/aa02.txt [root @ serv01 data] # ls/work upload [root @ serv01 data] # ls upload01.tar # contains the file path during compression [root @ 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 # You do not need to specify the file path when unzipping [r Oot @ serv01 data] # tar-xPvf upload02.tar/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/ work/upload/aa02.txt [root @ serv01 data] # ls/work/upload # 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 directory tar: removing leading '/' from member names/work/upload // work/upl Oad/aa03.txt/work/upload/aa01.txt/work/upload/aa04.txt/work/upload/aa05.txt/work/upload/aa02.txt work/upload/00007550000000000000000000000000121766767060120445 ustar rootrootwork/upload/aa03.txt00006440000000000000000000000000121766767060133170ustar rootrootwork/ upload/aa01.txt000064400000000000000000000000000000121766767060133150ustar rootrootwork/upload/aa04.txt00006440000000000000000000000000121 766767060133200 ustar rootrootwork/upload/aa05.txt00006440000000000000000000000000121766767060133210ustar rootrootwork/upload/aa02.txt000064400000000000000000000000001217667670601300000ustar rootroottar: exiting with failurestatus due to previous errors redirect to upload03.tar [root @ serv01 data] # tar-cv/work/upload/> upload03.tar: removing leading '/' from member names/work/upload // work/uploa D/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/# extract, specify the input source [root @ serv01 data] # tar-xv-C/<upload03.tar work/upload/aa03.txt work/upload/aa01.txt work/upload/aa04.txt work/upload /aa05.txt work/upload/aa02.txt # view [root @ serv01 data] # ls/work/upload [root @ serv01 data] # tar-tf upload03.tar work /Upload/work/upload/aa03.txt work/upload/aa01.txt work/upload/aa04.txt work/upload/aa05.txt work/upload/aa02.txt # test the different effects of path addition [root @ serv01 data] # cd/work/[root @ serv01 work] # tar-cf upload04.tarupload/[root @ serv01 work] # tar-tf upload04.tar upload/aa03.txt upload/aa01.txt upload/ aa04.txt upload/aa05.txt upload/aa02.txt # Will be decompressed to the upload directory under the root [root @ serv01 work] # tar-xv-C/<upload04.tar Upload/aa04.txt upload/aa05.txt upload/aa02.txt [root @ serv01 work] # ls/upload/aa01.txt aa02.txt aa03.txt upload temporary upload File [root @ serv01 upload] # touch aa06.txt [root @ serv01 upload] # cd/data [root @ serv01 data] # tar-tf upload02.tar: removing leading '/' from member names/work/upload // work/upload/aa03.txt/work/upload/aa01.txt/work/upl [Root @ serv01 data] # tar-Pvf upload02.tar-r/work/upload/aa04.txt in oad/aa04.txt/work/upload/aa06.txt/work/upload /aa06.txt [root @ serv01 data] # tar-tf upload02.tar 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/work/upload/aa06.tx T # After the demo file is modified, 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.tar 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/work/upload/aa06.txt/work/upload/aa01.t Xt # delete the file and 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 upload02.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/aa 01. txt this is aa01.txt # find the file ending with conf in etc, and 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 folder creates 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 conf01.tar 2 tar command implementation-full backup and Incremental Backup [plain] [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.txt contains aa02.txt, no [root @ serv01 data] # cat/work/upload/aa02.txt restore file found. [root @ serv01 data] # tar-g flag -xPvfupload02.tar/work/upload/work/ upload/aa02.txt/work/upload/aa07.txt contains the aa02.txt file, the content is returned. [root @ serv01 data] # cat/work/upload/aa02.txt hello world logs: 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

Related Article

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.