Created
July 30, 2025 14:33
-
-
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.
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 | |
# 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