shell编程系列25--shell操作数据库实战之备份MySQL数据,并通过FTP将其传输到远端主机

备份mysql中的库或者表

mysqldump
常用参数详解:
-u 用户名
-p 密码
-h 服务器ip地址
-d 等价于--no-data 只导出表结构
-t 等价于--no-create-info 只导出数据,不导出建表语句
-A 等价于--all-databases
-B 等价于--databases 导出一个或多个数据库 需求:将school中的score表备份,并且将备份数据通过ftp传输到 10.11.0.148(windows) 的ftp的 bak 目录下 FTP常用指令:
open 与FTP服务器建立连接,例子:open 10.11.0.148
user 有权限登录FTP服务器的用户名和密码,例子:user ftpuser ftpuser # 备份school库
[root@localhost shell]# mysqldump -udbuser -p123456 -h 10.11.0.215 school >school.sql
# 备份school库下的score表
[root@localhost shell]# mysqldump -udbuser -p123456 -h 10.11.0.215 school score >score.sql
# -A备份所有数据库,所有有权限的数据库
# mysqldump -udbuser -p123456 -h 10.11.0.215 -A >score.sql [root@localhost shell]# sh auto_backup.sh aaa
Connected to 10.11.0.148 (10.11.0.148).
-FileZilla Server 0.9. beta
-written by Tim Kosse (tim.kosse@filezilla-project.org)
Please visit https://filezilla-project.org/
Remote system type is UNIX.
Password required for ftpuser
Logged on
CWD successful. "/bak" is current directory.
local: aaa remote: aaa
Entering Passive Mode (,,,,,)
Opening data channel for file upload to server of "/bak/aaa"
Successfully transferred "/bak/aaa"
bytes sent in 9.4e-05 secs (53.19 Kbytes/sec)
Goodbye
[root@localhost shell]# cat auto_backup.sh
#!/bin/bash
# db_user="dbuser"
db_password=""
db_host="10.11.0.215" ftp_user="ftpuser"
ftp_password="ftpuser"
ftp_host="10.11.0.148" src_dir="/data01/bak"
dst_dir="/bak" function auto_ftp
{
ftp -niv << EOF
open $ftp_host
user $ftp_user $ftp_password cd $dst_dir
put $
bye
EOF
} auto_ftp aaa # 自动备份数据库并传输备份文件到ftp的脚本 [root@localhost shell]# cat auto_backup.sh
#!/bin/bash
# # 需要备份的数据库的账号信息
db_user="dbuser"
db_password=""
db_host="10.11.0.215" # 远端ftp服务器的信息
ftp_user="ftpuser"
ftp_password="ftpuser"
ftp_host="10.11.0.148" # 源目录,目标目录
src_dir="/data01/bak"
dst_dir="/bak/"
time_date="`date +%Y%m%d%H%M%S`"
# 备份文件名,根据当前的年月日时分秒 作为文件名
file_name="school_score_${time_date}.sql" function auto_ftp
{
ftp -niv << EOF
open $ftp_host
user $ftp_user $ftp_password cd $dst_dir
put $
bye
EOF
}
#chown -R ftpuser.ftpuser /data01
#auto_ftp "/data01/bak/school_score_20190612181401.sql"
# 备份数据
mysqldump -u"$db_user" -p"$db_password" -h"$db_host" school score > $file_name && auto_ftp $file_name # 执行脚本
[root@localhost shell]# sh auto_backup.sh
Connected to 10.11.0.148 (10.11.0.148).
-FileZilla Server 0.9. beta
-written by Tim Kosse (tim.kosse@filezilla-project.org)
Please visit https://filezilla-project.org/
Remote system type is UNIX.
Password required for ftpuser
Logged on
CWD successful. "/bak" is current directory.
local: school_score_20190612182616.sql remote: school_score_20190612182616.sql
Entering Passive Mode (,,,,,)
Opening data channel for file upload to server of "/bak/school_score_20190612182616.sql"
Successfully transferred "/bak/school_score_20190612182616.sql"
bytes sent in 7.9e-05 secs (29734.18 Kbytes/sec)
Goodbye 搭建windows的ftp服务



