HOW-TO: Script: List My OPKGs (to a file for backup)

Keywords: backup, opkg, plugins, list, howto, script, shell, luci, restore, ipk, tarball, conf


Description

List user's (your) installed packages, writing them to a text file that can be used to reinstall the binaries of what a user manually installed. The resulting .list file will be use to opkg install to pull from the feeds. That is done with two commands in one execution.

The GL GUI doesn’t feature a backup function. Creating & restoring a backup achieve (.tar.gz, aka tarball) of all your configuration files (.conf) is described in the below section marked Note(s).

Result

root@GL-AXT1800:~# cat /root/backup/package-lists/2023-07-01-072023_-_GL-AXT1800_-_my-installed-packages.list
bash
drill
htop
libldns

Dependencies

  • root access via SSH to the GL device IP (default 192.168.8.1)
  • sed (should be already present)

Optional but Recommended

  • LuCI (Install via GL GUI → System → Advanced Settings)
  • openssh-sftp-server (to quickly upload/download files via your favorite SFTP client (eg: FileZilla))

Installation

  • Copy the below script to a text file, editing the variables to your preferences but make sure to save extension as .sh & not .txt.
    • Windows 10 Notepad should be fine but make sure UTF-8 is show in the lower right corner. Save it as something similar to list_my_installed_packages.sh .
    • You don't have to change anything in it to use it; the defaults will work just fine.
  • SSH/SFTP into your GL device, copy or upload the script to an easy to remember location/dir. /root/bin/ is advised (mkdir /root/bin).
  • Make it executable: chmod +x /root/bin/list_my_installed_packages.sh

Usage

  • Run it: /root/bin/./list_my_installed_packages.sh
  • See what was recorded: ls -l /root/backup/package-lists/
    • then cat /root/backup/package-lists/[fileName] one of those listed files.
  • Download your list via SFTP or other method (eg: copying the cat output to a UTF-8 text file on your PC).

Script

#!/bin/ash

# (OpenWrt 21.02) List My OPKGs: list user (your) installed packages, writing
# them to a text file that  can be used to restore the binaries of what a user
# manually installed
# **Keywords:** *backup, opkg, plugins, list, howto, script, shell, luci, restore, ipk, tarball, conf*

# 2023-07-01-1205
# thread: https://forum.gl-inet.com/t/how-to-script-list-my-opkgs-to-a-file-for-backup/30963
# sources: https://forum.openwrt.org/t/solved-opkg-how-to-list-only-packages-that-i-have-installed/11983/5

# edit these variable to your preferences
# ensure double quote mark encapsulation
dateFormat="natural" # natural or iso-8601 formatted
saveDir="/root/backup/package-lists" # note: *no* ending slash
outputName="my-installed-packages.list" # a '.list' is just a text file

### [ do not edit below this line ] #####

# get the device's name fr the system hostname
deviceName=$(cat /etc/config/system | grep "hostname" | awk '{print $3}' | xargs)

# get the device's mac in case multiple of same device but same hostname
mac=$(cat /sys/class/net/eth0/address | tr '[:lower:]' '[:upper:]' | tr -d ':')

# set the date for the list according to the chosen preference
if [ "$dateFormat" = "iso-8601" ]; then
    timeStamp=$(date +"%Y%m%dT%H%M%S%z")
else
    timeStamp=$(date +"%Y-%m-%d-%H%M%S")
fi

# check for the existance of a save location/dir, creating it if needed
if [ ! -d "$saveDir" ]; then
    mkdir -p "$saveDir"
fi

