Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:installation:generic.backup [2019/03/05 11:25] – [Create Full MTD Backup from OpenWrt] Code optimized vgaeteradocs:guide-user:installation:generic.backup [2022/07/11 15:06] – Add instructions for how to explore MTD backups spookyuser
Line 1: Line 1:
-====== Generic Backup ====== +====== Generic NOR backup ====== 
-===== Backup System Files ===== +  * This guide describes how to perform block-level backup/restore via [[docs:guide-quick-start:sshadministration|CLI]]. 
-Please have a look at [[docs:techref:file_system]] and the [[docs:techref:flash.layout#Details|flash layout details]] and take notice, that OpenWrt covers only the ''firmware'' part. The **[[docs:techref:bootloader]] partition**, ''ART''/''NVRAM'' and similar partitions are NOT part of the OpenWrt firmware. If something should go wrong and the data on these partition gets unexpectedly corrupted, you will not be able to replace it via public OpenWrt sources!+  * Follow [[docs:guide-user:troubleshooting:backup_restore|Backup and restore]] for file-level backup/restore. 
 + 
 +<WRAP center round important 60%> 
 +NAND-based devices should use [[docs:techref:flash#nand-specific_tools_for_reading_and_writing_to_raw_nand|NAND-aware utilities]], as ''dd'' does not properly handle the error correction or bad-block marking of NAND flash. 
 +</WRAP> 
 + 
 +Please have a look at [[docs:techref:file_system]] and the [[docs:techref:flash.layout#Details|flash layout details]] and take notice, that OpenWrt covers only the ''firmware'' part. 
 +The **[[docs:techref:bootloader]] partition**, ''ART''/''NVRAM'' and similar partitions are NOT part of the OpenWrt firmware. 
 +If something should go wrong and the data on these partition gets unexpectedly corrupted, you will not be able to replace it via public OpenWrt sources!
  
 Since OpenWrt does not write to those partitions, it is very unlikely that they get corrupted by OpenWrt itself. Since OpenWrt does not write to those partitions, it is very unlikely that they get corrupted by OpenWrt itself.
Line 7: Line 15:
 Otherwise, in case you lose that data, you would have to go to the forum, ask somebody to make a backup of his and send it to you, then you would have to replace the MAC address, and then flash it via [[docs:techref:hardware:port.jtag]], since your device would probably not boot any longer. Otherwise, in case you lose that data, you would have to go to the forum, ask somebody to make a backup of his and send it to you, then you would have to replace the MAC address, and then flash it via [[docs:techref:hardware:port.jtag]], since your device would probably not boot any longer.
  
-==== Create ART Backup ==== +===== Create ART backup ===== 
-If your ART-partition got corrupted, you would still be able to boot OpenWrt and only your wireless would not function correctly any longer. Easy fix with ''[[docs:techref:mtd]]''.+If your ART-partition got corrupted, you would still be able to boot OpenWrt and only your wireless would not function correctly any longer. 
 +Easy fix with ''[[docs:techref:mtd]]''. 
 <code bash> <code bash>
-dd if=/dev/$(grep -'"art"' /proc/mtd | cut -c 1-4) of=/tmp/art.backup+dd if=/dev/$(sed -n -e '/:.*"art"/s///p' /proc/mtd) of=/tmp/art.backup
 </code> </code>
  
Line 24: Line 34:
 Then copy your backup-file via scp or ssh to your PC and keep them safe for the time when you may need them. Then copy your backup-file via scp or ssh to your PC and keep them safe for the time when you may need them.
  
-==== Create Full MTD Backup ==== +===== Create full MTD backup ===== 
-This script assumes a working bash and SSH on the host (4.0 or newer for ControlMaster support)+This script assumes a working Bash and SSH in native Unix-like or WSL environment
-If you've changed your router's IP address, change the "OPENWRT variable value to the hostname/IP of your OpenWRT router+If you've changed your router's IP address, change the OPENWRT variable value to the hostname/IP of your OpenWrt router. 
- +This will backup your mtd contents to a compressed tarball file ''mtd_backup.tgz'' in the same folder as the script.
-On your local PC (not on the router), using a bash terminal (not Windows Command Prompt, Windows 10 Linux subsystem bash terminal is fine) create a new file (eg. ~/mtdbk.sh) containing the below script. +
-If running on windows, make sure to save the text file as UNIX (LF) encoded, otherwise you'll get syntax errors, and then execute it (./mtdbk.sh). +
-If running on unix-like system, give this file execution privileges (chmod u+x mtdbk.sh) and then execute it (./mtdbk.sh)+
-This will backup your mtd contents to a compressed tarball file "mtd_backup.tgzin the same folder as the script. +
-Make sure to use bash. (Don't do sh ./mtdbk.sh)+
  
 <code bash> <code bash>
 +cat << "EOF" > mtdbk.sh
 #!/bin/bash #!/bin/bash
  
Line 92: Line 98:
  
 echo -e "\nMTD backup complete. Extract the files using:\ntar xzf \"${OUTPUT_FILE}\"" echo -e "\nMTD backup complete. Extract the files using:\ntar xzf \"${OUTPUT_FILE}\""
 +EOF
 +chmod +x mtdbk.sh
 +./mtdbk.sh
 </code> </code>
  
-==== Create Full MTD Backup from OpenWrt ====+===== Create full MTD backup from OpenWrt =====
 The method above works great, but only if you have SSH root access to you router. The method above works great, but only if you have SSH root access to you router.
 In some cases when you don't have SSH root access to router, but can connected from UART console. In some cases when you don't have SSH root access to router, but can connected from UART console.
Line 129: Line 138:
 </code> </code>
  
-==== Create Backup from Bootloader ==== +===== Create backup from bootloader ===== 
-Sometimes it might be necessary to backup settings/partitions from original firmware. Depending on the bootloader, different strategies might be possible.+Sometimes it might be necessary to backup settings/partitions from original firmware. 
 +Depending on the bootloader, different strategies might be possible. 
 + 
 +The flash-chip is mapped to a start address. 
 +With uboot it should be in the following settings:
  
-The flash-chip is mapped to a start address. With uboot it should be in the following settings: 
 <code bash> <code bash>
 printenv printenv
Line 141: Line 153:
 Writing dumps to tftp or nfs. Writing dumps to tftp or nfs.
  
-==== Restore Backup from Bootloader Console ====+===== Restore backup from bootloader console =====
 Many bootloader allow you to work with mtd partition, but beware: they do not have to be identical with the Kernel mtd partitions! Many bootloader allow you to work with mtd partition, but beware: they do not have to be identical with the Kernel mtd partitions!
 Also, with some bootloaders, you cannot use mtd-partition, you must work with offsets. Also, with some bootloaders, you cannot use mtd-partition, you must work with offsets.
 In the latter case, it is probably a good idea to write down these correct offsets when you make the backups. In the latter case, it is probably a good idea to write down these correct offsets when you make the backups.
  
-==== Restore Backup from OpenWrt Console ====+===== Restore backup from OpenWrt console =====
 <code bash> <code bash>
 mtd write art.backup art mtd write art.backup art
Line 153: Line 165:
 Then you must flash this to you device, boot it, and now the partition should be writable. Then you must flash this to you device, boot it, and now the partition should be writable.
  
-===== Backup OpenWrt Configuration ===== +===== Exploring MTD Backups ===== 
-Backup OpenWrt configuration to local PC via [[docs:guide-user:luci:start|LuCI]] or [[docs:guide-quick-start:sshadministration|SSH/SCP]]. +If you want to explore the contents of an MTD backup on your computer, without restoring it to openwrt, you can use [[https://github.com/sviehb/jefferson|jefferson]] with the command
-<WRAP box> +
-//[[http://openwrt.lan/|LuCI]] > System > Backup / Flash Firmware > Generate Archive// +
-</WRAP>+
  
 <code bash> <code bash>
-# Generate backup +jefferson mtd4_rootfs_data.backup -d rootfs
-sysupgrade -b /tmp/backup-${HOSTNAME}-$(date +%F).tar.gz +
-ls /tmp/backup-*.tar.gz +
- +
-# Download backup +
-scp root@openwrt.lan:/tmp/backup-*.tar.gz . +
-</code> +
- +
-[[docs:guide-user:installation:generic.sysupgrade#ensure_desired_configuration_files_will_be_saved|Verify and customize]] your backup. +
- +
-===== Restore OpenWrt Configuration ===== +
-Restore previously saved OpenWrt configuration from local PC via [[docs:guide-user:luci:start|LuCI]] or [[docs:guide-quick-start:sshadministration|SSH/SCP]]. +
-<WRAP box> +
-//[[http://openwrt.lan/|LuCI]] > System > Backup / Flash Firmware > Backup / Restore// +
-</WRAP> +
- +
-<code bash> +
-# Upload backup +
-scp backup-*.tar.gz root@openwrt.lan:/tmp +
- +
-# Restore backup +
-ls /tmp/backup-*.tar.gz +
-sysupgrade -r /tmp/backup-*.tar.gz+
 </code> </code>
  
 +Where the mtd4_rootfs_data.backup file is the mtd block you want to explore. Likely this will be >rootfs_data as it contains most of the customizations you will have made to openwrt.
  • Last modified: 2023/03/19 10:23
  • by ryanc