📜 ⬆️ ⬇️

Using 7zip for data backup

For the onset of complete and total happiness in terms of backups of information on the production server, I decided to abandon Acronis True Image in favor of the usual data archiving using 7-Zip.

To accomplish the task, I naturally used the console version of the archiver.


After a short smoking, the team took the following form:
')
7za.exe a -tzip -ssw -mx7 -r0 -x@exclusions.txt full_path_for_the_archive working_dir

In more detail about the used keys:

-tzip archive format is set to zip, without this key, the default format is 7z;

-ssw compulsory packaging of files that are currently open for writing (is it not enough that someone has stayed behind at work and something is ruled there);

-mx7 high compression ratio (7), you can put and 5 (normal compression), then the process will go faster;

-r0 (this is zero, not the letter O); exceptions that will be further written are processed only in the working directory;

-x@exclusions.txt is actually a file with a list of exceptions that we will not archive. Each line of the file is a new exception. You can use masks like * .ext, etc. If the exception is not a lot, then you can do without the file, in which case the key will look like the following: -x! *. Ext;

full_path_for_the_archive is the path and name of the new archive respectively;

working_dir is the folder to be packaged.

For convenience, you can use % date% in the archive name.

Due to the fact that you need to archive different folders into different archives, with volumes of 10-15 gigs, it is reasonable to use a sequence of commands in order not to create a bunch of rules in the scheduler and not think how long this whole process will take. Accordingly, for these purposes I use teaming with && . If you use & , then all commands will be executed simultaneously, which doesn’t suit me at all, with && - sequentially, with successful completion of the previous command.

In addition, it is desirable to have logs in order to be aware of whether something has happened. This can be easily implemented using the '>>' instruction, which saves the output to the console in a text file. However, the problem is that 7zip dumps into the console a lot of information, including about archiving each new file. Obviously, on volumes of several thousand files, all this info in the logs is needed like a dead poultice. Accordingly, it is required to exclude all unnecessary lines, leaving those where there is information about the name of the archive being created, the result of archiving and information about errors, if any appear.

This is where the FINDSTR team comes to the rescue . In my case, it takes the following form:

findstr / P / I / V "Compressing 7-Zip"

First a couple of words about the keys used:

/ P skips lines containing non-printable characters;

/ I just in case ignore case of letters;

/ V "" directly lists the words to search for in the lines and then exclude these lines.

As a result, at the output of this command we have 3 lines:

Scanning

Creating archive archive_name

Everything is ok

And then I roll everything into a text file for further study:

findstr / P / I / V "Compressing 7-Zip" >> log_file

Now it's up to you. You need to kick all three blocks into one sequence of commands:

7za.exe a -tzip -ssw -mx7 -r0 -x@exclusions.txt full_path_for_the_archive working_dir | findstr / P / I / V "Compressing 7-Zip" >> log_file.% date% .txt

Source: https://habr.com/ru/post/72636/


All Articles