$man scp

SCP(1)                  FreeBSD General Commands Manual                 SCP(1)

NAME
    scp -- secure copy (remote file copy program)

SYNOPSIS
    scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
        [-l limit] [-o ssh_option] [-P port] [-S program]
        [[user@]host1:]file1 [...] [[user@]host2:]file2

DESCRIPTION
    scp copies files between hosts on a network.  It uses ssh(1) for data
    transfer, and uses the same authentication and provides the same security
    as ssh(1).  Unlike rcp(1), scp will ask for passwords or passphrases if
    they are needed for authentication.

    Any file name may contain a host and user specification to indicate that
    the file is to be copied to/from that host.  Copies between two remote
    hosts are permitted.

usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
          [-l limit] [-o ssh_option] [-P port] [-S program]
          [[user@]host1:]file1 [...] [[user@]host2:]file2

SCP를 이용하여 데이터를 백업하기 위해서는 서비스 서버와 백업 서버의 트러스트(trusted) 관계를 만들고 sshd에서 서비스 할 수 있도록 수정해 주어야 한다.

localhost#vi /etc/ssh/sshd_config

AuthorizedKeysFile      .ssh/authorized_keys (주석 제거)

머신 1
O/S : FreeBSD
용도 : Service Server
IP : 192.168.0.1

머신 2
O/S : FreeBSD
용도 : Backup Server
IP : 194.168.0.2

1) 먼저 머신 2에서 root권한으로 트러스트 관계를 설정할 dsa키를 만들어야 한다.

localhost# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): [Enter]
Enter passphrase (empty for no passphrase): [Enter]
Enter same passphrase again: [Enter]
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
f1:a7:45:4f:e8:e7:2b:d8:f2:ae:d5:a1:76:22:59:9c
root@localhost

2) 이제 만들어진 파일을 머신 1로 전송

localhost# scp .ssh/id_dsa.pub
root@192.168.0.1:
Password:
id_dsa.pub                          100% 1116     1.1KB/s   00:00

3) 머신 1로 접속하여 확인
localhost# ls
test.txt  id_dsa.pub
localhost# cat id_dsa.pub > .ssh/authorized_keys
localhost# rm id_dsa.pub
localhost# chmod 700 .ssh
localhost# chmod 644 .ssh/authorized_keys

4) 이제 테스트하기 위해 test.html을 백업해 보자.
localhost# cd /www/data
localhost# ls
localhost# test.html <---(이 파일을 백업할 것임)

5) 머신 2 에서 아래 명령을 실행
localhost# scp root@192.168.0.1:/www/data/index.html /backup/index.html
index.html                                     100% 1333     1.3KB/s   00:00
localhost# ls /backup/index.html
index.html

※ cron을 활용하여 주기적인 데이터 백업을 할 수 있다.
머신 1에서는 주기적으로 데이터를 tar압축
머신 2에서는 주기적으로 데이터를 scp백업
-끝-

출처 - 네이버 지식인

by 뭔일이여 2007. 1. 8. 16:21