[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: Non-interactive multivolume restore
From:       George Mitchell <george+freebsd () m5p ! com>
Date:       2019-02-08 21:01:58
Message-ID: 1f2f42bb-adf9-db72-25ba-b8a7a89e5b32 () m5p ! com
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Apparently people don't often have to restore multivolume dumps.  (I
rarely do it myself except that I'm in the middle of compiling an index
of a plethora of ancient dumps before purging them.)  Since it requires
a lot of interaction (as least as far as I have been able to determine),
I've writtien this silly python program to help out.  It relies on
misc/py-pexpect, which happily compiles in a py36 version that doesn't
run, so this program specifies python2.7:
---------------------------------------------------------------------
#!/usr/bin/env python2.7

from __future__ import print_function
import pexpect
import sys
import os

if len(sys.argv )< 2 or (len(sys.argv) == 2 and sys.argv[1] == '-h'):
    print('''
Non-interactively restore from a multivolume dump.  You can use a
glob to specify the dump volume if the glob expands to the files in
the correct order.  Creates symbolic links to your dumps in $TMPDIR
(or /tmp by default) and runs 'restore' with the -P option.  Generates
responses as needed to keep the restore program running.
''')
    print('You did not specify any dump volumes.')
    sys.exit(1)

tmpdir = os.getenv('TMPDIR') or '/tmp'
for i, volume in enumerate(sys.argv[1:]):
    try:
        os.remove(tmpdir + '/dumpvolume' + str(i + 1))
    except:
        pass
    os.symlink(sys.argv[i + 1], tmpdir + '/dumpvolume' + str(i + 1))
child = pexpect.spawn("/sbin/restore -x -P 'cat " + tmpdir +
                      "/dumpvolume$RESTORE_VOLUME'")
child.logfile = sys.stdout
while True:
    resp = child.expect(['Specify next volume #: ', 'default: ',
                         "set owner/mode for '.'. .yn. ", pexpect.EOF],
                        timeout=600)
    if resp == 0:
        child.sendline('1')
    elif resp == 1:
        child.sendline('')
    elif resp == 2:
        child.sendline('y')
    else:
        break

for i in len(sys.argv[1:]):
    os.delete(tmpdir + '/dumpvolume' + str(i + 1))


["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic