dockersetup: support importing gzip compressed database dumps

Database dumps are simply SQL (i.e. plain text) so they tend to be
both large and easy to compress, so having them gzipped is something
worth supporting.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-01-10 14:24:11 +13:00
parent 841124a662
commit 24dcd4618a

View File

@ -519,9 +519,14 @@ if not updatemode:
# Import the user's supplied data
if dbfile:
return_code = subprocess.call("gunzip -t %s > /dev/null 2>&1" % dbfile, shell=True)
if return_code == 0:
catcmd = 'zcat'
else:
catcmd = 'cat'
env = os.environ.copy()
env['MYSQL_PWD'] = dbapassword
return_code = subprocess.call("docker exec -i -e MYSQL_PWD layersdb mysql -uroot layersdb < " + dbfile, shell=True, env=env)
return_code = subprocess.call("%s %s | docker exec -i -e MYSQL_PWD layersdb mysql -uroot layersdb" % (catcmd, dbfile), shell=True, env=env)
if return_code != 0:
print("Database import failed")
sys.exit(1)