본문 바로가기
Tool/NAS

NAS / freenas / cron job 으로 백업(sftp 서버로접속)

by 하하IT 2020. 4. 24.

1. freenas에 backup 유저생성

    -root계정으로  /root/.ssh 경로에  인증키 저장이 안되므로

    MENU > Account > Users > Add User

  

 Home Directory 지정할것(해당 경로의 권한확인)

 groups 지정(백업파일저장할 경로의 권한확인)

 

2. 인증키 생성

[backup@freenas ~]$ whoami

backup

[backup@freenas ~]$

[backup@freenas ~]$ ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/mnt/disk2/.ssh/id_dsa):  인증키가 저장되는경로

Created directory '/mnt/disk2/.ssh'.

Enter passphrase (empty for no passphrase): 그냥엔터

Enter same passphrase again: 그냥엔터

Your identification has been saved in /mnt/disk2/.ssh/id_dsa.

Your public key has been saved in /mnt/disk2/.ssh/id_dsa.pub.

The key fingerprint is:

2d:f2:8f:1c:d8:5d:3f:59:21:6f:47:1b:7a:5e:7b:86 backup@freenas.local

The key's randomart image is:

+--[ DSA 1024]----+

|                 |

|                 |

|             . o.|

|         .    +.+|

|      . S . .. =+|

|       = o . .+++|

|      . + .   Eoo|

|       . +     o.|

|        o .      |

+-----------------+

[backup@freenas ~]$

[backup@freenas ~]$ ssh root@sftp서버주소  mkdir .ssh/

The authenticity of host 'aaa.co.kr (111.222.333.444)' can't be established.

RSA key fingerprint is 0a:b1:26:54:0d:29:11:54:7e:99:41:3b:42:ac:d0:b8.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'oracle.ejudata.co.kr' (RSA) to the list of known hosts.

Password: sftp서버주소의 password

mkdir: cannot create directory `.ssh/': File exists

[backup@freenas ~]$

[backup@freenas ~]$

[backup@freenas ~]$ scp ~/.ssh/id_dsa.pub root@sftp서버주소:.ssh/authorized_keys

Password:

id_dsa.pub                                                                                                                                100%  610     0.6KB/s   00:00

[backup@freenas ~]$

[backup@freenas ~]$

[backup@freenas ~]$ sftp root@sftp서버주소

[backup@freenas ~]$

[backup@freenas ~]$

 

 

3. backup script 파일 생성

[backup@freenas ~]$ cat ftpbackup_serverNAME.sh

## vi  ftpbackup_serverNAME.sh

##  chmod +x  ftpbackup_serverNAME.sh

## script delete

rm -fr idcbackupscript

 

## script file make

touch idcbackupscript

echo lcd /mnt/disk2/oracle/oracle>> idcbackupscript

echo cd /data/oracle/backup/dump/system>> idcbackupscript

#echo get `date +'%Y%m%d'`*.tgz>> idcbackupscript

echo get `date +'%Y%m%d'`*.txt>> idcbackupscript

echo bye>> idcbackupscript

#!/bin/sh

sftp -b idcbackupscript  root@serverNAME

exit

[backup@freenas ~]$

[backup@freenas ~]$

[backup@freenas ~]$

 

 

4. cron job에 등록

 MENU > System > Cron Jobs > Add Cron Jobs

 

user      : backup

command   : /mnt/disk2/ftpbackup_serverNAME.sh

ShortDesc : oracle

Minute    : 01

Howr      : 07  (해당백업파일이 만들어지는시간을 감안하여 선택)

Dayofmonth: every day

'Tool > NAS' 카테고리의 다른 글

Installing the FreeNAS Image Directly to a USB Drive  (0) 2020.04.26
NAS / Freenas8 / CIFS / samba  (0) 2020.04.26
NFS mount , umount  (0) 2020.04.26
NAS / cron job / backup / ftp  (0) 2020.04.26