98.Innobackupx通过nc远程备份

247 阅读2分钟

许多公司对线上生产服务器进行了传送限制。SCP这个命令有时候就会传输到一半被停掉。
可以使用nc这个命令传送文件。

1.传送单个文件

A:接收文件的服务器
B:发送文件的服务器
首先在A服务器开启一个监听端口用于接收文件。接收文件名随便起。
nc -l 端口 > 1.txtB上服务器将发送文件给A。
nc A的ip地址 < 1.txtA上观察。文件已经传送完成
ls -lh
-rw-r--r-- 1 root root 762K Jan 28 12:56 1.txt

2.传送目录(通过压缩和解压缩传送文件)

cd learnShell/
-rw-r--r-- 1 root root 22 Jan 11 19:45 0.helloworld.sh

首先在A服务器开启一个监听端口用于接收目录 xf后必须是 -
nc -l 端口 | tar xf -B上执行命令发送目录给Atar cf - learnShell | nc Aip地址 A的端口地址
tar cf - learnShell |nc 10.1.1.1 9999

观察文件已经传送完成。
ls -lh
-rw-r--r--  1 root root 762K Nov 18 17:14 1.txt
drwxr-xr-x  2 root root 4.0K Jan 28 13:01 learnShell

3.Innobackupx远程备份

备份服务器:10.1.1.1
接受备份的远程服务器:10.1.1.2

首先在10.1.1.2上开启端口用于接收备份文件
nc -l 9998 --recv-only | xbstream -x -C /tmp/目录名

开始在10.1.1.1上开始备份(采用stream流备份+压缩备份(使用qpress工具来实现压缩和解压缩))
innobackupx --defaults-file=/etc/my.cnf --parallel=4 --compress-threads=4 --compress --stream=xbstream --user=backup --password=123456 --host=localhost --slave-info /tmp | nc 10.1.1.2 9998