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 close1

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:
    # "name:" is optional, only if you want to set the local file name
    - 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

The section name is the host to connect to (blog, backup@bot:2222). To back up one server into several directories, give the sections any names and set host: (same user@host:port format; user:/port: override it):

bot-db:
  host: backup@bot:2222      # -> ~/backups/bot-db/<YYYY-MM-DD>/
  files:
    - /tmp/bot.db.gz

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.9.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.9.0
File Size Uploaded Provenance Actions
close1-0.9.0.tar.gz 24.0 kB Without provenance Details for close1-0.9.0.tar.gz

Built distribution (wheel)

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

Total release size: 43.3 kB

Release files / close1-0.9.0.tar.gz

Download URL close1-0.9.0.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
158f2c2701216b1ac06c22638f1580c45e8c9c39df38ec250b0980af214f271a
BLAKE2b-256 checksum
How to use checksums
a628088319654da2ec0cd368f62bcc7886f185f51dcd0552e9b85baf4d59d655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.9.0-py3-none-any.whl

Download URL close1-0.9.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2470105c669d6181a5678a6596c689a441b7fb78bc1870618cc1b7355ddfcc1e
BLAKE2b-256 checksum
How to use checksums
011204a833c4743a1503de4a00c33dec881fe6bd68796d7c7daa04b14e20b07d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.9.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