borg extract archives with prefix from repository path examples
This refinement focuses on extracting archives with a specific prefix from a Borg repository, making it clearer and more targeted for relevant documentation or examples related to Borg and prefix extraction.
To extract files from a Borg repository while ensuring you're targeting only those archives that match a specific prefix, you can modify your command using the borg list options and command substitution to filter archives accordingly. Below, I’ll outline how to structure this command effectively.
BorgBackup allows for efficient extraction of files from compressed and deduplicated archives. By leveraging command substitution alongside pattern matching, you can focus your extractions on archives that start with a particular prefix.
The base command you provided is meant to extract specific files from the most recent archive:
borg extract /path/to/repo::$(borg list /path/to/repo --last 1 --format '{archive}') path/to/file1 path/to/file2
This command retrieves the last archive and extracts file1 and file2 from it. To filter archives by a specific prefix, you can adjust your approach as follows:
To extract files only from archives that start with a certain prefix, you can use borg list to filter based on that prefix. Here is the modified command that accomplishes this:
borg extract /path/to/repo::$(borg list /path/to/repo --format '{archive}' | grep '^prefix-') path/to/file1 path/to/file2
borg list /path/to/repo --format '{archive}': This lists all archives in the repository.grep '^prefix-': This filters the list to include only those archives whose names start with prefix-. Replace prefix- with your actual prefix.borg extract /path/to/repo::$(...): This part remains unchanged and continues to extract files from the filtered list of archives.Let’s say you want to extract files from archives that start with the prefix backup-. Your command would look like this:
borg extract /path/to/repo::$(borg list /path/to/repo --format '{archive}' | grep '^backup-') path/to/file1 path/to/file2
Multiple Archives Handling: If multiple archives match the prefix, the command will attempt to extract the files from all matching archives, which might create conflicts. Consider specifying whether you want to extract from only the latest of those archives or all.
Extracting All Files: If you want to extract all files from the matched archives rather than specific files, you could remove path/to/file1 path/to/file2 altogether.
Command-Line Environment: Ensure that you have the appropriate permissions and that your command-line environment supports the necessary utilities such as grep.
For further reading, you can refer to the official Borg documentation on extracting archives which covers various options and configurations.
This efficient command structure allows you to harness the power of BorgBackup for targeted extractions based on archive naming conventions. Adjust the prefix as necessary for your use case to streamline the backup restoration process.