Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change gunzip temporary directory while used in pipe

Background

I'm working on an mysql server with those hdd partitions:

...
/dev/vdd       99G     58G   39G   61% /var/lib/mysql
tmpfs         2,4G       0  2,4G    0% /tmp
...

I need to import a mysql dump into my database. Therefore I use the following syntax:

gunzip -c sql_dump.sql.gz | mysql -uDB_USER -p DB_NAME

In general this works but my sql_dump.sql.gz file will be over 5GB when extracted.

The command above will fail with gzip: /home/.../sql_dump.sql.gz: No space left on device. I think this is not related to the mysql partiton which has enough space, but the /tmp partition which does only have 2.4GB free.

For now I did go ahead an moved the file to the /var/lib/mysql parition which has enough free space. gunzip my file there, start the mysql import and removed the compressed and uncompressed files afterward.

Question

I was asking myself if there is any way I can force gunzip to temporary change the default temporary target location, which is /tmp/ by default. So that gunzip -c sql_dump.sql.gz | ... does not store the extracted file under /tmp/ but under /var/lib/mysql while extracting the file. Something like this:

export "GZIP_TMP_DIR=/var/lib/mysql/"
gunzip -c sql_dump.sql.gz | mysql -uDB_USER -p DB_NAME

Is this even possbile ? I searched a lot but could not find anything that would solve this specific need.

like image 281
cb0 Avatar asked Mar 13 '23 00:03

cb0


1 Answers

Set the desired temporary directory in environment variable TMPDIR (see https://en.wikipedia.org/wiki/TMPDIR).

like image 54
Krzysztof Krasoń Avatar answered Mar 16 '23 06:03

Krzysztof Krasoń