# as-backup.sh > Backup and restore CLI for OpenVPN Access Server (AS): the 7 configuration databases plus as.conf. POSIX sh, runs as root on the AS host. This file is enough for routine use; llms-full.txt has every option, message and failure case. Describes as-backup.sh SHA-256 8300d528… (published 2026-11-10). Installed path: /usr/local/bin/as-backup.sh. Check the copy on a host with `as-backup.sh --help`. ## Before you act - A restore STOPS and STARTS the openvpnas service: every VPN user is disconnected for up to about a minute. Get the operator's explicit OK for each restore, and run `--dry-run` first. - In a shell with no TTY (agent shells, ssh host cmd, scripts) a restore asks NO confirmation and runs at once. `--yes` is not needed there. - Every restore first takes a backup of the current state, comment `pre-restore of `, and prints the undo command. Record it and report it to the operator. Running the undo is another restore: it needs a new OK. - Before you change AS settings, take a backup and keep its ID: `id=$(as-backup.sh -q -c "before ")`. - Do not delete archives unless the operator asks. Only `--keep` deletes, and only scheduled (`auto`) backups. - Not in a backup: etc/web-ssl, licence files, the AS package. To move to another AS version, install that package first, then restore. - Not supported: the BACKUP node of a failover pair (openvpnas is not active there). Use the active node. - A backup from another AS version restores with only a warning (`Warning: backup version (X) differs from current AS version (Y)`; `--dry-run` shows both). Tell the operator before restoring it. ## Install ```sh bash <(curl -fsS https://as-backup.devopenvpn.net/install.sh) --yes --keep 14 sha256sum /usr/local/bin/as-backup.sh # compare with https://as-backup.devopenvpn.net/ ``` `--yes` always installs a DAILY systemd timer (or /etc/cron.d/as-backup) and replaces an existing schedule; no option keeps hourly or weekly (only the interactive installer, which needs a terminal). If the host already has a schedule (`systemctl list-timers as-backup.timer`), ask the operator first. `--keep N` = scheduled backups to keep (0 = all; default 14). Existing archives are kept. ## Common commands Backup; stdout is the ID only, plus a newline: ```sh id=$(as-backup.sh -q -c "before LDAP change") ``` List as tab-separated rows, no header: id (= Unix seconds when the backup was taken), date `YYYY-MM-DD HH:MM:SS` UTC, AS version `X.Y.Z`, archive path, comment (empty if none): ```sh as-backup.sh --list --tsv as-backup.sh --list --tsv | awk -F'\t' '$5 == "baseline" { print $1 }' # ID by comment ``` Preview a restore; changes nothing, exit 0: ```sh as-backup.sh -r 1794301200 --dry-run ``` Restore (after the operator's OK): ```sh as-backup.sh -r 1794301200 # Pre-restore backup ID: 1794306000 # Restore complete from backup ID: 1794301200 (undo: as-backup.sh -r 1794306000) ``` These two lines are stable; parse `Pre-restore backup ID: ` for the undo ID. Restore but keep the current connection log (log database): add `--skip-log`. After a restore, check the service: `systemctl is-active openvpnas` and `sacli status` (or /usr/local/openvpn_as/scripts/sacli). Do not parse the human `--list` table or other prose output; use `-q` and `--tsv`. ## All options Backup: (none), `-c, --comment VAL`, `-q, --quiet`, `--auto`, `--keep N` (only with --auto). List: `-l, --list`, `--no-header`, `--as-version X.Y.Z`, `--tsv`. Restore: `-r, --restore ID`, `--dry-run`, `-y, --yes`, `--skip-log`. Help: `-h, --help`. An option used without the mode it belongs to is refused (exit 1, e.g. `--dry-run requires --restore`). ## Exit codes - 0: success. Also returned by a scheduled `--auto` run that was skipped because another operation was running. - 1: error; the reason is on stderr. Also returned when a restore is cancelled at the prompt. - 4: another backup or restore holds the lock (`Another as-backup operation is running (pid N)`). Nothing was changed. Wait and retry (a backup takes seconds, a restore up to a minute; e.g. every 30 s for 5 min, then report); do not remove /run/as-backup.lock yourself (a lock whose PID is gone is cleared automatically). - 130 / 143: interrupted (SIGINT / SIGTERM); temp files, partial archive and lock were cleaned up. ## Constraints - Comment: at most 80 bytes; the exact comment `auto` is reserved for scheduled backups. - Archives: /usr/local/openvpn_as/etc/backup//*.tar.gz (path = `--tsv` column 4). Removing one file deletes that backup; do it only when the operator names it. `--keep` prunes after a successful backup. - Backup ID = Unix seconds, numbers only, unique. - One backup or restore at a time; `--list` takes no lock and needs no root. - If a restore fails after replacing databases it prints `service NOT restarted` and leaves openvpnas stopped on purpose: report to the operator, do not just start it. See llms-full.txt. ## Links - [llms-full.txt](https://as-backup.devopenvpn.net/llms-full.txt): complete agent reference (all options, every message with the action to take, failure recovery, formats) - [doc.html](https://as-backup.devopenvpn.net/doc.html): documentation for people - [install.sh](https://as-backup.devopenvpn.net/install.sh), [as-backup.sh](https://as-backup.devopenvpn.net/as-backup.sh): the scripts; SHA-256 on https://as-backup.devopenvpn.net/