#!/usr/bin/env bash # Backup script for sensitive dotfiles # This handles files that shouldn't be stored directly in git set -euo pipefail DOTFILES_DIR="$HOME/dotfiles" BACKUP_DIR="$DOTFILES_DIR/backups" TIMESTAMP=$(date +%Y%m%d_%H%M%S) # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}Starting sensitive files backup...${NC}" # Create backup directory mkdir -p "$BACKUP_DIR" # Function to backup a file/directory with encryption backup_encrypted() { local source="$1" local name="$2" if [ -e "$source" ]; then echo -e "${YELLOW}Backing up $name...${NC}" tar -czf - "$source" | gpg --symmetric --cipher-algo AES256 -o "$BACKUP_DIR/${name}_${TIMESTAMP}.tar.gz.gpg" echo -e "${GREEN}✓ $name backed up and encrypted${NC}" else echo -e "${RED}✗ $source not found${NC}" fi } # Backup SSH keys and config (encrypted) backup_encrypted "$HOME/.ssh" "ssh" # Backup shell history cp "$HOME/.zsh_history" "$BACKUP_DIR/zsh_history_${TIMESTAMP}" echo -e "${GREEN}✓ Shell history backed up${NC}" # Create a sanitized SSH config for git if [ -f "$HOME/.ssh/config" ]; then echo -e "${YELLOW}Creating sanitized SSH config...${NC}" # Remove sensitive host details but keep structure sed -E 's/(HostName|User|IdentityFile) .*/\1 /' "$HOME/.ssh/config" > "$DOTFILES_DIR/ssh/config.example" echo -e "${GREEN}✓ SSH config template created${NC}" fi # List what needs manual backup echo -e "\n${YELLOW}Remember to manually backup:${NC}" echo "- Any private keys stored outside ~/.ssh" echo "- Any credentials in ~/.aws, ~/.gcloud, etc." echo "- Application-specific secrets" echo -e "\n${GREEN}Backup complete!${NC}" echo -e "Encrypted backups stored in: $BACKUP_DIR" echo -e "To decrypt: gpg -d file.tar.gz.gpg | tar -xzf -"