Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.04 KB

bash-backup-public-repos.md

File metadata and controls

49 lines (38 loc) · 1.04 KB

Backup Public Repositories

You never know when disaster will strike. Backup important vendor dependencies with rclone.

https://rclone.org/

#!/usr/bin/env bash
# User Script:
# bash /volume1/GithubBackups/backup-github.sh

# Exit on Errors and switch to parent directory of script.
set -e; cd "$(dirname "${BASH_SOURCE[0]}")"

# Local Destination Directory
destination=./data/github

# Setup Log File
logFile="./logs/github-$(date +"%Y-%m-%d_%H-%M-%S").log"

# Log Writer
function logger(){
  echo "$1" >> "$logFile"
}

# Begin Backup Operations
logger "Running RClone in $PWD as $(whoami)"
logger "Logfile: $logFile"
logger "Synchronizing Github Repos"

declare -a repoCollection=(
"username/repo-a" \
"username/repo-b" \
"username/repo-c"
)

# Iterate the string array using for loop
for repo in "${repoCollection[@]}"; do
  logger "Synchronizing $repo..."
  ./rclone-linux \
  copyurl \
  --verbose \
  "https://github.com/$repo/archive/master.zip" \
  "$destination/$repo-master.zip" \
  >> "$logFile" 2>&1
done

logger "Backup Completed"