1. enable ssh-key
hostname -I | awk '{print $1}'
ssh-keygen -t rsa
ssh-copy-id -p 22 root@10.10.10.9
2. manual command
scp /data/sample/* root@10.10.10.9:/dummy/
scp -P22 /data/sample/* root@10.10.10.9:/dummy/
3. manual folder
scp -r /data/sample/ root@10.10.10.9:/dummy/
scp -P22 -r /data/sample/* root@10.10.10.9:/dummy/
4. scp folder yyyymmdd to yyyymmdd
[root@teguhth-all sample]# pwd
/data/sample
[root@teguhth-all sample]# cat scptransfer.sh
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <IP_ADDRESS>"
echo "Example: $0 10.10.10.9"
exit 1
fi
datex=$(date +%Y%m%d)
destsvr=$1
scp -r /media/backup/$datex root@$destsvr:/dummy/
[root@teguhth-all sample]#
5. scp folder yyyy/mm/dd to yyyy/mm/dd
[root@teguhth-all sample]# pwd
/data/sample
[root@teguhth-all sample]# cat transfscp_daily.sh
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <IP_ADDRESS>"
echo "Example: $0 10.10.10.9"
exit 1
fi
datey=$(date +%Y/%m)
datec=$(date +%d)
destsvr=$1
ssh root@$destsvr "mkdir -p /dummy/${datey}/${datec}"
scp -r /media/backup/${datey}/${datec} root@$destsvr:/dummy/${datey}
[root@teguhth-all sample]#

.jpeg)





No comments:
Post a Comment