# do it
ls /overlay/upper/usr/lib/opkg/info/*.list | sed -e 's/.*\///' | sed -e 's/\.list//' > "$saveDir"/"$timeStamp"_-_"$deviceName"_-_"$mac"_-_"$outputName"

# done
exit 0


Reinstalling

  • Login via SSH/SFTP
  • Upload your list
  • Update opkg & run opkg through the list.

Example

I'm restoring a list made 2023-07-01-085109. It is located on the GL device at /root/backup/package-lists/ as 2023-07-01-085109_-_GL-AXT1800_-_my-installed-packages.list. Edit to taste:

opkg update && for i in $(cat /root/backup/package-lists/2023-07-01-085109_-_GL-AXT1800_-_my-installed-packages.list); do opkg install $i; done

Note(s)

This does not restore any changes you've made to configuration files. It only installs the programs you've installed since the last time you upgraded or reset the device's firmware.

The GL GUI doesn't feature a backup function. Use LuCI -> System -> Backup / Flash firmware -> Restore -> Restore backup -> Upload achieve ... to restore the conf from a previous tarball (.tar.gz) after you've re-installed those binaries/programs from your .list.

You can make that tarball containing your conf(s) via LuCI -> System -> Backup / Flash firmware -> Flash operations -> Actions -> Backup -> Generate achieve.

To preview exactly what’s going into that tarball see LuCI -> System -> Backup / Flash firmware -> Flash operations → Configuration → Configuration → Show current backup file list → Open list…

Tips

  • LuCI's & SSH's default password is the same as GL GUI. root is the default login name.
  • Add the script location/dirs to your future backups: LuCI -> System -> Backup / Flash firmware -> Flash operations -> Configuration -> Configuration -> add /root/ -> Save
    • If you have custom firewall rules be sure to add /etc/firewall.user too.
    • If you have custom Encrypted DNS server settings of DNS over TLS, DNS over HTTPS or DNSCrypt add /etc/dnscrypt-proxy2/
  • Use GL GUI for firmware updates (GL GUI -> System -> Upgrade) but make backups via LuCI
  • The nano editor is very easy to edit text/conf files while logged into your GL device (opkg install nano)

Caveats

  • Assumes firmware 4.2.1-release4
  • This was scripted using the bash shell but OpenWrt defaults to ash. Please report any issues including error output.
  • No warranties are either expressed or implied; I’m not responsible if your devices become sentient & fight back from the abuse.
10 Likes
Need both Internet Kill Switch and WAN access
Suggestion: Technical Support for Routers: New Category: HOW-TOs
[Firmware 4.3.6-r3] Beryl update wipes VPN config & locks 'Block Non-VPN Traffic' on
Access from remote with VPN enabled
OpenMPTCProuter build for GL-X3000
How to Disable DHCP only for LAN (Ethernet) devices, not for Wifi Devices?
Newby help: add Brume 2 VPN to existing Home network
IPV6 support on wireguard server?
LAN / WIFI AP with ips other than RFC1918
Is it possible to block-non vpn traffic on specific device (MAC address)
Does device performance matter over long distance VPN?
[Feature Request] RTTY/SSH access within GL GUI
Does GL-A1300 (Slate Plus) run as an exit node for Tailscale
No TCP for connected VPN clients (just ICMP)
Wireguard AND tor simultaneously
Still on 4.5.6, what should I update to (Flint 2 with lots of settings)
Automatic update for custom firmware
VLAN/multiple SSIDs not working on FLINT!
Subnet not connected to tailscale exit node when using Modem
mDNS not resolving router's hostname
Dual VPN client on one router
Auto connect to public wifi database
GL-AX1800 flint notification?
Question about log entry that appears every 1 second on GL-X3000
Vlan help
Tailscale AX1800. Taildrop feature
Best way to configure a GL.iNet device for full home network VPN access
Split Tunnel via VPN Policy or via Wireguard allowedIPs config?
Backing up entire router
New Flint AX1800
Advice for my Current Setup and Fallback Routers
Flint 2 - Upgrade
Problem using printer on port 9100 (GL-AR300M16)
A1300(Slate plus) Tailscale subnet is not adviertized with USB modem
WPS (Flint 2)
Fixed lost wifi pane in flint ax1800 v4 upgrade
Beryl MT1300 beta 2 feedback
Is This Configuration Possible?
No Device Detected for USB connection to AXT1800
How can I gain some space and delete luci etc.?
Flint2 & mt300n v2 - Extender Mode
[Firmware 4.3.6] Genius automatic upgrade broke DDNS settings, Static leases, Port forwards, Domain name, and what else?
QOS settings for GL.iNet GL-MT3000
GL-AR750S EXT firmware 4.3.6 TTL mangle rule?
Backing up Creta (GL-AR750) Before Flashing Firmware Update (4.3.6)
Anyone tried Wireguard with IPv6 on GL-AX1800 Flint?
VXLAN Support on GL-X3000 or any GLiNet device
Firmware Upgrade Results in Missing Custom Firewall Script
GL-AR750S-EXT running 3.216 - worth upgrading?
/etc/config/wireless getting overwritten on reboot
Flint - v4.4.6 - now it dies every night - not fking happy
Connecting to VPN with built in windows VPN
Need some space unsure whats ok to delete
AX1800 Slate AX - Which Firmware Version to Use
SNMP on Flint 2
Isolate one WireGuard profile from LAN
Tailscale settings lost on reboot
Override dns settings for all clients - where is it applied?
What is the proper way to change the hostname of my Mango v2 device?
Slate AX & Beryl Multiple SSID with unique DHCP/SubNet
Slowdown sft1200 slowing to half speed
GL-AXT1800 Slate config question
Copy GL-AX1800 over to GL-MT6000
Luci is not working on opal
OpenVPN not working (FW: 4.4.6)
GL-MT6000 Use USB for log
AR300M16 connection issues under version 4.3.7
GL mt6000: mDNS and IOT isolated wifi
Flint 2 - Where do we file bug reports?
Accepted Preview Plan
Slate Plus (GL-A1300) WG VPN connection freezes every 10 minutes
Python 3 OpenSSL
HOW-TO: Mango (GL-MT300N-V2): Setting up a Huawei e3372h-607 USB LTE/4G Modem
No squeezelite package for GL-AXT1800
VPN from Iran - blocked access
Feature Request : BanIP
Disable IPV6 on Flint2
Does any one successfully setup syncthing on AXT-1800?
SFT1200 Opal WPS is enabled by default
Flint 2 WAN access not working
Brume 2 reboots from memory issue? bug? exploit?
Flip WAN/LAN of Brume 2
How to separate Home Automation lan on Flint 2 router
VPN from Iran - blocked access
Migration from OpenWrt 21.02.3 (netgear wndr3700) to GL-MT6000(Flint2)
Opkg update command failed with code 3
Flint2 (GL-MT6000) : best firmware update, and best way to do
Need some advice regarding restoring a backup on a different device
Flint 3 (GL-BE9300) Discussion Thread
Full Firmware image backup
Move root filesystem to SD card
WireGuard client and server
GL-iNet AX1800 debricking by USB and TFTPD
Flip WAN/LAN of Brume 2
GL-MT6000 - Can't access DDNS forwarded port with wireguard
Wireguard listening to wrong IP in Multi-WAN setup
Local route table uses VPN dispite policy for only specific devices to use VPN
Run udp discovery protocol to make unifi protect work via vpn
Does any one successfully setup syncthing on AXT-1800?
Need help connecting to devices on wan from lan (MT2500)
New GL.iNet Customer
Firmware 4.3.6 r2 GL-MT1300 captive portal gone?
[Feature Request] Side Button to Toggle WiFi On/Off on Dual Radio Devices
Oblivious DNS (ODoH) Renders DNS Inoperable
Brume 2 as a Tailscale exit node
Address by computer name instead of IP address in WireGuard VPN?
System update clears installed packages
Gl-mt6000 v4.6.3-op24
[Feature Request] Forums: Category: Off-topic
OutlineVPN (obfuscation) with GL routers?
Can i create 2 separate WIFI for 2 WANS on Flint 2?

Changelog

  • 2023-07-01-1205: Added device's MAC in case of multiple same model, same hostname
  • 2023-07-01-0720: Initial release

References & Resources

1 Like