Skip to content

Commit

Permalink
Add --latest command line option to mount command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Sep 23, 2019
1 parent 8b0ffea commit 46efae2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
4 changes: 4 additions & 0 deletions doc/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ Or you can mount the files that existed on a particular date using::

emborg mount --date 2015-04-01 backups

Or you can mount the latest available archive::

emborg mount --latest backups

You will need to un-mount the repository or archive when you are done with it.
To do so, use the *umount* command.

Expand Down
1 change: 1 addition & 0 deletions doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Releases
this version).
- Added *prefix*, *exclude_from*, and *verbose* settings.
- Provide defaults for *archive* setting.
- Add --latest command line option to *mount* command.

**1.4 (2019-04-24)**:
- Added *ssh_command* setting
Expand Down
53 changes: 29 additions & 24 deletions emborg/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,24 @@ def get_available_archives(settings):
except json.decoder.JSONDecodeError as e:
raise Error('Could not decode output of Borg list command.', codicil=e)

def get_nearest_archive(settings, date):
# get_name_of_latest_archive() {{{2
def get_name_of_latest_archive(settings):
archives = get_available_archives(settings)
if not archives:
raise Error('no archives are available.')
if archives:
return archives[-1]['name']

def get_name_of_nearest_archive(settings, date):
archives = get_available_archives(settings)
try:
date = arrow.get(date)
except arrow.parser.ParserError:
raise Error('invalid date specification.', culprit=date)
for archive in archives:
if arrow.get(archive['time']) >= date:
return archive['archive']
return None
return archive['name']
raise Error('archive not available.', culprit=date)

# get_available_files() {{{2
def get_available_files(settings, archive):
Expand Down Expand Up @@ -505,8 +513,8 @@ class ExtractCommand(Command):
emborg [options] extract <path>...
Options:
-d <date>, --date <date> date of the desired version of paths
-a <archive>, --archive <archive> name of the archive to use
-d <date>, --date <date> date of the desired version of paths
You extract a file or directory using:
Expand Down Expand Up @@ -563,14 +571,9 @@ def run(cls, command, args, settings, options):

# get the desired archive
if date and not archive:
archive = get_nearest_archive(settings, date)
if not archive:
raise Error('archive not available.', culprit=date)
archive = get_name_of_nearest_archive(settings, date)
if not archive:
archives = get_available_archives(settings)
if not archives:
raise Error('no archives are available.')
archive = archives[-1]['name']
archive = get_name_of_latest_archive(settings)
output('Archive:', archive)

# run borg
Expand Down Expand Up @@ -736,8 +739,8 @@ class ManifestCommand(Command):
emborg [options] la
Options:
-d <date>, --date <date> date of the desired version of paths
-a <archive>, --archive <archive> name of the archive to use
-d <date>, --date <date> date of the desired archive
-n, --name output only the filename
Once a backup has been performed, you can list the files available in
Expand Down Expand Up @@ -769,14 +772,9 @@ def run(cls, command, args, settings, options):

# get the desired archive
if date and not archive:
archive = get_nearest_archive(settings, date)
if not archive:
raise Error('archive not available.', culprit=date)
archive = get_name_of_nearest_archive(settings, date)
if not archive:
archives = get_available_archives(settings)
if not archives:
raise Error('no archives are available.')
archive = archives[-1]['name']
archive = get_name_of_latest_archive(settings)
output('Archive:', archive)

# run borg
Expand All @@ -800,8 +798,9 @@ class MountCommand(Command):
emborg [options] mount <mount_point>
Options:
-d <date>, --date <date> date of the desired version of paths
-a <archive>, --archive <archive> name of the archive to use
-d <date>, --date <date> date of the desired version of paths
-l, --latest mount latest available archive
You can mount a repository or archive using:
Expand All @@ -813,6 +812,10 @@ class MountCommand(Command):
If you do not specify an archive or date, all archives are mounted.
You can mount the latest archive using:
emborg mount --latest backups
You can mount an archive that existed on a particular date using:
emborg mount --date 2015-04-01 backups
Expand All @@ -832,12 +835,14 @@ def run(cls, command, args, settings, options):
mount_point = cmdline['<mount_point>']
archive = cmdline['--archive']
date = cmdline['--date']
latest = cmdline['--latest']

# get the desired archive
if date and not archive:
archive = get_nearest_archive(settings, date)
if not archive:
raise Error('archive not available.', culprit=date)
if not archive:
if date:
archive = get_name_of_nearest_archive(settings, date)
elif latest:
archive = get_name_of_latest_archive(settings)

# create mount point if it does not exist
try:
Expand Down

0 comments on commit 46efae2

Please sign in to comment.