Informix Data Backup skills

Source: Internet
Author: User
Tags informix

In large-scale project development, a project team usually carries out initial development in a small simulated environment. After the system is initially stable, move the development environment to the new system, finally, the old system is switched to the new system. However, in a simulated environment, database servers are generally poorly configured, and no special data backup measures are available. Once the power is down or incorrect, data loss or database destruction may easily occur, the painstaking efforts of developers will be wasted. Therefore, a simple and effective data backup method is required.
Assume that the operating system of the database Server in 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 need to be able to automatically back up the database table structure and data on a daily basis. Therefore, we need to use crontab for the work schedule. crontab is used to operate the daemon of each user and the execution schedule. Crontab file format: m h d m d cmd.
M: minute 0-59 ).
H: hour 0-23 ).
D: Day 1-31 ).
M: Month 1-12 ).
D: The day of a week ~ 6, 0 is Sunday ).
The program to be run by cmd is sent to sh for execution. The shell contains only three environment variables: USER, HOME, and SHELL.
The root user uses the crontab-e command to edit the crontab file. In this example, the file content is 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 dbtemp is created at 03:24 P.M. every day. SQL; the second statement specifies that the create_unload. SQL file is executed by dbaccess at 03:25 P.M. every day. The content of the create_unload. SQL file is as follows: UNLOAD TO/opt/Informix/data/unload. SQL DELIMITER ';'
SELECT "unload to/opt/informix/data/" | tabname |
". Txt delimiter '$ 'select * from" | tabname
FROM tables Ables WHERE tabid> 99
This is a nested SQL statement that can be used to find all the tables in the database except the system table. Assume that in addition to system tables, there are also user tables userinfo1, userinfo2 ,...., Userinfon, the unload. SQL file generated after the statement is executed 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;
Then, 3rd statements specify that dbaccess is used to execute unload at 03:27 P.M. every day. in the SQL file, the unload statement is used to convert the data in the table into a text file that separates fields with the specified delimiter. In this example, unload. the SQL file exports data from tables other than the system table in the database and generates text files separated by '$, that is to say, the data in all tables except the system table is imported into a text file separated by '$' and stored in the/opt/Informix/data directory. In this way, a simple data backup is complete.


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.