Page 1 of 1

Extract individual files from archive

Posted: Sun Jul 14, 2013 2:04 am
by Berix

I've written a quick modification to fsarchiver 0.6.19 that will allow you to extract individual file(s) from an archive. I realize this feature may be planned for a future release, but we needed this ability for one of our client's systems in order to move forward with their backup procedure.

The download and installation instructions are below.


USE THIS AT YOUR OWN RISK. Please test this on a non-production system before you rely on it. I have done only very light testing with this change, and it works for my purposes. I don't know what kind of problems can occur in more complicated use cases. For instance, I am not entirely sure if this will work to extract files from one filesystem type to another type (reiserfs archive -> ext4 filesystem).

Also, I realize this may not be the most elegant solution, but for my purposes, it will work just fine. I thought someone else may find this a handy addition, so here we go.

How it works

Basically we follow the same code path as if we were restoring an archive to a filesystem, but we skip certain parts, such as creation of the filesystem, mounting, etc. As we iterate through all of the files in the archive, we examine the path of each one to see if you specified that it should be extracted (using the -E option). If it was, then it will be extracted. Otherwise, the file/directory will be skipped.


Using fsarchiver with this code addition, there will be a new 'extract' command, as well as a new '-E' option for specifying files and/or directories to extract. The -E option can be specified multiple times to allow multiple files/directories to be extracted, similar to the behavior of the -e exclude option.

Example #1

Code: Select all

# fsarchiver extract /home/testing/myarchive1.fsa id=0 -E /file1.txt
This command will attempt to extract a file called "/file1.txt" from filesystem number 0 in archive "myarchive1.fsa".

Note that dest= is not specified/required. When using 'extract' mode, we are extracting to the current working directory, so be sure you're sitting in the directory you want to extract to.

Example #2

Code: Select all

# fsarchiver extract /home/testing/myarchive2.fsa id=0 -E /dir1/ -E /dir2/
This example will attempt to extract directories /dir1/ and /dir2/ to the current working directory. In order to specify a directory, the path must contain the trailing slash, otherwise it will think you're specifying a single file.
When you specify a directory path like this, fsarchiver will extract all of the files/directories underneath that directory, recursively.


Unified format patch file:


First, be sure you have the fsarchiver source downloaded and extracted somewhere on your system. Then, 'cd' into the newly extracted directory.

Code: Select all

# tar xzf fsarchiver-0.6.19.tar.gz
# cd fsarchiver-0.6.19
Next, download the patch file listed above, using wget if it's available.

Code: Select all

# wget
Then, we apply the patch to the extracted source:

Code: Select all

# patch -p1 < fsa-extract-0.3.patch
If successful, you should see something similar to this:

Code: Select all

patching file src/fsarchiver.c
patching file src/fsarchiver.h
patching file src/oper_restore.c
patching file src/options.c
patching file src/options.h
Now you can continue compiling/running fsarchiver according to the bundled installation instructions (see INSTALL)


I hope this works as well for you as it will for me. Hopefully someday fsarchiver will come with a feature that allows you better access than mine.


*EDIT 1*: Uploaded new version of the patch. Cleaned up the code a bit, reduced size of diff, less original program lines changed.
*EDIT 2*: New version of the patch. Added handling of errors so that skipped files don't get reported as errors. Also works with fsarchiver 0.6.19

Re: Extract individual files from archive

Posted: Sun Jul 14, 2013 4:43 am
by Lazy_Kent
Thanks for contribution!
Haven't tested yet myself. I've forwarded your message to SystemRescueCd forum: ... =23&t=5132