Differences
This shows you the differences between two versions of the page.
| 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:02] – Code optimized vgaetera | docs:guide-user:installation:generic.backup [2022/07/11 15:06] – Add instructions for how to explore MTD backups spookyuser | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Generic | + | ====== Generic |
| - | ===== Backup | + | * This guide describes how to perform block-level backup/ |
| - | Please have a look at [[docs: | + | * Follow [[docs: |
| + | |||
| + | <WRAP center round important 60%> | ||
| + | NAND-based devices should use [[docs: | ||
| + | </ | ||
| + | |||
| + | Please have a look at [[docs: | ||
| + | The **[[docs: | ||
| + | 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: | 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: | ||
| - | ==== 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 '' | + | 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 '' | ||
| <code bash> | <code bash> | ||
| - | dd if=/dev/$(grep -i '" | + | dd if=/dev/$(sed -n -e '/:.*" |
| </ | </ | ||
| 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 | + | ===== Create |
| - | This script assumes a working | + | This script assumes a working |
| - | If you've changed your router' | + | If you've changed your router' |
| - | + | This will backup your mtd contents to a compressed tarball file '' | |
| - | 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 (./ | + | |
| - | If running on unix-like system, give this file execution privileges (chmod u+x mtdbk.sh) and then execute it (./ | + | |
| - | This will backup your mtd contents to a compressed tarball file "mtd_backup.tgz" | + | |
| - | Make sure to use bash. (Don't do sh ./mtdbk.sh) | + | |
| <code bash> | <code bash> | ||
| + | cat << " | ||
| #!/bin/bash | #!/bin/bash | ||
| Line 92: | Line 98: | ||
| echo -e "\nMTD backup complete. Extract the files using:\ntar xzf \" | echo -e "\nMTD backup complete. Extract the files using:\ntar xzf \" | ||
| + | EOF | ||
| + | chmod +x mtdbk.sh | ||
| + | ./mtdbk.sh | ||
| </ | </ | ||
| - | ==== Create | + | ===== Create |
| 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 104: | Line 113: | ||
| #!/bin/sh | #!/bin/sh | ||
| - | BACKUP_HOST=" | + | BACKUP_HOST=" |
| BACKUP_USER=" | BACKUP_USER=" | ||
| echo " | echo " | ||
| Line 117: | Line 126: | ||
| # Run the script | # Run the script | ||
| - | sh backup.sh | + | sh /tmp/backup.sh |
| </ | </ | ||
| - | Now you'll be asked for SSH password from PC for each mtd device | + | Now you'll be asked for SSH password from PC for each mtd device 5 or more times. |
| - | 5 or more times. | + | |
| After operation completed, you'll find all files in user home directory on PC. | After operation completed, you'll find all files in user home directory on PC. | ||
| - | If you on linux and wish to see progress you can run in separate console on PC, in home dir: | + | If you on linux and wish to see progress you can run in separate console on PC: |
| <code bash> | <code bash> | ||
| - | watch -n 0.2 ls -l --block-size=K | + | watch -n 0.2 ls -l --block-size=K |
| </ | </ | ||
| - | ==== Create | + | ===== Create |
| - | Sometimes it might be necessary to backup settings/ | + | Sometimes it might be necessary to backup settings/ |
| + | 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 settings | ||
| <code bash> | <code bash> | ||
| printenv | printenv | ||
| Line 139: | Line 150: | ||
| </ | </ | ||
| - | * memory | + | Memory |
| - | * writing | + | Writing |
| - | ==== Restore | + | ===== Restore |
| - | === 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, | + | Also, with some bootloaders, |
| - | + | In the latter case, it is probably a good idea to write down these correct offsets when you make the backups. | |
| - | === From OpenWrt Console === | + | |
| - | <code bash>mtd write art.backup art</ | + | |
| - | Above method could work, but most probably will not as art partition is usually not writable, so you will have to compile you own kernel after doing some minor modification like described here: | + | |
| - | [[toh/ | + | |
| - | or here: [[https:// | + | |
| - | Then you must flash this to you device, boot it, and now the partition should be writable. | + | |
| - | + | ||
| - | From: | + | |
| - | [[https:// | + | |
| - | [[https:// | + | |
| - | + | ||
| - | ===== Backup OpenWrt Configuration ===== | + | |
| - | Backup OpenWrt configuration to local PC via [[docs: | + | |
| - | <WRAP box> | + | |
| - | // | + | |
| - | </ | + | |
| + | ===== Restore backup from OpenWrt console ===== | ||
| <code bash> | <code bash> | ||
| - | # Generate backup | + | mtd write art.backup |
| - | sysupgrade -b / | + | |
| - | ls /tmp/backup-*.tar.gz | + | |
| - | + | ||
| - | # Download backup | + | |
| - | scp root@openwrt.lan:/ | + | |
| </ | </ | ||
| + | Above method could work, but most probably will not as art partition is usually not writable, so you will have to compile you own kernel after doing some [[toh: | ||
| + | Then you must flash this to you device, boot it, and now the partition should be writable. | ||
| - | [[docs: | + | ===== Exploring MTD Backups |
| - | + | 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 | |
| - | ===== Restore OpenWrt Configuration | + | |
| - | Restore previously saved OpenWrt configuration from local PC via [[docs:guide-user: | + | |
| - | <WRAP box> | + | |
| - | //[[http:// | + | |
| - | </ | + | |
| <code bash> | <code bash> | ||
| - | # Upload backup | + | jefferson mtd4_rootfs_data.backup -d rootfs |
| - | scp backup-*.tar.gz root@openwrt.lan:/ | + | |
| - | + | ||
| - | # Restore backup | + | |
| - | ls /tmp/backup-*.tar.gz | + | |
| - | sysupgrade -r / | + | |
| </ | </ | ||
| + | Where the mtd4_rootfs_data.backup file is the mtd block you want to explore. Likely this will be > | ||