Skip to content

Instantly share code, notes, and snippets.

@lgloege
Last active October 20, 2018 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgloege/2dec36b29f69178fcee39a149f8eea27 to your computer and use it in GitHub Desktop.
Save lgloege/2dec36b29f69178fcee39a149f8eea27 to your computer and use it in GitHub Desktop.
Steps to setup remote login and rsync backup

Setting up remote login

  1. Let's first see if you have a remote key. Open a terminal and type more ~/.ssh/id_rsa.pub If a random string of letters and numbers appears, then you already have a public key and you can skip to step 3.
  2. Don't have a public key? Let's make one! Open a terminal and type ssh-keygen to generate a public key. Just keep hitting enter. It's going to ask if you want to save the key to /Users/USER/.ssh/id_rsa and to make a passphrase. You want to save it to the default location and don't worry about the passphrase, just hit enter.
  3. Copy the public key to the remove computer with the command ssh-copy-id USER@artemis.ldeo.columbia.edu What this is doing is copying your key to .ssh/authorized_keys on artemis.
  4. Now you can log into artemis without a password. Try this ssh USER@artemi.ldeo.columbia.edu

Backup script

Now that we have remote login working, we can write a simple backup script that can use with crontab. rsync-backup.sh is a simple script to backup a SOURCE directory on artemis to DESTINATION on your local computer. This is nothing fancy and could (read: should) be improved.

#!/usr/bin/env bash
# ==================================================
# backup script using rsync
# r : backups up the source directory recusrively
# t : preserves the time stamp on the files
# e : excutes the ssh. "-e ssh" probably isnt necessary
#
# Notes:
#     Want to see which files are transferred?
#     then add --progress afer "-e ssh"
#
# L. Gloege 2018
# ==================================================
set -o errexit
set -o nounset

# Define source and destination directories
SOURCE=/local/data/artemis/workspace/gloege/test_directory
DESTINATION=/Users/gloege/backups

# Transfer files using rsync
rsync -rt -e ssh gloege@artemis.ldeo.columbia.edu:${SOURCE} ${DESTINATION}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment