Non-interactive multivolume restore
George Mitchell
george+freebsd at m5p.com
Fri Feb 8 21:02:35 UTC 2019
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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20190208/e2b772ce/attachment.sig>
More information about the freebsd-hackers
mailing list