π ImmortalWrt β Smart Automatic Backup
Overview
- Script:
/root/smart_backup.sh
- Schedule: Daily at 15:00
- Logic: On-demand backup - only when config changes
- Dual storage:
- tar.gz archives: For system restore
- configs/ folder: For viewing change history
- Retention: Local 3, Remote 30 tar.gz files
- Stability checks: Uptime (>10min), time sync, network
Backup Files
π¦ tar.gz Archive (For System Restore)
- Filename:
backup_20231213_150023.tar.gz
- Content: Complete system backup (sysupgrade format)
- Usage:
- LuCI: System β Backup/Flash Firmware β Restore backup
- CLI:
sysupgrade -r backup_20231213_150023.tar.gz
- Location: GitHub repo root
π configs/ Folder (For Viewing Changes)
- Content: Extracted
/etc/config/ files from tar.gz
- Usage:
- View changes on GitHub
- Git Diff highlights modifications
- Track configuration history
- Note: Cannot be used alone for restore
Setup
1. Install Dependencies
opkg update
opkg install git openssh-client openssh-keygen ca-bundle ca-certificates
2. Generate SSH Key
ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N ""
cat /root/.ssh/id_ed25519.pub # Add to GitHub SSH keys
ssh -T git@github.com
cat > /root/.ssh/config <<'EOF'
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_ed25519
StrictHostKeyChecking accept-new
EOF
chmod 600 /root/.ssh/config
4. Deploy Script
wget -O /root/smart_backup.sh https://raw.githubusercontent.com/YOUR_USER/REPO/master/scripts/smart_backup.sh
chmod +x /root/smart_backup.sh
# Edit: BACKUP_DIR and GIT_REMOTE
vi /root/smart_backup.sh
5. Schedule (15:00 Daily)
echo "0 15 * * * /root/smart_backup.sh >> /root/smart_backup.log 2>&1" >> /etc/crontabs/root
/etc/init.d/cron restart
Restore Backup
Via LuCI
- Download
backup_YYYYMMDD_HHMMSS.tar.gz from GitHub
- Login to router: http://192.168.1.1
- System β Backup/Flash Firmware β Restore backup
- Upload and wait for reboot
Via SSH
cd /tmp
wget https://github.com/USER/REPO/raw/master/backup_20231213_150023.tar.gz
sysupgrade -r backup_20231213_150023.tar.gz
reboot
View Changes
On GitHub
- Open backup repository
- Navigate to
configs/ folder
- Click any file (e.g.,
network)
- Click History to view changes
Via Git
cd /root/Immortalwrt-AutoBackup
git log --oneline configs/network
git show abc1234:configs/network
git diff abc1234 def5678 -- configs/network
Notes
- tar.gz restores system: configs/ is only for preview
- Backup before restore: Always backup current config first
- Check compatibility: Ensure backup version matches system
- Large files separate: Manage OpenClash configs separately