shell编程系列25--shell操作数据库实战之备份MySQL数据,并通过FTP将其传输到远端主机的更多相关文章

  1. shell编程系列24--shell操作数据库实战之利用shell脚本将文本数据导入到mysql中

    shell编程系列24--shell操作数据库实战之利用shell脚本将文本数据导入到mysql中 利用shell脚本将文本数据导入到mysql中 需求1:处理文本中的数据,将文本中的数据插入到mys ...

  2. shell编程系列23--shell操作数据库实战之mysql命令参数详解

    shell编程系列23--shell操作数据库实战之mysql命令参数详解 mysql命令参数详解 -u 用户名 -p 用户密码 -h 服务器ip地址 -D 连接的数据库 -N 不输出列信息 -B 使 ...

  3. shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查)

    shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查) Shell脚本与MySQL数据库交互(增删改查) # 环境准备:安装mariadb 数据库 [ro ...

  4. shell编程系列26--大型脚本工具开发实战

    shell编程系列26--大型脚本工具开发实战 大型脚本工具开发实战 拆分脚本功能,抽象函数 .function get_all_group 返回进程组列表字符串 .function get_all_ ...

  5. shell编程系列7--shell中常用的工具find、locate、which、whereis

    shell编程系列7--shell中常用的工具find.locate.which.whereis .文件查找之find命令 语法格式:find [路径] [选项] [操作] 选项 -name 根据文件 ...

  6. shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计

    shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计 shell中的数组的用法: shell数组中的下标是从0开始的 array=("Allen" & ...

  7. shell编程系列18--文本处理三剑客之awk动作中的条件及if/while/do while/for循环语句

    shell编程系列18--文本处理三剑客之awk动作中的条件及if/while/do while/for循环语句条件语句 if(条件表达式) 动作1 else if(条件表达式) 动作2 else 动 ...

  8. shell编程系列17--文本处理三剑客之awk动作中的表达式用法

    shell编程系列17--文本处理三剑客之awk动作中的表达式用法 awk动作表达式中的算数运算符 awk动作中的表达式用法总结: 运算符 含义 + 加 - 减 * 乘 / 除 % 模 ^或** 乘方 ...

  9. shell编程系列14--文本处理三剑客之awk的概述及常用方法总结

    shell编程系列14--文本处理三剑客之awk的概述及常用方法总结 awk是一个文本处理工具,通常用于处理数据并生成结果报告 awk的命名是它的创始人 Alfred Aho.Peter Weinbe ...

随机推荐

  1. Something is already running on port 3000. Would you like to run the app on another port instead?

    查看端口sudo lsof -i :3000 删除进程 sudo kill -9 12297[pid]  

  2. Luogu P1339 热浪Heat Wave

    Luogu P1339 热浪Heat Wave 裸·单源最短路. 但是! 有以下坑点: 算过复杂度发现Floyd跑不过去就不要用了. 如果建边是双向边,边的数组大小要开两倍! 考场上如果再把初始化的$ ...

  3. 神经网络(14)--具体实现:put it together

    如何选择神经网络的architecture input units和output units都很好决定,关于hidden layer的层数,则一般来说是选择一个hidden layer, 或者> ...

  4. CheckList 如何梳理可减少上线的验证时间(总结篇)

    对CheckList的执行发起的思考? (1)功能越来越多,CheckList越补充越多,执行CheckList时间越来越长,如何减少上线的验证时间?(2)减少上线验证的时间外,如何保证质量?上线后少 ...

  5. 09 webpack的介绍

    webpack干嘛的?:  模块打包机,分析目录结构,找到js模块(包括浏览器不能直接识别的代码 typscript sass...),打包成合适的格式供浏览器访问 webpack是一款模块加载器兼打 ...

  6. 4、MapReduce思想、运行机制

    MapReduce 离线计算框架 分而治之 input > map > shuffle > reduce > output 分布式并行的计算框架 将计算过程分为两个阶段,Map ...

  7. [Schematics] 1. Copy and Manipulate Template

    1. Create a src/my-component/files/src/app directory to hold your templates. mkdir -p src/my-compone ...

  8. linux学习2 Linux云计算学习环境介绍

    一.VNC: Virtual Network Computing协议.虚拟网络计算协议. vncviewer:client vncserver:server

  9. 检测 nginx 关闭切换keepalived

    检测nginx 端口启用  关闭 keepalived  检测 nginx 进程:然后关闭 keepalived ,关闭漂移IP : cat nginx_pid.sh #!/bin/bash whil ...

  10. 洛谷P5017摆渡车

    题目 一道做法多种多样的题,DP做法的状态也很多. 我用\(dp[i]\)表示在第i秒发车的时间和,然后dp方程就很好写了 \(dp[i] = dp[j] + i车的等待时间\)j属于i-2m ~ i ...