Recover Pastebinit Files with pbget Without Losing Track of Them
You will finish with a repeatable way to retrieve data uploaded by pbput or pbputs, recognise whether it is printed or extracted, and keep archive contents in a directory you chose. The examples match the installed pastebinit package, version 1.6.2-1, and its pbget(1) manpage.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes, plus the time needed to obtain a real paste URL. You need a shell, the pastebinit package, a URL produced by a compatible uploader, and write access to the destination directory if you choose one. The commands here do not need elevated privileges. Do not use sudo to compensate for a bad destination choice: it can turn an untrusted archive into a root-owned file-writing operation.
1. Check the installed command
First confirm which executable and package version you are using. This is read-only:
$ command -v pbget
/usr/bin/pbget
$ dpkg-query -W -f='${Package} ${Version}\n' pastebinit
pastebinit 1.6.2-1
The command is a name-specific link to the package's pbput script. Its interface is deliberately small:
pbget URL [DIRECTORY]
URL is mandatory. The optional DIRECTORY matters only when the retrieved data is a tar archive. There are no useful --help or output-format switches in this installed implementation, so do not add flags from a different downloader.
Checkpoint
If command -v returns nothing, stop and install the package through your normal system change process. Installation is outside this recovery workflow.
2. Prepare a controlled destination
For an uploaded file or directory, use a new, private directory. Creating it changes local state, but the operation is reversible: remove the directory after checking its contents if you no longer need it.
$ dest="$(mktemp -d)"
$ printf 'destination: %s\n' "$dest"
destination: /tmp/tmp.a1b2C3d4
The final name is generated by mktemp and will differ on your machine. Do not point pbget at /, your home directory, or a directory containing important files. The script invokes tar -C DIRECTORY -xvf for archives, so extraction can create or replace paths in the destination according to the archive contents.
Use a persistent directory instead when the recovered files must survive a reboot:
$ dest="$PWD/pbget-recovery"
$ mkdir -- "$dest"
$ test -w "$dest" && echo "writable: $dest"
writable: /path/to/pbget-recovery
If mkdir reports that the directory already exists, do not blindly reuse it. Inspect it, choose an empty directory, or remove only a directory you have confirmed is disposable.
3. Retrieve an uploaded file or directory
Replace the example URL with the complete URL supplied by the uploader. Quote it so shell characters in a copied URL cannot change the command.
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' "$dest"
docs/notes.txt
docs/config.ini
INFO: Output is in [/tmp/tmp.a1b2C3d4]
The exact URL and file names are examples of shape, not a live paste. For an archive, the installed script prints each path as tar extracts it and then reports the destination. A successful-looking path list is not a trust decision: inspect the files before opening or executing them.
Checkpoint
Verify what arrived rather than relying on the paste's description:
$ 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 read from standard input. In that case pbget decodes and decompresses the paste, then writes the original content to standard output. Leave out the destination argument:
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' > recovered.txt
$ wc -c recovered.txt
128 recovered.txt
The redirection is performed by your shell, not by pbget. If the URL is wrong or the paste is not in the format this script expects, you may create an empty or incomplete output file. Use a temporary output path and inspect it before replacing an existing file:
$ tmp_out="$(mktemp)"
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' > "$tmp_out"
$ file "$tmp_out"
$ mv -- "$tmp_out" recovered.txt
The final mv is only appropriate after checking the temporary file. To recover from a failed attempt, delete the temporary file, not a broad directory.
5. Retrieve an encrypted paste
pbputs adds GPG encryption. When the recovered data is encrypted, pbget calls gpg -d and prompts for the pre-shared passphrase or uses 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]
Do not put a passphrase in the URL, shell history, a script, or a command substitution. If GPG reports a missing key or a bad passphrase, stop and fix the key or secret; retrying does not make an unrelated key suitable. Treat the recovered plaintext as sensitive, and remove it securely according to your organisation's retention policy when it is no longer needed.
6. Diagnose the common failures
An empty result, an lzma error, or unexpected text usually means the URL did not return the paste format this old script expects. Check the URL in a browser or with a separate, trusted HTTP diagnostic, then obtain a fresh compatible paste. Do not pipe arbitrary web content into another decoder and call it recovered data.
A permission error means the selected destination or its parent is not writable by your account. Choose a directory you own. A non-zero exit status from tar can leave a partial extraction, so discard that destination and retry in a new empty directory after checking the URL.
If you used a temporary destination and have finished inspecting it, clean up exactly that directory:
$ 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 the selected paths. Check the expanded value of dest before running it, and never substitute a broad path such as / or $HOME.
Done means
- You confirmed the installed
pbgetand pastebinit version. - You used a quoted, complete paste URL.
- You extracted archives into a new controlled directory.
- You redirected standard-input uploads to a temporary file before accepting them.
- You kept encryption passphrases out of commands and shell history.
- You inspected recovered files before using them and removed temporary data when appropriate.