scp
从本地复制到远程
在本地服务器上将/data/mysqlbackup目录下所有的文件传输到服务器10.0.0.2的/data/mysqlbackup目录下,命令为:
scp -r /data/mysqlbackup root@10.0.0.2:/data/mysqlbackup
从远程复制到本地
在本地服务器上操作,将服务器10.0.0.2上/data/mysqlbackup/目录下所有的文件全部复制到本地的/root目录下,命令为: scp -r root@10.0.0.2:/data/mysqlbackup /root
rsync
time=$(date '+%Y-%m-%d-%H-test1_binlog.0001')
time1=$(date '+%Y-%m-%d-%H-test2_binlog.0001')
#cp /data/mysqlbackup/log/test1_binlog.0001 /data/mysqlbackup/log/$time
#cp /data/mysqlbackup/log/test2_binlog.0001 /data/mysqlbackup/log/$time1
/usr/bin/rsync -av --bwlimit=10000 /data/mysqlbackup/log/test1_binlog.0001 /data/mysqlbackup/log/$time
/usr/bin/rsync -av --bwlimit=10000 /data/mysqlbackup/log/test2_binlog.0001 /data/mysqlbackup/log/$time1
cat /dev/null > /data/mysqlbackup/log/test1_binlog.0001
cat /dev/null > /data/mysqlbackup/log/test2_binlog.0001
find /data/mysqlbackup/log/ -ctime +5 -exec rm -f {} \;
##剪切参考,IO速度限制的cp和mv(限速1024 KB/s)
##cp: rsync --bwlimit=1024 {src} {dest}
##mv: rsync --bwlimit=1024 --remove-source-files {src} {dest}
##使用ssh方式rsync,不用服务端,简单方便,SSH需要认证,就不用每次输入密码
#ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q -b 2048 -C "root@test"
#cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
#chmod 600 ~/.ssh/authorized_keys
rsync -av --exclude=.gitlab-ci.yml --exclude=log --exclude=logs --delete /root/test 192.168.1.119:/root/test1
>> Home