Linux+shell Administrator's Good helper--batch decompression

Source: Internet
Author: User

Linux+shell Administrator's Good helper--batch decompression

Recently, the company has been busy with OA on-line work, as an administrator, it is necessary to provide them with data backup and recovery operations, the main operation is to restore the production environment change data to the test machine for testing. Of course, some of the previous articles have also introduced to the use of shell scripts to back up data and restore data, today we introduce the use of shell script to the specified directory of data compression backup and decompression coverage operation, see below:

First, the first script is introduced:

The script will compress the 123, Gavin folder in the/oafs directory and move it to the specified directory;

#!/bin/bashsources= "/oafs/123/oafs/gavin" target= "/oafs/bak_dir/" function Successfulllog () {echo "$ (date +%y-%m-%d_ %h:%m:%s)-Backup directory: $ $1.tar.gz and MV $target is successful ">>/var/log/tarbak.log}function Faildlog ( {echo "$ (date +%y-%m-%d_%h:%m:%s)-Backup directory: $ $1.tar.gz and MV $target is Faild" >>/VAR/LOG/TARBAK.L Og}for source in $sourcesdoif [-D "$source"]; THENTAR-ZCPF "$source". tar.gz $sourcemv $source. tar.gz $targetsuccessfulllog $sourceelsefaildlog $sourcefidone

The second script: we need to compress the files and folders in the specified directory separately and then move them to the specified directory:

Note: When the script executes, if there is a file, the file format will be renamed compressed file name: No similar format will appear a.txt.tar.gz

#!/bin/bashsources=/oafs/abc/datatarget=/oafs/bak_dircd $sourcesfor source in ' ls ';d o[-F "$source"]&& a=${ source%%.*}| | A= $sourcetar cvzfp $a. tar.gz $sourcemv $a. tar.gz $targetdone

The third script: bulk execution of the specified directory to specify the file's decompression to the specified directory;

The script will decompress the compressed files in the/OAFS/ABC directory, and then the extracted files will be marked under the TAR command.

#!/bin/bashsources= "/oafs/abc/" target= "/oafs/" echo ": ${sources}:" CD $sourcespwdtar-ZXVF zhangsan.tar.gz-c $ TARGETTAR-ZXVF lisi.tar.gz-c $target

Note: If you need to unzip all the compressed files in the specified directory, we only need to modify the format to

TAR-ZXVF *.tar.gz

The fourth script, batch execution file deletion, we are also the most stupid way to delete, because the specified directory has more than one file, you need to delete the specified file

#!/bin/bashsources= "/oafs/abc/" target= "/oafs/" echo ": ${sources}:" CD $sourcespwdrm-RF ZHANGSANRM-RF Lisi

V: Bulk Move the specified file

Move files in bulk

#!/bin/bashsources= "/oafs/abc/" target= "/oafs/" echo ": ${sources}:" CD $SOURCESPWDMV zhangsan.tra.gz $TARGETMV Lisi.tar.gz $target

This article from "Gao Wenrong" blog, declined reprint!

Linux+shell Administrator's Good helper--batch decompression

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.