SCP – SecureCopy

Simple scp transfer from Server A (Source) to Server B (Destination)

1. Server A

Create a script for scp transfer called scp-filetransfer.sh on /home/admin

#########################################

#!/bin/bash

#Source
DIRA=/home/admin/Documents/
#Destination
DIRB=/home/admin/Backup

/usr/bin/scp -P 22 -r $DIRA root@i p a d d r e s s:/$DIRB

##########################################

2. Server B.

a. If you have firewall script add Server A IP address to ssh to Server B firewall script
Ex.
ServerAIP=”Server A ip address”
PrivatePort=”your private port”
IPaddr=”your public ip address – Sever B”

iptables -A INPUT -p tcp -s $ServerAIP –sport $PrivatePort -d $IPaddr –dport 22 -m state –state NEW,ESTABLISHED -j ACCEPT

b. Allow the directory to be accessible and writable.
cd /home/admin/
Ex.  chmod 750 Backup

3. Add crontab to schedule the transfer
a. crontab -e
b. append to the last line
# BACKUP DAILY 3PM
10 15 * * * /home/admin/scp-filetransfer.sh

Advertisements

Mag-iwan ng Tugon

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Baguhin )

Twitter picture

You are commenting using your Twitter account. Log Out / Baguhin )

Facebook photo

You are commenting using your Facebook account. Log Out / Baguhin )

Google+ photo

You are commenting using your Google+ account. Log Out / Baguhin )

Connecting to %s