#!/usr/bin/perl -T use warnings; use strict; =head1 NAME borg-restore.pl - Restore paths from borg backups =head1 DESCRIPTION borg-restore.pl helps to restore files from borg backups. It takes one path, looks for its backups, shows a list of distinct versions and allows to select one to be restored. Versions are based on the modification time of the file. It is also possible to specify a time for automatic selection of the backup that has to be restored. If a time is specified, the script will automatically select the newest backup that is at least as old as the time value that is passed and restore it without further user interaction. B has to be executed regularly, ideally after creating or removing backups. =cut =head1 OPTIONS =over 4 =item B<--help>, B<-h> Show help message. =item B<--debug> Enable debug messages. =item B<--update-cache>, B<-u> Update the lookup database. You should run this after creating or removing a backup. =item B<--destination=>I, B<-d >I Restore the backup to 'path' instead of its original location. The destination either has to be a directory or missing in which case it will be created. The backup will then be restored into the directory with its original file or directory name. =item B<--time=>I, B<-t >I Automatically find the newest backup that is at least as old as I specifies. I is a string of the form ">>" with I being one of the following: s (seconds), min (minutes), h (hours), d (days), m (months = 31 days), y (year). Example: 5.5d =back =head1 CONFIGURATION borg-restore.pl searches for configuration files in the following locations in order. The first file found will be used, any later ones are ignored. If no files are found, defaults are used. =over =item * $XDG_CONFIG_HOME/borg-restore.cfg =item * /etc/borg-restore.cfg =back =head2 Configuration Options You can set the following options in the config file. Note that the configuration file is parsed as a perl script. Thus you can also use any features available in perl itself. =over =item C<$cache_path_base> This defaults to "C<$XDG_CACHE_HOME>/borg-restore.pl". It contains the lookup database. =item C<@backup_prefixes> This is an array of prefixes that need to be added when looking up a file in the backup archives. If you use filesystem snapshots and the snapshot for /home is located at /mnt/snapshots/home, you have to add the following: # In the backup archives, /home has the path /mnt/snapshots/home {regex => "^/home/", replacement => "mnt/snapshots/home/"}, The regex must always include the leading slash and it is suggested to include a tailing slash as well to prevent clashes with directories that start with the same string. The first regex that matches for a given file is used. This setting only affects lookups, it does not affect the creation of the database with --update-database. =back =head2 Example Configuration $cache_path_base = "/mnt/somewhere/borg-restore.pl-cache"; @backup_prefixes = ( {regex => "^/home/", replacement => "mnt/snapshots/home/"}, # /boot is not snapshotted {regex => "^/boot", replacement => ""}, {regex => "^/", replacement => "mnt/snapshots/root/"}, ); =head1 SYNOPSIS borg-restore.pl [options] Options: --help, -h short help message --debug show debug messages --update-cache, -u update cache files --destination, -d Restore backup to directory --time, -t Automatically find newest backup that is at least