linux c数据库备份第二版
#想知道更多请查看第一版"linux c数据库备份第一版"
#include<sys/types.h>
#include<sys/wait.h>
#include<ctype.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h> //待备份的数据表文件(一个数据库一行)
#define DB_FILE "./db_list"
//最多可以备份的数据库数量
#define NUM 20
//一个数据库名字的最长字符数
#define LEN 128
//保存从DB_FILE中读取到的数据库
char *db_list[NUM];
//从DB_FILE文件中读取到的数据库数量
int read_num;
//请求内存函数
void malloc_dblist();
//释放内存函数
void free_dblist();
//读取数据库文件
void readDbFile(); int main(int argc, char *argv[]) {
pid_t pid;
int i;
char buf[LEN]; //从文件读取数据库信息
readDbFile(); pid = fork(); if (pid < ) {
fprintf(stderr, "fork error\n");
exit();
} switch (pid) {
case -:
fprintf(stderr, "fork failed\n");
exit();
case :
//子进程进行数据库的备份
for (i = ; i < read_num; i++) {
memset(buf, '\0', LEN);
sprintf(buf, "%s%s%s%s%s", "mysqldump -uroot ", db_list[i], " > ", db_list[i], ".sql");
system(buf);
printf("%d,%s\n", i, buf);
}
break;
}
//等待子进程的结束
if (pid > ) {
int stat_val;
pid_t child_pid; child_pid = wait(&stat_val); if (!WIFEXITED(stat_val)) {
fprintf(stdout, "Child terminated abnormaly\n");
}
exit(); } free_dblist(); exit(); } void malloc_dblist()
{
int i = ;
//malloc for db_list
for (i = ; i < NUM; i++) {
db_list[i] = malloc(LEN);
memset(db_list[i], '\0', LEN);
}
}
void free_dblist()
{
int i;
//free db_list's memory
for (i = ; i < NUM; i++) {
free(db_list[i]);
}
} void readDbFile()
{
FILE *fp; fp = fopen(DB_FILE, "r");
if (!fp) {
fprintf(stderr, "%s not found\n", DB_FILE);
}
else {
malloc_dblist(); read_num = ;
while (fscanf(fp, "%127[^\r\n]\n", db_list[read_num]) == ) {
puts(db_list[read_num]);
read_num++;
} fclose(fp);
} }
linux c数据库备份第二版的更多相关文章
- linux c数据库备份第四版
该版本算是比较成熟的啦,欢迎大伙拿来试用!!!1.新增数据库连接和备份时间配置文件conf2.新增日志文件,程序运行的一些异常会记录在log文件下 后续的工作:1.将代码切割为多个文件,分类存放代码2 ...
- linux c数据库备份第五版
linux下c实现的数据库备份程序终于迎来第五版啦,这样改程序就暂告一段落啦,有点小激动呢...接下来的一周(可能两周)时间里,我会用一个小型的网络游戏(比拼99乘法)作为我学习linux c的毕业之 ...
- linux c数据库备份第一版
使用linuxC实现的mysql数据库备份目标:通过alarm信号定时备份数据库备注:目前是第一个版,本身不能定时备份可以结合linux自动化实现定时备份.运行平台:Linux或类unix测试平台:u ...
- Linux下数据库备份
1.登录数据库服务器并切换到数据库用户下 [root@*** ~]# su - oracle 2.测试用户名密码是否能正确连接数据库 [oracle@*** ~]$ sqlplus username/ ...
- linux c数据库备份第三版
这个版本相对第一版更新了很多,其实我本地定义为第五版的.相对第一版主要更新内容:1.增加了定时器2.用户可以停止调备份程序3.如果备份程序正在运行,那么尝试运行提示已经在运行4.记录程序运行时的pid ...
- Linux下数据库备份恢复过程
1. 远程进入Linux服务器. 2. 一般登录的是root用户, 第一步切换到Oracle用户, 命令: su - oracle 3. 查看服务器上面数据库的监听的状况 lsnrctl 之后输入命令 ...
- Linux文件系统管理命令(第二版)
Linux文件系统管理命令 常用命令 1.df命令 查看分区使用情况 常用选项 -h 比较人性化 -m 以兆字节显示分区使用情况 显示信息: Mounted on:挂载点 Filesystem:对应的 ...
- Linux用户管理命令(第二版)
添加用户 1.useradd -设置选项 用户名 [-D 查看缺省参数 ] 选项: u: UID [必须是系统中没有的] g:缺省所属用户组GID[最好有] G: 指定用户所属多个组[可以指定这个用户 ...
- Linux特殊权限分析(第二版)
SetUID[权限值=4] 问题:为什么普通用户可以修改自己的密码? ll $(which passwd) 1.SetUID:当一个可执行程序/命令具有SetUID 权限,用户执行这个程序时,将以这个 ...
随机推荐
- python多线程机制
Python中的线程从一开始就是操作系统的原生线程.而Python虚拟机也同样使用一个全局解释器锁(Global Interpreter Lock,GIL)来互斥线程多Python虚拟机的使用. GI ...
- O - Extended Traffic(判断负环)
题意:有n个城市,每一个城市有一个拥挤度ai,从一个城市I到另一个城市J的时间为:(aJ-aI)^3,存在负环.问从第一个城市到达第k个城市所话的时间,如果不能到达,或者时间小于3输出?否则输出所花的 ...
- Spring和MyBatis实现数据的读写分离
移步: http://blog.csdn.net/he90227/article/details/51248200
- Genymotion开始搞起~
简介 一:什么是GenymotionGenymotion是一款完全超越BlueStacks的安卓模拟器,正如它中文官网的介绍:快到极致的Android模拟器.英文官网:http://www.genym ...
- Demo_玩家移动(主要注意动画的设置)
using UnityEngine; using System.Collections; public class NewPlayerMove : MonoBehaviour { private fl ...
- SQLServer中使用索引视图(物化视图)
物化视图:以前用的普通的视图,普通视图就是一段逻辑语句,对性能没有任何的提升,也不能创建索引,而物化视图会把视图里查询出来的数据在数据库上建立快照,它和物理表一样,可以创建 索引,主键约束等等,性能会 ...
- Linux下tomcat使用
http://tomcat.apache.org/download-70.cgi这里下载 放到Linux目录下,解压开, 默认port:8080能够直接使用 经常使用启动命令catalina.sh ...
- FACTORY设计模式【让吃货也能理解的程序】
一个人要有思想,技术再牛的人,如果没有一点点文化气氛,那么也是个码农,不能追到女朋友滴. 我这个人文化真心不多,但是比较喜欢读古诗文.虽然读完之后,记在脑海里的不多,不过,就讨一个喜欢[读]. Lee ...
- [ES6] Array.find()
Convenient method to find one item in an array, avoid writing and for + if: let arys = [1,,5,,6] ; ...
- [Angular 2] Pipes with Multiple Parameters
Showing how to set up a Pipe that takes multiple updating inputs for multiple Component sources. imp ...