Teach you how to easily master Informix data backup Tips

Source: Internet
Author: User
Tags informix backup

In the development of large-scale projects, a project team usually in a small simulation environment for the initial development, after the initial stability of the system, then move the development environment to the new system, and finally the old system to switch to the new system. However, in the simulation environment, the general database server configuration is low, and there will be no special data backup measures, once the power off or misoperation, it will be vulnerable to data loss, database damage, a developer's efforts will be wasted. Therefore, a simple and effective method of data backup is needed.

We assume that the operating system of the database server for the simulated environment is Rerhat Linux 7, the database server is Informix Online Dynamic Server 7.0, and the database name to be backed up is dbtemp. During the development process, we require that the database table structure and the data in it can be scheduled for automatic backup every day. So we need to use crontab to work on the schedule, crontab is to manipulate each user's daemon and the execution schedule.

crontab文件的格式:M H D m d cmd。
M: 分钟(0-59)。
H:小时(0-23)。
D:天(1-31)。
m: 月(1-12)。
d: 一星期内的天(0~6,0为星期天)。

CMD to run the program, the program was sent to SH execution, this shell only user,home,shell these three environment variables.

The root user edits the crontab file using the CRONTAB-E command, in this case the contents of the file are as follows:

#backup zhdata start;
24 15 * * * su -l -c "dbschema -d
dbtemp -ss /opt/informix/data/dbtemp.sql" informix
25 15 * * * su -l -c "dbaccess
dbtemp /opt/informix/data/create_unload.sql" informix
27 15 * * * su -l -c "dbaccess
dbtemp /opt/informix/data/unload.sql" informix
#backup zhdata end;

The first statement in the file specifies that the database dbtemp schema file Dbtemp.sql is created 3:24 P.M. every day, and the second statement specifies that the dbaccess execution Create_unload.sql file be used every 3:25 P.M., Create_ The contents of the Unload.sql file are as follows:

UNLOAD TO /opt/Informix/data/unload.sql DELIMITER ';'
SELECT "unload to /opt/informix/data/"||tabname||
".txt delimiter '$' select * from "||tabname
FROM systables WHERE tabid >; 99

This is a nested SQL statement that can find all tables except the system tables in the database. Assuming that the database has a user table Userinfo1,userinfo2,...., userinfon In addition to the system tables, the Unload.sql file content generated after executing the statement will be:

unload to /opt/Informix/data/userinfo1.txt
delimiter '$' select * from userinfo1;
unload to /opt/Informix/data/userinfo1.txt
delimiter '$' select * from userinfo2;
……
unload to /opt/Informix/data/userinfo1.txt
delimiter '$' select * from userinfon;

The 3rd statement then specifies that the Unload.sql file is executed using dbaccess every 3:27 P.M., and the Unload statement completes a text file that pours the contents of the table into the specified delimiter-delimited field; In this case, the Unload.sql file implements the table data from the system table in the exported database, generating A text file separated by the ' $ ' symbol, which is a text file separated by a ' $ ' symbol in the database except the system tables, stored under the/opt/informix/data directory. In this way, this simple data backup is done.

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.