Skip to main content

A Python software to backup Linode configuration to a local folder or Linode Object Storage

Project description

What is YesterdayPy? - TLDR Version

A Python software to backup Linode configuration to a local folder or Linode Object Storage.

What is YesterdayPy? - Longer Version

Have you asked the question “How was this configured yesterday?” while working with Linode, or any of the variations with the same meaning?
If yes, YesterdayPy will help you find the answer.
If no, well, you are in the wrong corner of the Internet.

Note: A project called yesterday was already in PyPI, so I just added Py in front of the name.

YesterdayPy creates a backup of your Linode configuration.
For each Linode product (Firewall for example), the software will create a JSON file for each object you have.
The file will be named using the format ID+date.json, with ID being the object’s ID (every Linode object has an ID), and date being the last update date.
If the file already exists, no file is created. That means, it will only backup the changes since the last backup.

If you want to know how the object was configured yesterday while troubleshooting a problem, you can then just compare the current version with the JSON file.

Technical Bits

Requires Python version 3.9 or above.
If used to backup configuration to Linode Object Storage, Boto3 is also required (https://github.com/boto/boto3).
Currently supports the following products Firewall, Linode, LKE, and VPC.

Installation

Use pipx (https://github.com/pypa/pipx) to install YesterdayPy.
pipx install yesterdaypy
If you need Linode Object Storage to store the backup, install Boto3.
You must use boto version 1.35.99, until Linode fixes compatibility.
pipx inject yesterdaypy boto3==1.35.99
You can also clone this repository and run:
python yesterdaypy/yesterdaypy.py

How to use it?

First, you need to setup the necessary environment variables.

Linode token is mandatory:
export LINODE_TOKEN=ABC
If using Linode Object Storage:
export AWS_ACCESS_KEY_ID=ABC
export AWS_SECRET_ACCESS_KEY=ABC
export AWS_ENDPOINT_URL=ABC
Run the software:
yesterdaypy
It will backup all objects to the current directory, for all supported products, with a folder per product.
To backup to a specific folder, specify the location.
yesterdaypy --storage /home/user/backup/example/
To backup to Linode Object Storage, storage needs to start with s3:// followed by the bucket name.
yesterdaypy --storage s3://bucket-name
You can also use –products to limit the products you want to backup.
Use –errors to get the list of errors.
Use –output to print basic information.
Use –verbose to print extra information.
Use –debug to print debug information.
Lastly, –help for the help information.

Docker

You can use the Dockerfile in this repository to build a local image.
Also, the image is available from DockerHub (https://hub.docker.com/r/leonardobdes/yesterdaypy).

Use the export command to setup the necessary environment variables.
Example using DockerHub:
docker run -e LINODE_TOKEN \
--mount type=bind,src=.,dst=/usr/local/yesterdaypy \
leonardobdes/yesterdaypy:latest
This will save the files to the current folder.
You don’t need the mount option to save to Linode Object Storage.

Systemd Service

The most common setup will be to run YesterdayPy daily.
You can do that using a systemd service and timer.
Copy the files yesterdaypy.service and yesterdaypy.timer to the folder /etc/systemd/system/.

The timer is configured to run daily at midnight, so change it based on your preference.
The service has 2 examples, the first command runs the software after installation using pipx, and the second one using Docker.
In both cases, it reads the Linode token from the file linode_token.txt.

jq

Use jq to print the text formatted.
You can also use the online version https://play.jqlang.org/
$ jq . 1056933+20250222233724.json
{
  "id": 1056933,
  "label": "test-fw",
  "created": "2024-10-22T22:38:26",
  "updated": "2025-02-22T23:37:24",
  "status": "enabled",
  "rules": {
    "inbound": [
      {
        "action": "ACCEPT",
        "addresses": {
          "ipv4": [
            "1.1.1.1/32"
          ]
        },
        "ports": "22",
        "protocol": "TCP",
        "label": "test-ssh",
        "description": null
      }
    ],
    "inbound_policy": "DROP",
    "outbound": [],
    "outbound_policy": "ACCEPT",
    "version": 3,
    "fingerprint": "cb6bf75b"
  },
  "tags": [],
  "entities": [
    {
      "id": 72473810,
      "type": "linode",
      "label": "ubuntu-gb-lon",
      "url": "/v4/linode/instances/72473810"
    }
  ]
}
You can query a specific part.
$ jq .rules.inbound 1056933+20250222233724.json
[
  {
    "action": "ACCEPT",
    "addresses": {
      "ipv4": [
        "1.1.1.1/32"
      ]
    },
    "ports": "22",
    "protocol": "TCP",
    "label": "test-ssh",
    "description": null
  }
]

jd

Use jd to compare 2 JSON files.
You can also use the online version http://play.jd-tool.io/
$ jd 1056933+20250222233724.json 1056933+20250314231035.json
@ ["entities",0]
[
- {"id":72473810,"label":"ubuntu-gb-lon","type":"linode","url":"/v4/linode/instances/72473810"}
]
@ ["rules","fingerprint"]
- "cb6bf75b"
+ "69cc1741"
@ ["rules","inbound",1]
  {"action":"ACCEPT","addresses":{"ipv4":["1.1.1.1/32"]},"description":null,"label":"test-ssh","ports":"22","protocol":"TCP"}
+ {"action":"ACCEPT","addresses":{"ipv4":["0.0.0.0/0"],"ipv6":["::/0"]},"description":null,"label":"icmp","protocol":"ICMP"}
]
@ ["rules","version"]
- 3
+ 4
@ ["updated"]
- "2025-02-22T23:37:24"
+ "2025-03-14T23:10:35"

To do

  • Products

    Add more products. Also, some objects have other obejcts under it (Linode Configuration Profile).

  • Thread

    Add threads for large configurations.

  • Mac OS

    Test on MacOS, it should work.

  • Windows

    Need some changes to work on Windows.

Other software ideas

  • YesterdayPy_Clone

    Clone an object with a new label (name).

  • YesterdayPy_Restore

    Restore the object to the configuration of the JSON file.

Author

Name:
Leonardo Souza
LinkedIn:

How to report bugs?

Use GitHub issues to report bugs.

How to request new functionalities?

Use GitHub issues to request new functionalities.
Use the following format in the title RFE - Title.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yesterdaypy-1.1.4.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yesterdaypy-1.1.4-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file yesterdaypy-1.1.4.tar.gz.

File metadata

  • Download URL: yesterdaypy-1.1.4.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for yesterdaypy-1.1.4.tar.gz
Algorithm Hash digest
SHA256 0f17d6d36e020f215bb46bae9f2878225e0cb3e7d3b48b255880d63b098afe14
MD5 5e06370496a0c24997db42b14193aefd
BLAKE2b-256 fe28fe20818075b505c206d2104732a7720baa09573248e0d8b9e28ea6837600

See more details on using hashes here.

File details

Details for the file yesterdaypy-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: yesterdaypy-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for yesterdaypy-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5628115b4435faaa73f244d12885df2e1de34a0b845eeb175c176f13f17fe0b3
MD5 92c1cf817e1a7e11a8dce7ea2432f5e8
BLAKE2b-256 e0d7830145d538e2f79bdd5235cd934ebcdc34eada5e348b19d1ab9d5341df4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page