• rsync常用命令


    从远程服务器复制文件到本地

    语法

    rsync [options] user@remote_host:/path/to/remote/source /path/to/local/destination
    

    示例

    rsync -avz -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
    

    从本地复制文件到远程服务器

    语法

    rsync [options] /path/to/local/source user@remote_host:/path/to/remote/destination
    

    示例

    rsync -avz -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
    

    选项说明

    • -a:归档模式,表示递归传输并保持文件属性。
    • -v:详细输出,显示传输过程中的信息。
    • -z:压缩文件数据在传输过程中减少带宽使用。
    • -e ssh:指定使用 SSH 作为远程 shell。

    处理权限问题

    有时会遇到权限问题,可以使用 sudo 提升权限:

    从远程服务器复制文件到本地:
    sudo rsync -avz -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
    
    从本地复制文件到远程服务器:
    sudo rsync -avz -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
    

    排除文件或目录

    如果要排除某些文件或目录,可以使用 --exclude 选项:

    从远程服务器复制文件到本地,排除特定目录:
    rsync -avz --exclude 'excluded_dir' -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
    
    从本地复制文件到远程服务器,排除特定文件:
    rsync -avz --exclude 'excluded_file' -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
    

    显示传输进度

    为了更好地了解传输进度,可以添加 --progress 选项:

    从远程服务器复制文件到本地,显示进度:
    rsync -avz --progress -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
    
    从本地复制文件到远程服务器,显示进度:
    rsync -avz --progress -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
    
  • 相关阅读:
    云技术分享 | 快速构建 CodeWhisperer 代码生成服务,让 AI 辅助编程
    华为数通方向HCIP-DataCom H12-821题库(单选题:321-340)
    内存笔记之DIMM与DDR
    由113号元素鉨114号元素夫115号元素镆元素汞银金等元素构成的超导体
    vue3动态路由警告问题
    常见的行为型设计模式
    Hoops API参考: 3D Graphics System的Set_Color()函数
    操作系统八股
    AWS 疑难问题——ECS传递环境变量给C#应用程序
    BUUCTF-babyheap_0ctf_2017
  • 原文地址:https://blog.csdn.net/m0_48096446/article/details/139661071