borg backup extract last archive command 2025
This refinement focuses on extracting the last created archive using Borg, includes the term 'backup' for clarity, and adds the current year for relevance in search results.
To extract the most recently created archive using Borg, you can utilize the borg extract command along with the --last option. This option simplifies the process by directly targeting the latest archive in your backup repository. Below is a detailed explanation, including the command structure and relevant background information.
First, let's break down the commands you've provided for context:
Creating an Archive:
borg create --progress /path/to/your/repository::archive-name-$(date +%Y-%m-%d_%H-%M-%S) /path/to/files/to/backup
This command creates a backup archive with a timestamp in its name, indicating when it was created.
Pruning Archives:
borg prune --prefix 'archive-name-' --keep-last 3 /path/to/your/repository
This command removes older archives, keeping only the last three archives that match the specified prefix.
To extract the last archive created, you can use the following command:
borg extract --last /path/to/your/repository
borg extract: This is the primary command used for extracting archived data.--last: This flag tells Borg to extract the most recently created archive./path/to/your/repository: Replace this with the actual path to your Borg repository where the archives are stored.If you wish to extract a specific archive (if you want to avoid the '--last' option), you can list the archives first to get their names using:
borg list /path/to/your/repository
This will give you a list of all archives, and you can identify the one you need based on its name (which includes the creation date).
Putting it all together, if you want to extract the most recent backup, you'd perform the commands as shown below:
# List all archives to confirm the latest one if needed
borg list /path/to/your/repository
# Extract the latest archive
borg extract --last /path/to/your/repository
Using the borg extract --last command is an efficient way to restore data from your latest backup without needing to specify the archive name manually. This command is designed to streamline the extraction process, particularly useful if you regularly create multiple archives. For further details and options, you can refer to the official Borg documentation on Borg Backup Documentation.