Nithin Chandy
Nithin Chandy

Reputation: 707

Automate File transfer to AWS jumphost from local machine

I'm trying to automate file backup from one of my dev server to an EC2 instance. planning to setup a cron job that'll run the script daily.

This is what am trying to accomplish.

LOCAL SERVER ---> JUMPHOST ----> EC2 INSTANCE

  1. Tar ball the directories in my dev server (dev-svr20 for example).
  2. Copy the tar ball file from the dev server to the AWS jump host.
  3. Copy the tar ball file from the jump host to the AWS EC2 instance.
  4. Extract the tar ball in the AWS EC2 server.

Can i accomplish all these tasks using a single script?

I'm not sure whether i can run a single script on jumphost that will first fetch files from dev-svr20 and then move to EC2 instance.

I know we can download files from AWS jumphost to our local machine or upload to jumphost from local machine. But, can we do the other way? I mean can the jumphost fetch files from distant server (dev-svr20) ?

Upvotes: 0

Views: 1369

Answers (1)

Mike Ryan
Mike Ryan

Reputation: 1438

Certainly, this is possible. You'll need to write a script that is executed on your jump server. The user running this script must be able to SSH in to both your dev server and the EC2 instance, as you will need to execute some of these commands over SSH.

The process will be something like:

# Create the tarball on the dev server
ssh user@dev-svr20 tar cvf /tmp/my_files.tar /path/to/some/dir
# Copy the tarball to the jump server
scp user@dev-svr20:/tmp/my_files.tar /tmp/my_files.tar
# Copy the tarball to the EC2 instance
scp /tmp/my_files.tar user@ec2-instance:/tmp/my_files.tar
# Extract the tarball on the EC2 instance
ssh user@ec2-instance tar xvf /tmp/my_files.tar

A tool like Fabric can simplify some of the steps for you, or you could write the script in Bash.

Upvotes: 2

Related Questions