Shell Script notes (the original is constantly recorded)

Source: Internet
Author: User

Start your own shell script practice today, just as the company has too servers, to time the data of the CP is monthly:

Consider: First look for the law, found all placed in the/opt/www/aaa/there are a lot of 2 level and 3 levels of directories and files, but I track to back up is the date of the year as the file name format: 2015_06

In this format, first we don't know how many of these 2015_06 subdirectories are in this directory so we need to count:

Find/opt/www/aaa-name 2015_06 Look at the place I want to back up #!/bi#admin fengtaotao Email:23956580@ Qq.com

#Fri Jul3  -: *: -Cst -Pathh=/opt/www/acc/musicfile/@ First defined is the source file pathPATHD=/opt2/musicfile/@ The path to be backed upDatem=`Date+%m ' @ Here I define a display reason for the current month is that I am in crontab to back up is the last month's #getmonth @ simple Comment I like it. Comments are written under the line code if ["$datem" = =];th En @ Current month is January so current year-1 thereby back up last year's December
datem= "_12" @ If the current month is January then the stiffness variable is modified to December
datey= ' Date +%y '
datey=$ (($datey-1)) @ Change the year to last year it was last December.
Else
Datem= "_0$ (($datem-1))" Datey=`Date+%Y ' @ Considering the January of the year to back up last year's fi
#getFullYear

Dird="$datey $datem"#Echo "$dird"Readd=`Date+%N '. txtFind$pathh-name $dird &>>$readd forIinch$(Cat$readd); DoAAC=$(Echo$i |awk-F"/" '{print $6 "/" $7 "/"}') AAC=${PATHD}${AAC}CP-R $i $AAC &>> dbcp. Log DoneRM-RF $readd

OK Next Modify the permissions and the timing of the crontab

chmod u+x dbback. SH  -e011 * */root/bash/dbback. SH No. 1th in the month. 1 o'clock in the morning start backup

2. Of course I also wrote a manual backup script

#!/bin/bash#admin Fengtaotao Email:23956580@qq. Com#fri Jul3  -: *: -Cst -Pathh=/opt/www/morp/musicfile/PATHD=/opt2/musicfile/TouchUlist.txtreadd=Ulist.txt forAinch$(CatList.txt); Do    Find$pathh-name $a &>>$readd Done forIinch$(Cat$readd); DoAAC=$(Echo$i |awk-F"/" '{print $6 "/" $7 "/"}') AAC=${PATHD}${AAC}CP-R $i $aac &>>Dbcp.log DoneRM-RF $readd

We can create a list.txt document in the same directory as the script, and write a list of names that we need to back up. The default is to change the behavior by a name

Shell Script notes (the original is constantly recorded)

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.