Regular backup of gadgets in configuration files and configuration tables, configuration file configuration backup

Source: Internet
Author: User

Regular backup of gadgets in configuration files and configuration tables, configuration file configuration backup

 

The currently maintained configuration files/tables are all manually backed up by people. The last time a machine went down, I wanted to pull the application on another machine. When I went to find the backup, I found that the latest backup was last year, therefore, with this idea, we can write such a small tool for regular backup. In fact, it is still necessary to back up data every day. If something goes wrong, you can also find the start date, right?

 

The design idea is to first back up the files on which machines and the tables in which databases need to be put into the database, then create a shell and start the shell on a machine, use ftp to back up the configuration file and use exp to go To the dmp database file to complete the backup.

 

The first part is the database design. Two tables are required:

"Machine table ":

Create table MONI_SYS_MACHINE

(

Machine_id NUMBER not null,

Machine_type CHAR (1 ),

Machine_info VARCHAR2 (20 ),

Machine_name VARCHAR2 (20 ),

Machine_class VARCHAR2 (10 ),

Shortname VARCHAR2 (10 ),

Username VARCHAR2 (20 ),

Userpasswd VARCHAR2 (100)

)

Comment on column MONI_SYS_MACHINE.machine_id

Is 'machine ID ,';

Comment on column MONI_SYS_MACHINE.machine_type

Is 'machine type, M stands for host D stands for database ';

Comment on column MONI_SYS_MACHINE.machine_info

Is 'machine information, fill in oracle, AIX, linux, etc., to facilitate future extension of shell and other things ';

Comment on column MONI_SYS_MACHINE.machine_name

Is 'machine name, IP address for host, tns' for database ';

Comment on column MONI_SYS_MACHINE.machine_class

Is 'machine classification, used to execute scripts in batches ';

Comment on column MONI_SYS_MACHINE.shortname

Is 'machine alias, used for machine login without a password ';

Comment on column MONI_SYS_MACHINE.username

Is 'username ';

Comment on column MONI_SYS_MACHINE.userpasswd

Is 'encrypted password ';

Note: For this tool, machine classification, machine alias, and machine information have no practical significance.

 

 

Backup configuration table:

Create table MONI_BACKINFO_CFG

(

Required _id NUMBER not null,

Machine_id NUMBER,

Backpath VARCHAR2 (1024 ),

Backcycle NUMBER,

Lastbacktime DATE

)

Comment on column MONI_BACKINFO_CFG.cfg_id

Is 'configuration id ';

Comment on column MONI_BACKINFO_CFG.machine_id

Is 'machine id ';

Comment on column MONI_BACKINFO_CFG.backpath

Is 'backup directory. For the host, it can be the backup directory name or file name. For the database, it is the table name ';

Comment on column MONI_BACKINFO_CFG.backcycle

Is 'backup cycle, by Day ';

Comment on column MONI_BACKINFO_CFG.lastbacktime

Is 'last backup date ';

 

 

SHELL:

1: Read the configuration from the database. The read logic is as follows:

Select. required _id | '#' | trim (. backpath) | '#' | trim (B. machine_name) | '#' | trim (B. username) | '#' | trim (B. userpasswd) | '##' | trim (B. machine_type)

From moni_backinfo_cfg a, moni_sys_machine B where a. machine_id = B. machine_id and sysdate-nvl (a. lastbacktime, sysdate-1)> = a. backcycle

After obtaining the data, use your Decryption Method to decrypt the ciphertext password.

 

2: For host file directory/file backup, I use the wget tool (there are others, depending on your hobbies and what is installed on the machine ).

Wget ftp: // $ {machine_name}/$ {backpath} -- ftp-user =$ {username} -- ftp-password =$ {userpasswd}-r-T 2-t 1-P $ {thislocalpath}/data >$ {WGETLOG} 2> & 1

 

3: For databases, I only use oracle here and use the exp tool dump file:

Exp $ {username}/$ {userpasswd} @ $ {machine_name} tables =$ {backpath} file =. /$ {backpath }. dmp >>$ {DMPLOG} 2> & 1

4: After the backup is completed, compress the backup and package it, and move the backup directory by date.

 

 

The overall effect is as follows:

21_billxxx % pai_bakfile.sh

20161222 backup starts

Create directory/data05/cmd_bakfile/20161222

Start to back up 172.20.31.98:/app/billxxx/template

Start packaging 172.20.31.98: template

End backup 172.20.31.98:/app/billxxx/template

Start backing up ACCTDB_JF_OLDCRM: moni_sys_machine

Start packaging./moni_sys_machine.dmp.tar.gz

End backup ACCTDB_JF_OLDCRM: moni_sys_machine

20161222 backup complete

 

21_billxxx % pwd

/Data05/pai_bakfile/20161222/ACCTDB_JF_OLDCRM

21_billxxx % ls

Moni_sys_machine.dmp.tar.gz

 

In addition, it should be noted that the wget tool is used because ftp is used and locked files cannot be downloaded (such as the charged xfer configuration file). In this case, my solution is to get a crontab on the host and copy it to another directory before downloading it. I don't know if there are other good solutions?

 

You can leave a message to obtain the script.

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.