Skip to content

Instantly share code, notes, and snippets.

@kenilt
Created July 30, 2025 14:33
Show Gist options
  • Save kenilt/fa39c3bf5cae11d1fa66c50a7800a507 to your computer and use it in GitHub Desktop.
Save kenilt/fa39c3bf5cae11d1fa66c50a7800a507 to your computer and use it in GitHub Desktop.
Backup key dotfiles (.zshrc, .gitconfig, .vimrc, etc.), the ~/.config/ directory, and my ~/.zsh and ~/.ssh folders.
#!/bin/bash
# Set backup directory
BACKUP_DIR="$(pwd)/Backup"
SSH_BACKUP_DIR="$BACKUP_DIR/ssh"
CONFIG_BACKUP_DIR="$BACKUP_DIR/config"
ZSH_BACKUP_DIR="$BACKUP_DIR/zsh"
echo "πŸ”„ Starting backup..."
# Create backup directories
mkdir -p "$SSH_BACKUP_DIR"
mkdir -p "$CONFIG_BACKUP_DIR"
# List of individual dotfiles to backup
DOTFILES=(.zshrc .bashrc .bash_profile .vimrc .gitconfig .gitignore .gitignore_global)
# Backup each dotfile if it exists
for file in "${DOTFILES[@]}"; do
if [ -f ~/$file ]; then
cp ~/$file "$BACKUP_DIR"
echo "βœ… Backed up $file"
fi
done
# Backup ~/.config directory (if it exists)
if [ -d ~/.config ]; then
cp -r ~/.config/* "$CONFIG_BACKUP_DIR/"
echo "βœ… Backed up ~/.config/"
fi
# Backup ~/.zsh directory (if it exists)
if [ -d ~/.zsh ]; then
cp -r ~/.zsh/* "$ZSH_BACKUP_DIR/"
echo "βœ… Backed up ~/.zsh/"
fi
# Backup SSH config (skip if not found)
if [ -d ~/.ssh ]; then
cp -r ~/.ssh/* "$SSH_BACKUP_DIR/"
echo "βœ… Backed up ~/.ssh/"
else
echo "⚠️ No ~/.ssh directory found, skipping SSH backup."
fi
echo "βœ… All files backed up to $BACKUP_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment