Recover Pastebinit Files with pbget Without Losing Track of Them
pbget pulls back whatever pbput or pbputs sent to a paste site, file, directory or piped output alike. You will finish able to tell printed pastes from extracted archives, and to land the contents in a directory you actually chose.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes, plus the time it takes to get hold of a real paste URL. The examples match the installed pastebinit package, version 1.6.2-1, and its pbget(1) manpage.
- A shell and the pastebinit package. That is all the tooling this needs.
- A URL from a compatible uploader. One produced by
pbputorpbputs, not a random paste link. - Write access to a destination you choose. No elevated privileges required. Do not reach for
sudoto paper over a bad destination choice: it just turns an untrusted archive into a root-owned file-writing operation.
1. Check the installed command
Confirm which executable and package version you have before you trust anything it tells you. This is read-only:
$ command -v pbget
/usr/bin/pbget
$ dpkg-query -W -f='${Package} ${Version}\n' pastebinit
pastebinit 1.6.2-1
pbget is a name-specific link to the pastebinit package's pbput script, and its interface stays deliberately small:
pbget URL [DIRECTORY]
URL is mandatory; the optional DIRECTORY only matters when the retrieved data turns out to be a tar archive. There is no --help and no output-format switches in this installed implementation, so do not go borrowing flags from a different downloader.
Checkpoint
If command -v comes back empty, stop and install the package through your normal system change process. Installation is not part of this recovery workflow.
2. Prepare a controlled destination
For an uploaded file or directory, work in a new, private directory rather than something you already care about:
$ dest="$(mktemp -d)"
$ printf 'destination: %s\n' "$dest"
destination: /tmp/tmp.a1b2C3d4
The name mktemp generates will differ on your machine. Never point pbget at /, your home directory, or anywhere else with files you would miss. For archives, the script runs tar -C DIRECTORY -xvf under the hood, so extraction can create or overwrite paths in that destination according to whatever the archive contains. Creating the temp directory changes local state, but it is trivially reversible: remove it once you have checked its contents and no longer need them.
Want something that survives a reboot instead? Use a persistent directory:
$ dest="$PWD/pbget-recovery"
$ mkdir -- "$dest"
$ test -w "$dest" && echo "writable: $dest"
writable: /path/to/pbget-recovery
If mkdir reports the directory already exists, do not just reuse it blind. Inspect it first, pick an empty directory, or remove only a directory you have personally confirmed is disposable.
3. Retrieve an uploaded file or directory
Swap in the complete URL the uploader gave you, and quote it: a stray shell character in a copied URL can otherwise change the command underneath you.
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' "$dest"
docs/notes.txt
docs/config.ini
INFO: Output is in [/tmp/tmp.a1b2C3d4]
The URL and file names above are examples of shape, not a live paste. For an archive, the installed script prints each path as tar extracts it, then reports the destination. A tidy-looking path list is not a trust decision on its own: inspect the files before you open or execute anything in them.
Checkpoint
Verify what actually arrived rather than trusting the paste's own description of itself:
$ find "$dest" -maxdepth 3 -type f -print
/tmp/tmp.a1b2C3d4/docs/notes.txt
/tmp/tmp.a1b2C3d4/docs/config.ini
$ file "$dest"/docs/*
/tmp/tmp.a1b2C3d4/docs/notes.txt: ASCII text
/tmp/tmp.a1b2C3d4/docs/config.ini: ASCII text
4. Handle data uploaded from standard input
pbput does not tar data that came in on standard input. In that case pbget decodes and decompresses the paste, then writes the original content straight to standard output, so leave the destination argument out entirely:
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' > recovered.txt
$ wc -c recovered.txt
128 recovered.txt
That redirection is your shell's doing, not pbget's. Get the URL wrong, or hand it a paste in a format this old script does not expect, and you can end up with an empty or half-written file. Route it through a temporary path first and inspect before you replace anything real:
$ tmp_out="$(mktemp)"
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' > "$tmp_out"
$ file "$tmp_out"
$ mv -- "$tmp_out" recovered.txt
That final mv only belongs after you have checked the temporary file. If a run goes wrong, delete the temporary file specifically, never a broad directory.
5. Retrieve an encrypted paste
pbputs adds GPG encryption on top. When the recovered data is encrypted, pbget calls gpg -d and either prompts for the pre-shared passphrase or reaches for the matching private key, depending on how the upload was made:
$ pbget 'https://paste.ubuntu.com/p/ENCRYPTED-EXAMPLE/' "$dest"
gpg: encrypted with 3072-bit RSA key, ID EXAMPLEKEY
Enter passphrase:
secrets/report.txt
INFO: Output is in [/tmp/tmp.a1b2C3d4]
Warning
Never put a passphrase in the URL, your shell history, a script, or a command substitution. If GPG complains about a missing key or a bad passphrase, stop and fix the key or the secret; retrying will not magically make an unrelated key fit. Treat the recovered plaintext as sensitive and remove it securely, per your organisation's retention policy, once you no longer need it.
6. Diagnose the common failures
- Empty result, an lzma error, or unexpected text. The URL almost certainly did not return the paste format this old script expects. Check the URL in a browser or a separate, trusted HTTP tool, then get hold of a fresh compatible paste. Do not pipe arbitrary web content into another decoder and call it recovered data.
- Permission error. The destination or its parent is not writable by your account. Pick a directory you actually own.
- Non-zero exit from tar. This can leave a partial extraction behind. Discard that destination and retry into a fresh, empty one after double-checking the URL.
Finished inspecting a temporary destination? Clean up exactly that directory, nothing wider:
$ find "$dest" -maxdepth 1 -mindepth 1 -print
$ rm -rf -- "$dest"
$ test ! -e "$dest" && echo 'recovery directory removed'
recovery directory removed
Warning
rm -rf is irreversible for whatever paths you give it. Check the expanded value of dest before you run it, and never let a broad path like / or $HOME sneak in there instead.
Done means
- You confirmed the installed pbget and pastebinit version before trusting its output.
- You used a quoted, complete paste URL rather than a fragment or an unquoted copy-paste.
- You extracted archives into a new, controlled directory instead of one you already cared about.
- You routed standard-input uploads through a temporary file before accepting them as final.
- You kept encryption passphrases out of commands and shell history.
- You inspected everything recovered before using it, and removed temporary data once it had served its purpose.