What is the purpose of wget backup-converted?
The --backup-converted option in wget is a
specialized command-line flag used during website mirroring to preserve
original file extensions before they are altered for local viewing. When
downloading a website for offline use, wget often converts
links (such as changing a dynamic .php or
.aspx URL to a local .html file) so the pages
can be navigated locally. Enabling this option instructs
wget to save a copy of the original file with a
.orig suffix before making these permanent formatting
adjustments, ensuring that the authentic structure and filenames of the
remote server are not lost.
Understanding the Need for Link Conversion
To understand why --backup-converted is valuable, it
helps to look at how wget handles website mirroring.
Typically, a user will run a command to download a site for offline
browsing using the --convert-links (or -k)
option.
- Without Link Conversion: The downloaded HTML files
still point to the live internet URLs (e.g.,
href="https://example.com/about"). If you open the local file without an internet connection, the links will break. - With Link Conversion:
wgetrewrites those links to point to the local files you just downloaded (e.g.,href="about.html").
While link conversion is essential for offline browsing, it permanently alters the source code of the downloaded files.
How the Backup Option Works
When you append --backup-converted (or the short form
-K) to your wget command, the utility adds a
safety net to the rewriting process.
wgetdownloads the original file from the server (e.g.,index.php).- Before it modifies the links inside
index.phpto make them local-friendly, it creates an exact duplicate of the original file. - It renames this duplicate by appending
.origto the extension (e.g.,index.php.orig). wgetthen proceeds to convert the links in the primary file as requested.
Common Use Cases
This option is particularly useful for developers, system administrators, and digital archivists who need to achieve two conflicting goals at once: viewing a site offline while still maintaining a perfect record of the original server-side code structure.
1. Verification and Auditing
If a converted local page doesn’t render correctly, you can compare
the modified file against the .orig file to determine if
wget’s link conversion caused the layout break or if the
issue existed on the live site.
2. Redeployment and Migration
If you are using wget to scrape a site with the intent
of hosting it elsewhere or analyzing the original file structure, having
the unaltered .orig files ensures you don’t accidentally
lose the original asset paths and file extensions to wget’s
automated rewriting logic.