
Using 7zip to backup data
For the onset of complete and total happiness in terms of backups of information on a production server, I decided to abandon Acronis True Image in favor of the usual data archiving using 7-Zip.
To accomplish this task, I naturally used the console version of the archiver.
After a short smoking of mans, the command took the following form:
7za.exe a -tzip -ssw -mx7 -r0 -x@exclusions.txt full_path_for_the_archive working_dir More
about the keys used:
-tzip the archive format is set to zip, without this key the default format is 7z;
-ssw forced packing of files that are currently open for writing (you never know if someone was sitting at work and something is correcting there);
-mx7high compression ratio (7), you can set 5 (normal compression), then the process will go faster;
-r0 (this is zero, not the letter O) exceptions that will be written further 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 such as * .ext, etc. If there is not much exception, then you can do without a file, in which case the key will take the following form: -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 added 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 so as 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 team combining using && . If you use & , then all the commands will be executed at the same time, which does not suit me at all, with && - sequentially upon successful completion of the previous command.
Among other things, it is desirable to have logs in order to be aware of whether something 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 a ton of information into the console, including about archiving every new file. Obviously, on volumes of several thousand files, all this info in the logs is needed as 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 archiving result and error information, if any appear.
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:
/ Pskips lines containing unprintable characters;
/ I just in case, ignore the case of letters;
/ V "" directly the list of words to search in the lines and then exclude these lines.
As a result, the output of this command has 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 small. You need to boot 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
To accomplish this task, I naturally used the console version of the archiver.
After a short smoking of mans, the command took the following form:
7za.exe a -tzip -ssw -mx7 -r0 -x@exclusions.txt full_path_for_the_archive working_dir More
about the keys used:
-tzip the archive format is set to zip, without this key the default format is 7z;
-ssw forced packing of files that are currently open for writing (you never know if someone was sitting at work and something is correcting there);
-mx7high compression ratio (7), you can set 5 (normal compression), then the process will go faster;
-r0 (this is zero, not the letter O) exceptions that will be written further 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 such as * .ext, etc. If there is not much exception, then you can do without a file, in which case the key will take the following form: -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 added 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 so as 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 team combining using && . If you use & , then all the commands will be executed at the same time, which does not suit me at all, with && - sequentially upon successful completion of the previous command.
Among other things, it is desirable to have logs in order to be aware of whether something 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 a ton of information into the console, including about archiving every new file. Obviously, on volumes of several thousand files, all this info in the logs is needed as 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 archiving result and error information, if any appear.
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:
/ Pskips lines containing unprintable characters;
/ I just in case, ignore the case of letters;
/ V "" directly the list of words to search in the lines and then exclude these lines.
As a result, the output of this command has 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 small. You need to boot 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