linux命令PV介绍

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

简单使用介绍:

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

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

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

把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
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

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]# 
  • 1.
  • 2.
  • 3.

pv显示进度压缩文件:

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

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

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机器本地

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

必须使用–name命名pv的每个实例,并且必须使用–cursor启用多行模式。 这两个选项结合在一起,创建了一系列带标签的指标,每个命名实例一个指标。

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,显示压缩的进度。 由于每个命令无法确定其各自操作中的字节数,因此累积的总数和活动条显示在每一行上。
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

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

如果当前线上的数据库处于繁忙的状态,可以采用下面的命令指定特定的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 已经非常冷静,并且缓慢的处理数据
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
[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] [   <=>    
  • 1.
  • 2.
  • 3.
  • 4.
posted @   勤奋的蓝猫  阅读(5)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示