Skip to content

Instantly share code, notes, and snippets.

@seanli1
Last active January 23, 2021 22:36
Show Gist options
  • Save seanli1/d2e99da80ffb10d81a03d5ed06d14b01 to your computer and use it in GitHub Desktop.
Save seanli1/d2e99da80ffb10d81a03d5ed06d14b01 to your computer and use it in GitHub Desktop.
Back up raspberry pi home directory to Google Drive via scp to another computer
#!/bin/bash
# Send a zip backup of the /home directory via scp
# to Google Drive via Sean's computer & SSH. (Need port forwarding if accessing from external network)
# The target folder name in Google Drive. Setting to something static
# instead of something like $HOSTNAME in case that ever changes.
device_name=screenpi
# Name of the file
filename=$device_name-$(date +%F).zip
# Where backup is stored locally
local_directory=.
# Content being backed up
content=/home
# Where backup is sent to
dest_directory=[USERNAME]@[ADDRESS]:/Users/[USERNAME]/'Google\ Drive'/_Backups/$device_name
# Zip content
echo "(1/2) Enter password to encrypt backup."
zip -er9 $local_directory/$filename $content
echo
echo
# Copy new backup to remote location
echo "(2/2) Enter password to log in via SSH."
scp "$local_directory/$filename" "$dest_directory/$filename"
# Delete local backup
rm $local_directory/$filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment