linux命令PV介绍

本次演示环境采用rpm安裝方式
rpm包下载安装
http://www.ivarch.com/programs/pv.shtmlhtml

简单使用介绍:mysql

复制文件限制到每秒1M到另外的目录下git

pv -L 1m 11.sql > /tmp/12.sql

复制文件夹到另一个文件夹下面:sql

把test01的文件夹复制到txt01文件夹下,限制每秒传输2M/s

 tar cf - "test01/" | pv -L 2m -s $(du -sb "test01/" | cut -f1) | tar xf - -C "txt01"

 [root@localhost tmp]# tar cf - "test01/" | pv -L 2m -s $(du -sb "test01/" | cut -f1) | tar xf - -C "txt01"
 233MiB 0:01:56 [2.00MiB/s] [===============================================================================================================================================>] 100%            
[root@localhost tmp]# ll test01/
总用量 239552
-rw-r--r--. 1 root root 245300506 9月  18 21:54 12.sql
-rw-------. 1 root root         0 9月  18 21:53 yum.log
[root@localhost tmp]# ll txt01/
总用量 0
drwxr-xr-x. 2 root root 35 9月  18 21:59 test01
[root@localhost tmp]# ll txt01/test01/
总用量 239552
-rw-r--r--. 1 root root 245300506 9月  18 21:54 12.sql
-rw-------. 1 root root         0 9月  18 21:53 yum.log

pv命令能够限制硬盘的io速度
pv命令限制文件的写入磁盘速率在每秒2M之内为例数据库

[root@localhost tmp]# tar zcf - txt01 |pv -L 2m >/tmp/txt01.tar.gz 
29.1MiB 0:00:14 [2.00MiB/s] [   <=>    ]
[root@localhost tmp]#

pv显示进度压缩文件:服务器

[root@localhost test01]# pv 12.sql | gzip > 12.sql.gz
 233MiB 0:00:09 [24.5MiB/s] [===============================================================================================================================================>] 100%            
[root@localhost test01]#

远程压缩备份而后拉取到本地服务器ssh

2台内网机器
192.168.1.217
192.168.1.220
提早2台机器之间实现相互免秘钥
从192.168.1.220机器本地要远程登陆192.168.1.217机器执行tar zcf 压缩打包/tmp/12.sql 文件而后传输到192.168.1.220机器本地ide

ssh -p5110 192.168.1.217 tar zcf - /tmp/12.sql | pv --wait --bytes --rate-limit 80M > projectx.tar.gz

必须使用--name命名pv的每一个实例,而且必须使用--cursor启用多行模式。 这两个选项结合在一块儿,建立了一系列带标签的指标,每一个命名实例一个指标。fetch

ssh -p5110 192.168.1.217 tar cf - /tmp/12.sql | pv --wait --name ssh | gzip | pv --wait --name gzip > projectx.tgz

[root@localhost test01]# ssh -p52110 192.168.1.217 tar cf - /tmp/12.sql | pv --wait --name ssh | gzip | pv --wait --name gzip > projectx.tgz
tar: 从成员名中删除开头的“/”
      ssh:  233MiB 0:00:09 [24.4MiB/s] [          <=>             ]
     gzip: 29.1MiB 0:00:09 [3.04MiB/s] [          <=>             ]
[root@localhost test01]# 

分析:第一行标记为ssh,显示了传输进度。 第二行标记为gzip,显示压缩的进度。 因为每一个命令没法肯定其各自操做中的字节数,所以累积的总数和活动条显示在每一行上。

繁忙的数据库上导入数据时如何最小化对线上库的影响:ui

若是当前线上的数据库处于繁忙的状态,能够采用下面的命令指定特定的SQL数据导入到指定的库,来减轻对当前线上库的压力

[root@mysql02 ~]# pv -p -a -L2m 2020-09-14.hlz_ad.sql|mysql test01 
[1.99MiB/s] [===========================================================================================================================================================================>] 100%
[root@mysql02 ~]# 

参数介绍: 
-p显示进度
-a显示平均速度
-L限制为2M

能够看到 CPU 已经很是冷静,而且缓慢的处理数据
[root@localhost ~]# find / -type f -name '*.c' -exec grep --files-with-match fopen \{\} \;|pv --line-mode
/usr/share/doc/libpng-1.5.13/example.c
/usr/share/doc/git-1.8.3.1/contrib/examples/builtin-fetch--tool.c
2.00  0:00:00 [2.80 /s] [   <=>
相关文章
相关标签/搜索