wiki/_next/data/Ie9t5zutrXP6Of75Cb5xF/cli.borg.json
2022-07-29 15:41:17 +00:00

1 line
15 KiB
JSON

{"pageProps":{"metadata":{"date":"\"2021-05-30 21:40:24 +08:00\"","date_modified":"\"2021-07-13 22:54:32 +08:00\"","language":"en","source":""},"title":"Command line: BorgBackup","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"synopsis"},"children":[{"type":"text","value":"Synopsis"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.borg#synopsis"},"children":[{"type":"text","value":"Synopsis"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.borg#options"},"children":[{"type":"text","value":"Options"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"repositories-and-archives"},"children":[{"type":"text","value":"Repositories and archives"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.borg#repositories-and-archives"},"children":[{"type":"text","value":"Repositories and archives"}]}]}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"environment-variables"},"children":[{"type":"text","value":"Environment variables"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.borg#environment-variables"},"children":[{"type":"text","value":"Environment variables"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.borg#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"quickstart"},"children":[{"type":"text","value":"Quickstart"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.borg#quickstart"},"children":[{"type":"text","value":"Quickstart"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"practicing-safe-backup-script"},"children":[{"type":"text","value":"Practicing safe backup script"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.borg#practicing-safe-backup-script"},"children":[{"type":"text","value":"Practicing safe backup script"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"an-interactive-interface-for-extracting-archives"},"children":[{"type":"text","value":"An interactive interface for extracting archives"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.borg#an-interactive-interface-for-extracting-archives"},"children":[{"type":"text","value":"An interactive interface for extracting archives"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"BorgBackup is a deduplicating archiver with compression and encryption.\nIn other words, this is the best backup tool (as of 2021-05-30).\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In this note, we'll be covering the following v1.1.16 and above.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For more information, you can view "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"borg.1"}]},{"type":"text","value":" manual page.\nIt has all of the information you can possibly know about the tool, making it a perfect reference.\nThis note rips off a few relevant pages from there.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"synopsis"},"children":[{"type":"text","value":"Synopsis"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"borg [options...] [subcommand [subcommand_options...] [subcommand_positional_args...]]\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Borg recommends to pass the options before the positional arguments.\nIt can be picky with certain subcommands output being affected from the order of the arguments but you should be safe when you do the recommended practice.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Borg uses a Git-style command-line interface with subcommands and some common options to choose from.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can set the log level of the program with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--debug"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--info"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--warning"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--error"}]},{"type":"text","value":", and "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--critical"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-v, --verbose"}]},{"type":"text","value":" is an alias for "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--info"}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-p, --progress"}]},{"type":"text","value":" shows progress information; will be slower on certain operations due to additional passing of the metadata\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Keep in mind, Borg doesn't have global configuration files, only per-repo configurations.\nYou can create configurations with a little hard work and shell scripts.\nBut if you want a tool that already does that, you have "},{"type":"element","tagName":"a","properties":{"href":"https://torsion.org/borgmatic/"},"children":[{"type":"text","value":"Borgmatic"}]},{"type":"text","value":" as an option with plain-text files in YAML format.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"repositories-and-archives"},"children":[{"type":"text","value":"Repositories and archives"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Most of the subcommands take the repository path with a certain format.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"${REPOSITORY_URL}::${ARCHIVE_NAME}\n"}]}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"# Points to an repo\n/home/foo-dogsquared/backup\n\n# Points to an archive named '2021-03-02' from the previous repo.\n/home/foo-dogsquared/backup::2021-03-02\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can also refer to a name dynamically with placeholders.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"/home/{user}/backup::{hostname}-{user}-{now}\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For more information, you can see the related section for Borg placeholders.\nOr you can run "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"borg help placeholders"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"h1","properties":{"id":"environment-variables"},"children":[{"type":"text","value":"Environment variables"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Borg will also take environment variables being used by most (if not all) of the subcommands.\nVery useful for scripting and saving time not repeating the same arguments.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"BORG_REPO"}]},{"type":"text","value":" - the repo URL\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"BORG_PASSPHRASE"}]},{"type":"text","value":" - the repo passphrase, if it has encryption enabled\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"BORG_PASSCOMMAND"}]},{"type":"text","value":" - the command used to get the passphrase\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Borg is a comprehensive tool for a comprehensive backup system.\nHere are some of the real-life examples of using the program.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"quickstart"},"children":[{"type":"text","value":"Quickstart"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Just from how I imagined I would start using this tool, anyway.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"# Initialize the Borg repo in the specified path with a simple passphrase.\nborg init --encryption repokey ${REPO_PATH}\n\n# Create an archive in the repo and save the documents, pictures, and videos folder.\n# This will prompt you into entering the passphrase.\nborg create --verbose --progress ${REPO_PATH}::{hostname}-{now:%F-%T-%z} ~/Documents ~/Pictures ~/Videos\n\n# Entering the passphrase can be annoying so let's save that into a variable.\n# Luckily, Borg already handles this by setting BORG_PASSPHRASE.\n# Thus, it will not bother us again.\nBORG_PASSPHRASE='gum cavity cabinet auditorium'\n\n# List all of the archives saved so far.\nborg list ${REPO_PATH}\n\n# List the files in the specified archive.\nborg list ${REPO_PATH}::${ARCHIVE_NAME}\n\n# Extract only the documents folder.\nborg extract --verbose --progress ${REPO_PATH}::{hostname}-{now:%F-%T-%z} ~/Documents\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"practicing-safe-backup-script"},"children":[{"type":"text","value":"Practicing safe backup script"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Better be safe than sorry.\nHere's the safe backup in all of its glory in Bash.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"if $# -eq 1; then echo \"No directories and files to be saved.\" && exit 1; fi\n\nlocations=$@\n\nborg create --verbose --stats --compression lz4 --exclude '**/.node_modules' ::{hostname}-{now:%F-%H-%M-%S-%z} ${locations[@]}\nborg check --verbose --verify-data\nborg prune --verbose --keep-daily 7 --keep-hourly 7 --keep-weekly 6 --keep-monthly 6\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Since the script only lets you enter arguments used for saving into the archive, you have to use environment variables.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"BORG_REPO=\"$HOME/backups\" BORG_PASSCOMMAND='gopass show misc/personal-borgbackup-repo' safe-borg-backup ~/projects ~/library ~/writings\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"an-interactive-interface-for-extracting-archives"},"children":[{"type":"text","value":"An interactive interface for extracting archives"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"All-time favorite fzf (see "},{"type":"element","tagName":"a","properties":{"href":"/cli.fzf"},"children":[{"type":"text","value":"Command line: fzf"}]},{"type":"text","value":") is required.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"export BORG_PASSPHRASE=\"oral hygiene\"\nexport BORG_REPO=\"${REPO_PATH}\"\n\nborg list --format=\"{name}{NL}\" \\\n | fzf \\\n | xargs --replace=\"{}\" borg extract --verbose --progress ::{}\n"}]}]}]},"backlinks":[{"path":"/lang.oil","title":"Oil shell language"}]},"__N_SSG":true}