1.1. 安装和帮助
PV 全命为Pipe Viewer,利用它我们可以查看到命令执行的进度。
# wgethttp://www.ivarch.com/programs/sources/pv-1.5.3.tar.bz2
# tar xjfpv-1.1.4.tar.bz2
# cdpv-1.1.4
#./configure
# make&& make install
例:需要将/home/opt 目录下打包文件名称为[email protected]
# tar -p -cf - /home/opt | pv --size `du -sk /home/opt | cut -f 1`k | gzip>/home/[email protected]`date +%y-%m-%d`.tar.gz
[[email protected]]# pv --help
Usage: pv[OPTION] [FILE]...
ConcatenateFILE(s), or standard input, to standard output,
withmonitoring.
-p, --progress show progress bar
-t, --timer show elapsed time
-e, --eta show estimated time of arrival(completion)
-r, --rate show data transfer rate counter
-a, --average-rate show data transfer average rate counter
-b, --bytes show number of bytes transferred
-T, --buffer-percent show percentage of transfer buffer in use
-A, --last-written NUM show NUM bytes last written
-F, --format FORMAT set output format to FORMAT
-n, --numeric output percentages, not visualinformation
-q, --quiet do not output any transferinformation at all
-W, --wait display nothing until first bytetransferred
-s, --size SIZE set estimated data size to SIZE bytes
-l, --line-mode count lines instead of bytes
-0, --null lines are null-terminated
-i, --interval SEC update every SEC seconds
-w, --width WIDTH assume terminal is WIDTH characters wide
-H, --height HEIGHT assume terminal is HEIGHT rows high
-N, --name NAME prefix visual information with NAME
-f, --force output even if standard error isnot a terminal
-c, --cursor use cursor positioning escapesequences
-L, --rate-limit RATE limit transfer to RATE bytes per second
-B, --buffer-size BYTES use a buffer size of BYTES
-C, --no-splice never use splice(), always useread/write
-E, --skip-errors skip read errors in input
-S, --stop-at-size stop after --size bytes have beentransferred
-R, --remote PID update settings of process PID
-P, --pidfile FILE save process ID in FILE
-d, --watchfd PID[:FD] watch file FD opened by process PID
-h, --help show this help and exit
-V, --version show version information and exit
1.2. 协助备份数据库
[[email protected]_tools]# mysqldump -uroot -p123456 --single-transaction --databases accounts |pv -q -L 10m |gzip>accounts.gzip
Warning:Using a password on the command line interface can be insecure.
[[email protected]_tools]# gunzip -fc accounts.gzip |mysql -uroot -p accounts
Enterpassword:
-- pv在这里做限流左右