borg backup extract last archive command keep last 3 archives
Focused on the specific action of extracting the last archive from a Borg backup and included relevant keywords to improve the precision of the search results.
To extract the last archive created by your borg create command, which maintains the last three archives due to the borg prune command, you can follow these steps. The borg extract command allows you to specify the exact archive you want to restore.
Identify the Archive Name: Since you used a dynamic naming system based on the date and time of creation (e.g., archive-name-YYYY-MM-DD_HH-MM-SS), you'll need to locate the latest archive in your repository.
Extract the Latest Archive: You can accomplish this by leveraging the borg list command to find the name of the most recent archive and then use borg extract to extract its contents.
List the Archives: First, you should list the archives in your repository to identify the most recent one.
borg list /path/to/your/repository
This will output a list of your archives. Look for the one with the most recent timestamp.
Extract the Most Recent Archive: Once you've identified the latest archive, you can extract it using the following command:
borg extract /path/to/your/repository::archive-name-2025-10-01_11-20-30
Replace archive-name-2025-10-01_11-20-30 with the actual name of the latest archive you found in the previous step.
If you wish to automate the extraction process to avoid manually checking the list, you can use a command to extract the last archive directly:
borg extract /path/to/your/repository::$(borg list /path/to/your/repository | tail -n 1)
This command utilizes borg list and pipes the output to tail to grab the last entry, which corresponds to the latest archive based on your pruning strategy.
To summarize, you can find and extract the most recent Borg archive using the borg list and borg extract commands. The automation option allows for a seamless extraction process without having to manually verify the latest archive name. Make sure to adjust the paths as per your configuration and always refer to the Borg documentation for any additional options or considerations.