[英]TAR over two hops
我需要創建一個tar並將其發送到我的本地文件夾。 如果我可以創建tar文件,則可以使用scp輕松將其保存在本地文件夾中。 這里的問題是第一步:在遠程服務器上創建TAR。 服務器只能通過另一個遠程服務器(堡壘服務器)訪問。
這是我當前正在使用的命令:
timestamp="20160226-085856"
ssh bastion_server -t ssh remote_server "sudo su -c \"cp -r /etc/nginx /home/ubuntu/backup/nginx_26Feb && cd /home/ubuntu/backup && tar -C /home/ubuntu/backup -cf backup_nginx-$timestamp.tar ./nginx_26Feb\" "
這是我得到的錯誤:
su: invalid option -- 'r'
Usage: su [options] [LOGIN]
這里的任何幫助將是巨大的。
不使用花哨的sudo su -c
嘗試一下。 使用sudo -s
應該足夠了:
ssh bastion_server -t ssh remote_server "sudo -s cp -r /etc/nginx \
/home/ubuntu/backup/nginx_26Feb && cd /home/ubuntu/backup && \
tar -C /home/ubuntu/backup -cf backup_nginx-$timestamp.tar ./nginx_26Feb"
或設置適當的兩跳~/.ssh/config
:
Host bastion
Hostname bastion_server
Host remote
Hostname remote_server
ProxyCommand ssh -W %h:%p bastion
然后跑
ssh remote sudo su -c "cp -r /etc/nginx /home/ubuntu/backup/nginx_26Feb \
&& cd /home/ubuntu/backup && tar -C /home/ubuntu/backup -cf \
backup_nginx-$timestamp.tar ./nginx_26Feb"
沒有花哨的逃脫和東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.