Skip to main content

close1

A simple tool for daily backups of files and databases over SSH.

Features

  • Pulls files and directories (.tar.gz/.zip) from the servers to your machine; nothing is installed on the servers.
  • Runs commands on the servers (for example, mysqldump, .backup in sqlite3, or stopping a web server for the duration of the backup and starting it again afterwards).
  • Good SSH integration: uses your key through the SSH agent (even if it is passphrase-protected). ControlMaster for speed and for reliability on lossy networks.
  • Tolerates missed cron runs (e.g. when the computer was off). You can run close1 from cron every hour and it still makes one backup per day.
  • Careful rotation: you set how many backups to keep (say, 7). Rotation removes the oldest ones, but it will not delete a 10-day-old backup if there were no newer ones. Even in the worst case you still have some backups.

Install

pipx install .        # or: pip install -e '.[dev]' in a venv

Usage

close1 --check                 # SSH agent, keys, host reachability (copies nothing)
close1                         # back up all hosts from the config
close1 blog -f -v              # only blog, overwrite today's backup, verbose
close1 log                     # show the log (-v: print its path first)
close1 status                  # hosts in storage: last backup, number of days (-v: sizes, file counts)

Config: -c path, otherwise the first one found of $CLOSE1_CONFIG, ~/.config/close1/close1.yml, /etc/close1.yml (no merging). See close1-example.yml (short) and close1-full-example.yml (every option explained). Log: ~/.local/state/close1/close1.log (root: /var/log/close1.log).

Config

_default:
  dest: ~/backups          # -> ~/backups/<host>/<YYYY-MM-DD>/
  keep: 7

blog:
  pre:
    - mysqldump blog | gzip > /tmp/blog-${DATE}.sql.gz
  files:
    - blog.sql.gz: /tmp/blog-${DATE}.sql.gz
    - /var/www/blog/uploads
    - /etc/nginx/sites-enabled
  post:
    - rm /tmp/blog-${DATE}.sql.gz

"backup@bot:2222":
  files:
    - /opt/bot/config.yml
  stdout:
    packages.txt: dpkg -l

All options with explanations: close1-full-example.yml.

SQLite

Do not copy a live SQLite file (in WAL mode part of the data lives in -wal). Take a snapshot in pre and fetch it:

pre:
  - umask 077 && sqlite3 /opt/app/app.db ".backup /tmp/app-${DATE}.db" && gzip -f /tmp/app-${DATE}.db
files:
  - app.db.gz: /tmp/app-${DATE}.db.gz
post:
  - rm -f /tmp/app-${DATE}.db.gz

Unreliable connections

All commands to a host go through one SSH connection (ControlMaster), so a backup needs a single handshake. After a connection error (ssh exit code 255) close1 retries the connection check, file checks and downloads (retries times, retry_delay seconds apart). pre, post and stdout commands are not retried: after a dropped connection it is unknown whether they ran. If they fail, the backup fails and the next cron run starts it again.

cron and ssh-agent

close1 authenticates through ssh-agent. If SSH_AUTH_SOCK is not set (as under cron), it looks for the socket in /run/user/$UID/ (openssh_agent, ssh-agent.socket, gcr/ssh, keyring/ssh, gnupg/S.gpg-agent.ssh). ssh is always called with BatchMode=yes and ForwardAgent=no. While you are not logged in or the key is not loaded into the agent, the backup is skipped and retried on the next run.

By default the first agent that holds any key is used. If you have several agents (e.g. ssh-agent and gnome-keyring) with different keys, set ssh_key: SHA256:... (globally or per host): close1 then uses the agent that holds this key and passes it to ssh as IdentityAgent. If the key is in no agent, the host is skipped. close1 --check lists all agents with their key fingerprints. The key comment (user@host) is not used for matching: it is arbitrary text.

17 * * * * $HOME/.local/bin/close1

Only errors go to stderr (and so to cron mail); everything else goes to the log.

Metadata

Release files for close1 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for close1 0.8.0
File Size Uploaded Provenance Actions
close1-0.8.0.tar.gz 22.9 kB Without provenance Details for close1-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for close1 0.8.0
File Interpreter ABI Platform Actions
close1-0.8.0-py3-none-any.whl Python 3 none any Details for close1-0.8.0-py3-none-any.whl

Total release size: 41.6 kB

Release files / close1-0.8.0.tar.gz

Download URL close1-0.8.0.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7d91a683ee3441e1a395cef42989a07248db6d66515f9cec7b961401cac5cda5
BLAKE2b-256 checksum
How to use checksums
17f3ad13d113c5e346a2ad1828e61f6c921643f297e6c6cfc994f6d1fe367fc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / close1-0.8.0-py3-none-any.whl

Download URL close1-0.8.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
beb979dfa2aa70e455ab93ac33f340c1bdbce079e97cada19432d60d07072720
BLAKE2b-256 checksum
How to use checksums
a7fc990fcf57514838efbda1cdcec5f40807befeb7ffa528f04d7c20852c05fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for close1 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page