Get the App
SLTechnology News&Howtos  ›  Servers  › 

Perform backups using 7zip through batch files; back up the 1st and 15th backups separately; clean up expired backups regularly

Shulou Source: shulou.com Published: 2022-06-02 09:09:13 09月29日 Update

7z.exe is a good thing. Many years ago, I tried all kinds of command-line compression software, but the effect was not good. Not long after 7zip came out, I found that it also had command-line mode. Then I found that the usability was very good, and the compression ratio and efficiency were also very good. At that time, I tried winrar and rar, and the results were not very good.

C:\ 7-Zip\ 7z.exe a-sdel "E:\ Backup\ Zip_%date:~0,4%_%date:~5,2%_%date:~8,2%.7z"E:\ Backup\% date:~0,4%_%date:~5,2%_%date:~8,2%.dmp"E:\ Backup\% date:~0,4%_%date:~5,2%_%date:~8,2%.log" for / F "delims="% I in ('wmic path Win32_LocalTime get day / delims= ^ | find "=" ') do set / a% iif% day%==2 (copy E:\ Backup\ Zip_%date:~0,4%_%date:~5,2%_01.7z E:\ Backup_1stDayOfMonth\) if% day%==16 (copy E:\ Backup\ Zip_%date:~0,4%_%date:~5,2%_15.7z E:\ Backup_1stDayOfMonth\) forfiles / p "E:\ Backup\" / m * .7z-d-30 / c "cmd / c del / f @ path"

Friends who are familiar with Oracle should be able to see that this is Oracle's dump and log file compression. Expdp export dump is very convenient, the disadvantage is that this thing is super large, after using 7zip compression, the capacity can be reduced to about 5%.

You can take a look at the parameters of 7z for yourself. Here are two parameters used in my command line.

A: compression

-sdel: delete the source file after the compression is completed. For dump such a large file, delete after backup, this parameter is very useful.

First path: compressed file name with path

The second and third paths: two file names that need to be compressed. If there is a fourth, fifth, and so on, you can continue to write.

% date:~0,4%%date:~5,2%%date:~8,2% is the date under the command line, and I underlined it in the middle of the year, 2018-01-01.

The second paragraph reads the system date and determines that if the date is 2, the backup of 1 day will be copied to another directory for long-term storage.

In the third paragraph, clean up the expired files in the backup directory.-d represents days, and-30 represents 30 days ago.

Tags: File command backup parameter date path two representative effect file name directory good practical not good three underlined not much availability years capacity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi NVidia Redmi Shulou Technology