Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:user-guide:installation:generic.backup [2018/02/20 20:00] – ↷ Page moved from docs:user-guide:generic.backup to docs:user-guide:installation:generic.backup bobafetthotmail | docs:guide-user:installation:generic.backup [2023/03/19 10:23] (current) – rephrase to use gender neutral language ryanc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Generic | + | ====== Generic |
| + | * This guide describes how to perform block-level backup/ | ||
| + | * Follow [[docs: | ||
| - | ===== Backup system files ===== | + | <WRAP center round important 60%> |
| + | NAND-based devices should use [[docs: | ||
| + | </ | ||
| - | Please have a look at [[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. | ||
| However, if you mess around with the bootloader, you certainly should create a copy of this data on your PC. | However, if you mess around with the bootloader, you certainly should create a copy of this data on your PC. | ||
| - | 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 theirs |
| - | ==== 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 '' | + | < |
| - | + | dd if=/dev/$(sed -n -e '/:.*" | |
| - | < | + | |
| - | dd if=/dev/$(grep -i '" | + | |
| </ | </ | ||
| + | If your bootloader-partition got corrupted, you would not even have a [[docs: | ||
| - | If your bootloader-partition got corrupted, you would not even have a [[docs: | + | However, once you've gotten yourself into the position to write to the flash again, you will still need something you can write to it. |
| - | + | Something that will work. | |
| - | + | And here is, where your backup will come in handy: | |
| - | However, once you've gotten yourself into the position to write to the flash again, you will still need something you can write to it. Something that will work. And here is, where your backup will come in handy: | + | < |
| - | + | ||
| - | < | + | |
| dd if=/ | dd if=/ | ||
| </ | </ | ||
| Line 29: | 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' |
| - | + | 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" | + | |
| - | < | + | < |
| + | cat << " | ||
| #!/bin/bash | #!/bin/bash | ||
| Line 44: | Line 46: | ||
| function die() { | function die() { | ||
| - | echo " | + | echo "${@}" |
| exit 2 | exit 2 | ||
| } | } | ||
| OUTPUT_FILE=" | OUTPUT_FILE=" | ||
| - | + | OPENWRT=" | |
| - | OPENWRT=" | + | |
| TMPDIR=$(mktemp -d) | TMPDIR=$(mktemp -d) | ||
| - | BACKUP_DIR=" | + | BACKUP_DIR=" |
| - | mkdir -p " | + | mkdir -p "${BACKUP_DIR}" |
| - | SSH_CONTROL=" | + | SSH_CONTROL=" |
| function cleanup() { | function cleanup() { | ||
| Line 64: | Line 64: | ||
| echo " | echo " | ||
| - | rm -r " | + | rm -r "${TMPDIR}" |
| } | } | ||
| trap cleanup EXIT | trap cleanup EXIT | ||
| Line 70: | Line 70: | ||
| # Open master ssh connection, to avoid the need to authenticate multiple times | # Open master ssh connection, to avoid the need to authenticate multiple times | ||
| echo " | echo " | ||
| - | ssh -oControlMaster=yes -oControlPath=" | + | ssh -o " |
| # This is the command we'll use to reuse the master connection | # This is the command we'll use to reuse the master connection | ||
| - | SSH_CMD=(ssh -oControlMaster=no -oControlPath=" | + | SSH_CMD=(ssh -o " |
| # List remote mtd devices from /proc/mtd. The first line is just a table | # List remote mtd devices from /proc/mtd. The first line is just a table | ||
| # header, so skip it (using tail) | # header, so skip it (using tail) | ||
| " | " | ||
| - | MTD_DEV=$(echo $REPLY | cut -f1 -d:) | + | MTD_DEV=$(echo ${REPLY} | cut -f1 -d:) |
| - | MTD_NAME=$(echo $REPLY | cut -f2 -d\" | + | MTD_NAME=$(echo ${REPLY} | cut -f2 -d\" |
| - | echo " | + | echo " |
| # It's important that the remote command only prints the actual file | # It's important that the remote command only prints the actual file | ||
| # contents to stdout, otherwise our backup files will be corrupted. Other | # contents to stdout, otherwise our backup files will be corrupted. Other | ||
| Line 89: | Line 89: | ||
| # Use gzip and tar to compress the backup files | # Use gzip and tar to compress the backup files | ||
| - | echo " | + | echo " |
| - | (cd " | + | (cd "${TMPDIR}" && tar czf - " |
| # Clean up a little earlier, so the completion message is the last thing the user sees | # Clean up a little earlier, so the completion message is the last thing the user sees | ||
| Line 97: | Line 97: | ||
| trap EXIT | trap EXIT | ||
| - | echo -e "\nMTD backup complete. Extract the files using:\ntar xzf \" | + | echo -e "\nMTD backup complete. Extract the files using:\ntar xzf \"${OUTPUT_FILE}\"" |
| + | 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. | ||
| + | In some cases when you don't have SSH root access to router, but can connected from UART console. | ||
| + | For example TP-Link Archer C9 HW ver 5.0 with original stock firmware. | ||
| + | You can make backup from router to you host. | ||
| + | <code bash> | ||
| + | # Save the script | ||
| + | cat << " | ||
| + | #!/bin/sh | ||
| - | Sometimes it might be necessary to backup settings/ | + | BACKUP_HOST=" |
| + | BACKUP_USER=" | ||
| + | echo " | ||
| - | The flash-chip is mapped to a start adress. With uboot it should be in settings | + | cat /proc/mtd | tail -n+2 | while read; do |
| - | < | + | MTD_DEV=$(echo ${REPLY} | cut -f1 -d:) |
| - | printenv | + | MTD_NAME=$(echo ${REPLY} | cut -f2 -d\" |
| - | bdinfo | + | echo " |
| + | dd if=/ | ||
| + | done | ||
| + | EOF | ||
| + | |||
| + | # Run the script | ||
| + | sh / | ||
| </ | </ | ||
| - | * memory dump to serial that is logged (uboot: //md// ; redboot: //dump//) | + | Now you'll be asked for SSH password from PC for each mtd device 5 or more times. |
| - | * writing dumps to tftp or nfs | + | |
| - | ==== Restore Backup ==== | + | After operation completed, you'll find all files in user home directory on PC. |
| - | === from Bootloader console === | + | If you on linux and wish to see progress you can run in separate console on PC: |
| - | 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, | + | <code bash> |
| + | watch -n 0.2 ls -l --block-size=K ~ | ||
| + | </ | ||
| + | ===== Create backup from bootloader ===== | ||
| + | Sometimes it might be necessary to backup settings/ | ||
| + | Depending on the bootloader, different strategies might be possible. | ||
| - | === from OpenWrt console === | + | The flash-chip |
| - | < | + | With uboot it should be in the following settings: |
| - | Above method could work, but most probably will not as art partition | + | |
| - | [[toh/ | + | |
| - | or here: [[https:// | + | |
| - | Then you must flash this to you device, boot it, and now the partition | + | |
| - | From: | + | <code bash> |
| - | [[https:// | + | printenv |
| - | [[https:// | + | bdinfo |
| + | </code> | ||
| - | ===== Backup OpenWrt configuration ===== | + | Memory dump to serial that is logged (uboot: //md// ; redboot: // |
| + | Writing dumps to tftp or nfs. | ||
| - | You can backup | + | ===== Restore |
| - | < | + | Many bootloader allow you to work with mtd partition, but beware: they do not have to be identical with the Kernel mtd partitions! |
| - | sysupgrade --create-backup / | + | 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. | ||
| + | |||
| + | ===== Restore backup from OpenWrt console ===== | ||
| + | < | ||
| + | mtd write art.backup | ||
| </ | </ | ||
| + | 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. | ||
| - | Now on your local computer, use scp to retreive the file: | + | ===== Exploring MTD Backups ===== |
| - | (Remember to use the ip of your OpenWRT device and the filename of your backup file.) | + | If you want to explore the contents of an MTD backup |
| - | < | + | < |
| - | scp root@192.168.1.1:/ | + | jefferson mtd4_rootfs_data.backup -d rootfs |
| </ | </ | ||
| - | You might also want to backup other files you have edited such as: | + | Where the mtd4_rootfs_data.backup file is the mtd block you want to explore. Likely this will be rootfs_data |
| - | + | ||
| - | * ''/ | + | |
| - | * ''/ | + | |
| - | * ''/ | + | |
| - | + | ||
| - | see also '' | + | |
| - | + | ||
| - | ===== Restore OpenWrt configuration ===== | + | |
| - | + | ||
| - | You can restore | + | |
| - | * web interface: //System > Backup / Flash Firmware > Backup / Restore// | + | |
| - | * command line: | + | |
| - | * < | + | |
| - | * If you got a .tar backup file and get " | + | |
| - | * < | + | |
| - | cd / | + | |
| - | tar -xvf / | + | |