Created
March 2, 2023 18:26
-
-
Save fernandoacorreia/91c776f554225e9c14dd34eecd6d903e to your computer and use it in GitHub Desktop.
Backup Mac to Google Drive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Backs up local folders to Google Drive. | |
# | |
# Run from a cron job script: ~/bin/backup-job | |
# | |
set -o nounset -o errexit -o pipefail | |
BACKUP_DIR="/Users/fernando.correia/Google Drive/My Drive/Backup" | |
function print_divider { | |
echo "" | |
echo "------------------------------------------------------------" | |
} | |
function backup_dir { | |
DIR="$1" | |
SOURCE="$HOME/$DIR/" | |
TARGET="$BACKUP_DIR/$DIR" | |
print_divider | |
echo "Backing up $SOURCE to $TARGET" | |
rsync -rL --inplace -v "$SOURCE" "$TARGET" || echo "Ignoring errors and continuing with next operation" | |
} | |
function backup_home_file { | |
FILE=$1 | |
SOURCE="$HOME/$FILE" | |
HOME_BACKUP_DIR="$BACKUP_DIR/home" | |
TARGET="$HOME_BACKUP_DIR/$FILE" | |
echo "Backing up $SOURCE to $TARGET" | |
mkdir -p "$HOME_BACKUP_DIR" | |
cp "$SOURCE" "$TARGET" || echo "Ignoring errors and continuing with next operation" | |
} | |
echo "Starting backup at $(date)" | |
backup_dir .config | |
backup_dir .dino | |
backup_dir .ssh | |
backup_dir Documents | |
backup_dir bin | |
backup_dir secrets | |
print_divider | |
backup_home_file .editorconfig | |
backup_home_file .gitconfig | |
backup_home_file .local_profile | |
backup_home_file .tmux.conf | |
backup_home_file .zsh_history | |
print_divider | |
echo "Finished at $(date)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Cron job to back up local folders to Google Drive. | |
# | |
# Schedule via crontab: | |
# 0 * * * * /Users/fernando.correia/bin/backup-job | |
# | |
set -o nounset -o errexit -o pipefail | |
LOG_DIR="$HOME/Documents/logs/backup-job" | |
mkdir -p "$LOG_DIR" | |
MAC_OS_DATE_FORMAT=$(date +%Y-%m-%d-%H-%M-%S) | |
LOG_FILE="$LOG_DIR/$MAC_OS_DATE_FORMAT.log" | |
$HOME/bin/backup >"$LOG_FILE" 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment