Skip to content

Instantly share code, notes, and snippets.

@aerth
Created May 14, 2020 21:23
Show Gist options
  • Save aerth/5de9bf5993e4c0651752e2b3bd4d210b to your computer and use it in GitHub Desktop.
Save aerth/5de9bf5993e4c0651752e2b3bd4d210b to your computer and use it in GitHub Desktop.
Asymmetric Backups over SSH using 'age' encryption (https://github.com/FiloSottile/age)

You should edit all variables and filenames :)

==> backup_homes.bash <==

set -e
RECIPIENT_KEY=github://aerth
FILENAME="/tmp/backup_$(date +%s).dat"
DIR_TO_BACKUP=/home/

# pipe tar into age and then echo the filename when finished
tar czpf - $DIR_TO_BACKUP | age -r $RECIPIENT_KEY -o $FILENAME &&
	echo $FILENAME

==> get_backup_loldev.bash <==

#!/bin/bash

set -e

USER_AT_HOST=root@loldev
BACKUPS_DIR=$HOME/backups/$USER_AT_HOST
mkdir -p $BACKUPS_DIR

# do encrypted backup
FILENAME=$(ssh $USER_AT_HOST backup_homes.bash)

# transfer to this machine
scp $USER_AT_HOST:$FILENAME $BACKUPS_DIR/

# echo filename
echo Saved: "$FILENAME"
@aerth
Copy link
Author

aerth commented May 14, 2020

note: does not delete /tmp/backup*.dat when finished

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment