A preliminary study on hierarchical backup of libraries

Source: Internet
Author: User

Read the 26 issue of the Wang Guide on MySQL sub-Library layered backup video, the script has generated interest, but the lack of knowledge of MySQL, some of the commands and some of the data is not very weak. But preface spent 3 hours of valuable learning time compiling a small script.

Script requirements: Now there is a dir file in/tmp with a name of 7 directories, one row for each name. There are also 7 files, such as Dirx_file, that contain the files that should be in the directory. The requirement now is to have the files and directories set up. and compressed to TMP under the collection of directories.

Script:

[Email protected] ~]# vim test.sh


Dirsource=/tmp/dir

For N in $ (cat $DIRSOURCE)

Do

[-d/test/$n] | | mkdir/test/$n

Filesource=/tmp/${n}_file

For M in $ (cat $FILESOURCE)

Do

touch/test/$n/$m

Done

Cd/test;tar zcf/tmp/test${n}_$ (Date +%f). tar.gz $n

Done

Process Summary: At the very beginning of the environment variable Dirsource defined is the Cat/tmp/dir.

The following prompt appears Test.sh:line 1:/tmp/dir:permission denied.

At the beginning of the thought is insufficient permissions, using the chmod command to test.sh added x permissions. This is still the case later on.

Looking back at the information about this part of the director Wang Video, I remembered that the previous variable referenced by him seemed to be a path.

This part of the content because of the knowledge of the environment variables, so we tried to go down the command, found that the script can be run. Let's just remember that later, when the teacher explained the environment variables in detail.

The current knowledge of environment variables only knows the last add statement in profile export can set environment variables.

Then continue running, found error test.sh:line 14:syntax error:unexpected end of file.

Self-study check found that the last done did not add, previously learned the C language impression is a do should be equipped with a done, the problem is mainly programming habits, need to pay attention to later.

Bug fix continues to run prompt command '-d ' not recognized.

Check the video to see if there is no problem, guess is that there is a space between the bracketed items and the brackets. After adding a space, the program runs normally.


Summary: This script has some vague understanding of the environment variables, and a more profound understanding of the for statement.

Subsequent: After a few days, the script is set to a timed task and the corresponding directory is established under TMP. is more convenient when looking for.


A preliminary study on hierarchical backup of libraries

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.