Get Appliance Info: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
Line 36: Line 36:


=== Single file extraction ===
=== Single file extraction ===
In order to extract a single from an archive we can use the <tt>tar -tvf filename.tar.gz</tt> command to display the file tree list present in the archive first to determine the exact path and file name of the target to extract.
Now to extract and display the file on the screen/console (the last character in the command below is a capital letter O) we use:
<source lang="bash">
tar -xzf archive1.tar.gz files/file1.txt -O
</source>
=== Multi Archive file extraction and cocatenation ===
If we know that the file name and path are in the exact place or follow a pattern, we can extract them into a single file for later manipulation.
<source lang="bash">
tar -xzf archive1.tar.gz files/file1.txt -O  > all_file1.txt
tar -xzf archive2.tar.gz files/file1.txt -O >> all_file1.txt
cat all_file1.txt
</source>
This will output:
<pre>
This is file 1 in archive 1
This is line 2 of file 1 in archive 1
This is file 1 in archive 2
This is line 2 of file 1 in archive 2
</pre>
== Extraction and Concatenation from DAB Templates ==

Revision as of 10:07, 3 November 2014

Introduction

All OpenVZ appliance templates created with Debian Appliance Builder will have the dab.conf file embedded in them as ./etc/appliance.info - the leading ./ is important as that is the way it has been archived.

A concatenation of all such appliance.info files separated by atleast 1 newline each along with Location and md5sum lines and removal of the Architecture, Installed-Size and Source lines is what essentially makes up the content of the /var/lib/pve-manager/apl-info/apl-available file (in PVE v1.x, the apl-info folder is not present and hence removed from the path listed here).

Linux file extraction from tar.gz archive

The following will serve as a tutorial on linux tar file creation and selective extraction and concatenation. If we were to use real templates which are big, they would take a long time to extract and concatenate and hence this dummy file set example.

Create some files

First we create a folder and place two files in it with different content:

mkdir files
cat << EOF > files/file1.txt
This is file 1 in archive 1
This is line 2 of file 1 in archive 1

EOF

sed -e 's/file 1/file 2/g' files/file1.txt > files/file2.txt

Archive the files

We now archive this folder with both it's files:

tar -czf archive1.tar.gz files

Create a second archive with different files

sed -e 's/archive 1/archive 2/g' -i files/file1.txt
sed -e 's/archive 1/archive 2/g' -i files/file2.txt
tar -czf archive2.tar.gz files

rm -rf files

Single file extraction

In order to extract a single from an archive we can use the tar -tvf filename.tar.gz command to display the file tree list present in the archive first to determine the exact path and file name of the target to extract.

Now to extract and display the file on the screen/console (the last character in the command below is a capital letter O) we use:

tar -xzf archive1.tar.gz files/file1.txt -O

Multi Archive file extraction and cocatenation

If we know that the file name and path are in the exact place or follow a pattern, we can extract them into a single file for later manipulation.

tar -xzf archive1.tar.gz files/file1.txt -O  > all_file1.txt
tar -xzf archive2.tar.gz files/file1.txt -O >> all_file1.txt
cat all_file1.txt

This will output:

This is file 1 in archive 1
This is line 2 of file 1 in archive 1

This is file 1 in archive 2
This is line 2 of file 1 in archive 2

Extraction and Concatenation from DAB Templates