Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Last active June 3, 2019 02:08
Show Gist options
  • Save jpcaparas/54fdd842f1b7d7e6d9c5e01580d3aebe to your computer and use it in GitHub Desktop.
Save jpcaparas/54fdd842f1b7d7e6d9c5e01580d3aebe to your computer and use it in GitHub Desktop.
Tarball to standard output and then to rclone (rclone-to-gdrive.sh)
#!/bin/bash
# file: rclone-to-gdrive.sh
# usage: $(rclone-to-gdrive.sh /var/www /etc/nginx /var/some\ dir\ with\ spaces)
set -e
# Check if user running the script is root
# https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root
if [[ $EUID -ne 0 ]]; then
printf "The script must be run by the 'root' user!\n"
exit 1
fi
paths=("$@")
paths_friendly=""
printf "Checking for path existence:\n"
for path in "${paths[@]}"; do
[[ ! -e $path ]] && printf "Path '${path} does not exist. Exiting!\n" && exit 1
paths_friendly+="\"${path}\", "
printf "\t'${path}' exists.\n"
done
[[ -z $paths ]] && printf "Specify directories to back up!\n" && exit 1
year=$(date +%Y)
month=$(date +%m)
month_friendly=$(date +%b)
day=$(date +%d)
hours_minutes_seconds=$(date +%H.%M.%S)
save_path="/${year}/${month_friendly}/backup-${year}-${month}-${day}-${hours_minutes_seconds}.tar.gz"
tar -zcpvf - "${paths[@]}"| rclone rcat gdrive:$save_path
printf "Backup succeeded (Output dir: $save_path) for $paths_friendly\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment