Repo Document

ImmortalWrt GitHub Auto Backup (Legacy Reference)

Note: this page is kept as a legacy reference for the older SSH + configs/ snapshot workflow.

docs/en/OpenWrt_AutoBackup.mdUpdated Apr 12, 2026

ImmortalWrt GitHub Auto Backup (Legacy Reference)

Note: this page is kept as a legacy reference for the older SSH + configs/ snapshot workflow. For the current recommended backup and maintenance path, read:

  • docs/OpenWrt_Backup_Resotre.md
  • docs/System_Maintenance.md

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

  1. tar.gz archive (for system restore)
  • Filename: backup_20231213_150023.tar.gz
  • Content: Complete system backup (sysupgrade format)
  • Usage:
    • LuCI: SystemBackup/Flash FirmwareRestore backup
    • CLI: sysupgrade -r backup_20231213_150023.tar.gz
  • Location: GitHub repo root
  1. 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

Follow the setup in order.

  1. Install dependencies First identify your OpenWrt branch:
  • OpenWrt 24.10 and earlier stable releases: use opkg
  • OpenWrt 25.12 and newer: use apk

For 24.10 and earlier:

opkg update
opkg install git openssh-client openssh-keygen ca-bundle ca-certificates

For 25.12 and newer:

apk update
apk add git openssh-client openssh-keygen ca-bundle ca-certificates
  1. Generate the 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
  1. Configure SSH (port 443)
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
  1. Deploy the backup 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
  1. Schedule it (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

Choose one restore path:

  1. Via LuCI

  2. Download backup_YYYYMMDD_HHMMSS.tar.gz from GitHub

  3. Login to router: http://192.168.1.1

  4. SystemBackup/Flash FirmwareRestore backup

  5. Upload and wait for reboot

  6. 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

  1. On GitHub

  2. Open backup repository

  3. Navigate to configs/ folder

  4. Click any file (e.g., network)

  5. Click History to view changes

  6. 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