Jump to content

Encrypted backup of sensitive data to a cloud

From Torben's Wickie

If you do not want your cloud provider to be able to read your files, encrypt them.

I use

  • xz for best compression
  • age for encryption
  • rclone for transfer to cloud

This guide is for MacOS. For Linux or Windows adjust the install tool steps.

Install tools

I use Homebrew to install the packages

brew install age rclone xz

Setup xz data compression

compression parameter

-6  : default compression
-9  : maximum compression
-9e : extreme compression

Setup age encryption

see Age Encryption

# generate key
age-keygen -pq -o ~/age-260801.key
age-keygen -y ~/age-260801.key > ~/age-260801.pub

Make sure you have a non-cloud backup of age-260801.key!!!

Setup rclone data transfer

see Backup#rclone

rclone supports

Setup connection

rclone config
# follow wizard, see links above for guidance

Test connection

rclone lsd pcloud:
touch /tmp/test.txt
rclone copy /tmp/test.txt pcloud:/backup/myDevice/
rclone lsd pcloud:/backup/myDevice/

Full Script

TIMESTAMP=$(date +%y%m%d-%H%M)
OUT="/tmp/GitHub-${TIMESTAMP}.tar.xz.age-260820"
rm -f "$OUT"

echo "## gen filtered list of files"
FILELIST=$(mktemp)
trap 'rm -f "$FILELIST"' EXIT 
find . \
  \( -path "*/.git" \
  -o -path "*/node_modules" \
  \) -prune -o \
  -type f \
  ! -name ".DS_Store" \
  ! -name "*.pyc" \
  ! -name "pnpm-lock.yaml" \
  -print >"$FILELIST"

echo "## create encrypted archive" 
tar -cf - -T "$FILELIST" | xz -9 | age -R ~/age-260801.pub -o "$OUT"

echo "## upload to cloud" 
rclone copy "$OUT" pcloud:/backup/myDevice/ --progress 
rm -f "$OUT"