# Wayback Machine Archiver: Backup Pages with Python

*June 4, 2019* | #my-projects

The [Internet Archive][ia] runs a service called the [Wayback Machine][wbm] to
create a digital archive of the entire internet. It contains the [first
snapshot of my website][first], as well as many others. I love the ability to
go back and see how my site has evolved, and know that even if I stop hosting
it, the archive will live on. That's why I want the Wayback Machine to archive
every change my site goes through.

[ia]: https://archive.org/
[wbm]: https://archive.org/web/
[first]: https://web.archive.org/web/20130518151312/http://alexgude.com/

The Internet Archive makes it easy to submit a site for archival, but doing
this manually is time consuming. So I built [**Wayback Machine
Archiver**][wbma] to automate it.

[wbma]: https://github.com/agude/wayback-machine-archiver

## Wayback Machine Archiver

The Archiver runs on either [Python][python] 2.7 or 3.4+. It can be installed
with pip:

[python]: https://www.python.org/

```bash
pip install wayback-machine-archiver
```

After that, submitting pages for archival is as easy as:

```bash
archiver https://alexgude.com https://alexgude.com/blog/  # etc.
```

This is not much of an improvement over doing it manually, since we still have
to find each URL by hand. Luckily, most sites already have a list of all their
pages in a [sitemap.xml][sitemap].

For example, my sitemap is at `https://alexgude.com/sitemap.xml`. It is
automatically generated by [Jekyll][jekyll] when I update my site. Archiver
can read a sitemap and submit all of the pages listed in it, making archival
of my blog as easy as:

[sitemap]: https://en.wikipedia.org/wiki/Sitemaps
[jekyll]: https://en.wikipedia.org/wiki/Jekyll_(software)

```bash
archiver --sitemaps https://alexgude.com/sitemap.xml
```

Archiver has additional options like using multiple threads, logging, and
archiving the sitemap as well as the pages they link to. Checkout the
[README][wbma] on the Github site, or use the `--help` flag.

### Scheduling Archiver

Archiver follows the [Unix Philosophy][up] of "Make each program do one thing
well", so it leaves the scheduling to another program. I recommend
[`cron`][cron]. Here is how I backup my site, and a few others, each day:

[up]: https://en.wikipedia.org/wiki/Unix_philosophy
[cron]: https://en.wikipedia.org/wiki/Cron

```
# Backup three websites weekly
@weekly archiver --sitemaps https://alexgude.com/sitemap.xml --archive-sitemap-also --log INFO
@weekly archiver --sitemaps http://charles.uno/sitemap.xml --archive-sitemap-also --log INFO
@weekly archiver https://www.radiokeysmusic.com --sitemaps https://www.radiokeysmusic.com/sitemap.xml --archive-sitemap-also --log INFO
```

If you find my Archiver useful, please consider [**donating to the Internet
Archive**][donate]; none of this would be possible without them! Your company
may even match your donation like mine does!

[donate]: https://archive.org/donate/

## Related Posts
- [Jupyter Notebook Templates for Data Science: Plotting Time Series](/blog/data-science-timeseries-plotting-notebook-template/)
- [Introducing the SWITRS SQLite Hosted Dataset](/blog/switrs-sqlite-hosted-dataset/)
- [Jupyter Notebook Templates for Data Science: Plotting](/blog/data-science-plotting-notebook-template/)