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 give a section any name, set host: (same user@host:port format; user:/port: override it).

Several projects on one server go under projects:. Each project is a separate backup in its own directory and inherits the server's options (it can override them, except host):

echo:
  host: root@echo.example.com:12234
  keep: 30
  projects:
    shop:                    # -> ~/backups/echo/shop/<YYYY-MM-DD>/
      files:
        - /var/www/shop
    wiki:                    # -> ~/backups/echo/wiki/<YYYY-MM-DD>/
      keep: 7
      files:
        - /var/lib/wiki

close1 echo backs up all projects of the server, close1 echo/shop only one. pre/files/stdout/post at the server level are not inherited: they make one more backup, into ~/backups/echo/<YYYY-MM-DD>/ (beside the project directories). close1 status lists projects as echo/shop.

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.11.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.11.0
File Size Uploaded Provenance Actions
close1-0.11.0.tar.gz 26.5 kB Without provenance Details for close1-0.11.0.tar.gz

Built distribution (wheel)

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

Total release size: 47.2 kB

Release files / close1-0.11.0.tar.gz

Download URL close1-0.11.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1696464a20c96446e5261a90b9782ab9841e03f7fdf16f36bb12aa68a76ba79d
BLAKE2b-256 checksum
How to use checksums
141cabfd33c5e71eb0ae46920412d511961b5ead8ceabcb86e0744cb2c47a4cf
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.11.0-py3-none-any.whl

Download URL close1-0.11.0-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1811dc9d2eb144ec3b1746ebc9196ea33893566adae1f24d26ad038c5319ab2
BLAKE2b-256 checksum
How to use checksums
b1e7eb2909b4d37da63946de7e7595006cd3d21e09d75a005b64c54462d01a65
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.11.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