Flexible backup with console command RAR

  
WinRAR provides a simple but highly efficient compression console command RAR. In-depth understanding and application of this little-known feature, you can flexibly create complex compressed backup solutions. Everyone uses WinRAR backup files. The usual practice is to right click on one or more files or folders for compression or decompression. However, if you encounter a situation where you want to process multiple compression tasks at once, the graphical interface can be complicated or difficult to implement. Fortunately, WinRAR compression software provides a console command program, which we can use to flexibly create complex backup solutions. Case: Creating a One-Click Multitasking Backup Task Description I have several folders placed in different partitions: “D:\\Working Documents”“E:\\e-book”“F:\\Beautiful Wallpapers”&ldquo ;F:\\Selected Music", these folders contain some personal information or downloaded boutique content, and you need to compress the backup to the mobile hard disk at regular intervals to prevent loss. Recently, according to actual needs, I plan to back up all DOC documents under the folder “D:\\Working Documents”, all PDF e-books under the “E:\\E-books” folder, “F:\\ All the pictures under the beautiful wallpaper & rdquo; folder and all the MP3 files under the folder "F:\\Selected Music". If you follow the usual practice, I need to select folders for compression in different partitions, and then copy the generated RAR archives one by one to the backup directory of the mobile hard disk, but this is obviously more troublesome. So, is there a more efficient, more flexible and convenient solution that can accomplish this task, and can easily perform backup tasks in the future? Implementation Ideas With the help of WinRAR's compression console command RAR, you only need to edit the list list TXT file of a backup task, and then use a backup console command RAR to call this manifest file, which can realize an automatic backup of batch tasks, and the task Addition, deletion, modification and maintenance are also extremely simple, just use Notepad to modify the TXT list file. Tip: Console RAR command line description: RAR < command > [ -<switch > ] <compressed file> [ <@list file...>][ <file...> ; ] [ <Decompression Path\\>] The most critical and flexible of these is the command line options (commands and switches), which provide a rich control method for creating and managing compressed files using RAR. The command is a string (or a single letter) that commands the RAR to perform a corresponding operation. The switch is used to change the way the RAR performs the operation. Other parameters are the compressed file name and the compressed file or the file to be uncompressed from the compressed file. A list file is a plain text file that includes the name of the file being processed. The first column should start with the file name. You can add comments after the //character. Basic plan construction 1. Prepare the compression console First, I need to use a compressed console command program RAR.EXE, which is located in the WinRAR installation directory (usually under the C:\\Program Files\\WinRAR folder). Copy the program to the target backup folder (such as a folder on the mobile hard disk or a folder in the hard disk data backup partition); you can also choose not to copy the file, but you need to add the file to the system's path search environment. In the variable (described later). 2. Constructing a backup list Next, use Notepad to edit a list file backup.lst (//followed by a character that can be omitted) (Figure 1), which contains the following four lines of strings. In the folder where the files you want to back up are located. D:\\Working Documents\\*.DOC //Back up only DOC documents E:\\E-books\\*.PDF //Back up only PDF files F:\\Beautiful wallpapers\\*.* //Back up all files F:\\Select music \\*.MP3 //Back up only MP3 files. Note that when saving the file, select the file type as “All files (*.*)”, and the file name is set to backup.lst to save the file correctly (Figure 2). Or use the traditional method to save the file as backup.txt, then unhide the file extension in the "folder options", and then change the file extension to lst. 3. Construct the batch file Finally, in the disk folder where the backup file is stored, use Notepad to create a batch file Backup.bat text file of the following content (Figure 3). Path c:\\program files\\winrar;%path%rar a -r My-backup.rar @backup.lst The batch content is only the above two lines, the following specific explanation. Because we want to call the compression console program RAR.exe, we need to find the program in the system environment path, so we need to use the path c:\\program files\\winrar;%path% command in the command prompt window to add the system. Search path. In this command, the path c:\\program files\\winrar before the semicolon indicates that a new path is added, and the %path% after the semicolon indicates that the original system path is added. If the RAR.EXE program has been copied into the target directory, the line command can be omitted. The second command rar a -r My-backup.rar @backup.lst is the core command to execute the bulk compression task, where the parameter a means to add files to the compressed file, and the -r option switch means together with the subdirectories of each level. Scan processing compression, @backup.lst refers to compressing one by one according to the folder specified in the backup.lst list. Performing a one-click backup After the above operation, we created two files in the backup target directory, one list file backup.lst, and one batch file Backup.bat. When you need to back up, just double-click the batch file Backup.bat to get a compressed backup file My-backup.rar in the target folder to complete the backup task (Figure 4). It contains all the backup files we need. Program change method My work task or collection folder cannot be fixed. It is very likely that I will increase or decrease the project or change some items in the future. So, when the project that needs to be backed up changes, is the change of the compression scheme troublesome? Still need to rebuild the program? Don't worry, it's very simple! 1. Remove backup items If there are items in your compression plan that need to be reduced, for example, you need to cancel the backup of the “F:\\Selected Music” folder, then you just need to open the Backup.lst file with Notepad. , delete “F:\\Select Music\\*.MP3” and save the file. 2. Add a new backup If you have added a backup project, such as many tables and databases need to be backed up in the “G:\\MyDOC\\Excel” folder, just add in the Backup.lst file. One line <; G: \\ MyDOC \\ Excel \\ *. * & rdquo; 3. Modify the backup project In addition to the above, any changes to the backup project can be opened at any time with Notepad to open the Backup.lst file. In this way, the project changes become a simple editing of a text file. The execution method of the backup project will never change. Always execute the batch file Backup.bat directly. This file does not need to be changed. The above is an example of a comprehensive backup. In fact, the use of the compressed console program RAR is very flexible, we can use it to achieve a variety of compression tasks by changing parameters and options. Let's take a look at a flexible implementation of a compressed case with subdirectories. Case: Does the compression task description of a subdirectory assume that all the files in the Bitmaps folder are compressed into the Pictures.rar file. How do you use the compression console command described above to specify whether to include or not include subfolders at all levels? The implementation process achieves the desired goal by flexibly coordinating the use of parameters, switches, paths, and wildcards. Specific to this problem: the following command will add all the files in the Bitmaps directory and its subdirectories to the RAR compressed file Pictures.rar (Figure 5): rar a -r Pictures.rar Bitmaps\\* because if the directory contains files The mask or the end of the backslash will apply the normal rule. In the normal rule, the subdirectory is not processed by default. If you want to process it together with its subdirectory, you need to specify the -r switch. The following command will add all files except the subdirectory in the Bitmaps directory, because the switch -r (Figure 6) is not specified: rar a Pictures.rar Bitmaps\\* However, as a special exception, if the directory name Bitmaps is used as a parameter Specifies and does not include a file mask and ends with a backslash, and all contents of the directory and subdirectories are added to the compressed file even if the -r switch is not specified. Specifically use the following command to achieve (Figure 7): rar a Pictures.rar Bitmaps tips: If you want to understand the detailed parameters and options for the compression console program RAR, you can execute the RAR /? command in the command prompt window . If you want to record the obtained commands, you can use the RAR /? >RAR-hlp.txt command to save the display list in the RAR-hlp.txt file (Figure 8). This article comes from [System Home] www.xp85.com
Copyright © Windows knowledge All Rights Reserved