On one server it was necessary to configure a backup. On Linux everything is done via cron, and on Windows using Task Scheduler. So the task is to add a folder to a rar or zip archive via a bat file (batch file). It is also possible with using cmd carry out as you please. I decided to write a simple bat to call winrar, add a folder to the archive and place it in the desired location. Then I execute this script in the scheduler at a given interval.

How to create a bat file and archive a folder in rar

First I want to say that add folder to archive You can use absolutely any extension - rar, zip and others supported by WinRAR. And now point by point:

1) open any notepad (notepad++ is best);
2) write the command there: start WinRAR A "D:\kudaarhiv.rar" "D:\Program Files\bdseoru"
3) save as *.bat (for example, v_archive.bat).

How to archive rar folder using bat

Let me clarify:
1 - launch winrar. Team start launches any program. If it doesn’t work, write the full path to the .exe file.
2 - team A adds files to the archive. Read the guide from winrar itself for more details.
3 - where we archive the folder and files. Please indicate full path, archive name and extension.
4 - which folder we archive. We write the full path.

That's it, now let's launch and check. If it works, then go to the Scheduler.

Space in the title - I can’t run bat

If you have spaces in the folder and file names, then enclose this path in quotes like I did. Then everything works fine.

If you don't write start

Then it will simply give an error that the command is unknown. Without start you can run the command in cmd

How to archive a folder in rar using cmd

The folder can be added to the archive using a simple command in cmd:
WinRAR A "D:\android-locat\Vega.rar" "D:\Program Files\bdseoru"


As you can see, here you can already “run” winrar separately start command no need.

How to add subfolders and files to an archive

To add subfolders and files to a .rar or .zip archive, add the -r switch. That is, the command will look like this:
WinRAR A -r "D:\android-locat\Vega.rar" "D:\Program Files\bdseoru"

How to delete files after archiving in winrar

Very often there is also a need to delete archived files and folders. To do this you need to add the -ep1 command. Sample code:
WinRAR A -r -ep1 "D:\android-locat\Vega.rar" "D:\Program Files\bdseoru"

That is, we archive the folder, process subfolders and files, and then delete them. If the archive is placed in this folder, it will not be deleted, but an error will appear that the folder is not empty. Therefore, it is better to save the archive in another folder (it is better to simply remove the last slash).

Read more on the official website of the winrar team.

Syntax command line

WinRAR can be controlled from the command line. The general command line syntax is:

WinRAR<команда> -<ключ1> -<ключN> <архив> <файлы> <@файл-список> <путь для извлечения\>

team A combination of characters that defines the action that WinRAR will perform.
key Keys are used to determine specific actions, compression ratio, archive type, etc.
archive The name of the archive being processed.
files Names of processed files.
list file List files are ordinary text files, containing the names of the files to be processed. Each file name must be on a separate line and begin at the first position of the line. It is allowed to place comments in the list file; the sign of the beginning of a comment is the // symbols. For example, to archive *.txt files from the c:\work\doc folder, *.bmp files from the c:\work\image folder, and all files from the c:\work\misc folder, you can create a backup.lst containing the following lines:

c:\work\doc\*.txt//backup copy of texts

c:\work\image\*.bmp//backup copy of pictures

After this, to archive it will be enough to run the command:

winrar a backup @backup.lst

On one command line you can specify both regular names or groups of files to process, and list files. If neither files nor list files are specified, then the template is assumed *.* (i.e. WinRAR will process all files).

extraction path Only used with commands e And x and specifies the folder where the files should be extracted. If this folder does not exist, it will be created.

Notes

a) If neither files, nor list file, then the pattern *.* is implied , those. WinRAR will process all files.

b) If not specified extension archive, then WinRAR will use the default archive format selected in the default archiving profile, but if you want to specify the archive type explicitly, you can do this by adding to the name archive RAR or ZIP extensions.

c) Keys entered on the command line have higher priority than the corresponding settings in the configuration dialog, i.e. the parameters specified by the keys are used.

d) For teams C, E, S, T, R.R., K And X You can use wildcards in the archive name, so you can process several archives at once with one command. Moreover, if you specify the key along with these commands, then the archives will be searched in all subfolders.

e) Some commands and switches are applicable only to RAR archives, some to RAR and ZIP archives, and some to archives of all supported formats. This depends on the capabilities included in the archive format.

f) Commands and switches are not case sensitive, so you can type them in both lowercase and uppercase letters.

general description

The method is based on a combination of possibilitiesWindows(assigned tasks) and archiverWinRAR(command line control),WinRAR"uncircumcised" will be required.

The Scheduled Task settings will allow you to set:

  • -How the task will be launched: when you turn on the computer, according to a schedule, manually.
  • -Which computer operating mode will the task be launched from: working or sleeping.
  • -Additional settings for laptops and other PC antiques.

SettingsWinRAR will allow you to: specify the archive address, directories/files/lists for archiving. Clarify the composition of the archive according to the following principles: file extensions, creation time, presence/absence in the archive, “refresh” the archive (update only files that are in the archive), add files that have reappeared at the archived address, delete those that have “disappeared”, however, about the possibilities WinRARlater with examples.

ATTENTION! If in the settingsWinrardirectories/files/lists for archiving are not indicated, but only the archive address is indicated:WinRAR will archive the entire system, and everything that is available to the system in this moment. This can lead to "bad things."

VerifiedFor: Windows 2000/2000 Server/XP/Server 2003/Windows 7/Server 2008.

Example settings

Description according to the principle: goal - method of solution, I do not describe deviations, only a brief reference in parentheses. I am sure that based on the examples you will be able to compose exactly your task. So:

TARGET : Once a week, archive all 1c databases located in one directory. The task should add new things to the archive, delete missing ones, leave static (unchanged) files intact: only files will be processed: newly created, changed, deleted ones. Automatically it will look like this:

We create in Windows new"assigned task" The wizard starts. Prompts you to select a program. Naturally, we choose WinRAR. We write the name of the Task when it will be executed. Let's fill it out step by step..., turn on "Install additional...".

What? It says it won't work? Therefore: open our task (go to the Control Panel - Scheduled Tasks), turn on the “Run only when logged in” flag, go to the “Settings” tab and turn on “Wake up the computer...”. This is necessary so that the computer, left in sleep mode, “wake up” to complete the task. To start at the appointed time, we “allow” the computer to use Sleep mode. If according to the schedule the task should run, for example, at night, in the evening before this we do not turn off the computer, but put it into sleep mode. IN right moment The computer will wake up, complete the task, or maybe turn off after completion; this option is available in the WinRAR settings.

So, let's set it upWinRAR. We open the task, in the first line “Run” we see something like:

C:\PROGRA~1\WinRAR\WinRAR.exe

This is the full path of the program to be launched. WordWinRAR can replace this line, because ForWindowsThis is ALREADY a team.

WinRAR – substitute.

In this state our job is functional, but it will only run the programWinRAR. Now the settings.

The settings are written in the “Run” parameter after the existing one (C:\PROGRA~1\WinRAR\WinRAR.exe)through a space.

General command line syntax:

WinRAR – – //in this example "

What is required for our task:

WinRAR u - as F:\ Archive\ Data_1 C. rar D:\ Data_1 C //highlighted line segments with color. By color and comments.

u- team. Updates files in the archive, processes only changed ones and adds new ones.

-as - key. Removes files from the archive that are not in the source.

Thus, the combination of command and key synchronizes the archive with the original data.

F:\ Archive\ Data_1 C. rar– this is our archive with the address. The archive, even if empty, should already be at the specified address.

D:\ Data_1 C– archived data. In this case, a catalog.

SO, the order is: command – key/keys – archive – files/@file-list. Separator "_" (space).

I will not repeat myself in the future. Just comment on the differences.

TARGET : Archive valuable data (documents, favorites, etc.) daily. To prevent the process from being distracting, it turns the computer on and off automatically, 2 new keys have been added. The difference from the 1st task is that the data is in different directories. You'll have to use a list file. A list file is a text file in which:

-the first entry starts from the first character of the first line

-subsequent entries begin on a new line

-no extra characters, comments, etc.

If you specify a list file instead of a data address, please note that in this case the parameter (file address) begins with the @ symbol (dog).

You can include files, directories in the file list, select files by extension, etc.

We need the line:

WinRARu - asdh IOFF F:\ Archive\ Doc. rar@ C:\ SpisokArh. txt

-dh– allows you to archive currently open files. I turned it on because I often put the computer into “hibernation” with open documents and programs (except 1c). The worst thing is that an unsaved copy of the file will also be archived. And this is not critical, because... when opening such an archive, the computer will “remember” the unsaved versions. What to do with them is your business.

-IOFF– turn off the computer after archiving is completed. Thus, the computer does this completely independently. One BUT: it is SHUT OFF, and not going into sleep mode. In this regard, calculate the placement of tasks in time; if you have several tasks for the night, use this key only on the last task, so that this key does not “slow down” other tasks that did not have time to complete.

@ C:\ SpisokArh. txt – list file. Herehis text:

C:\Documents and Settings\Admin\Favorites

C:\Documents and Settings\Admin\Desktop\Downloads

I won’t describe all the variations that I use, I think you have enough imagination for more, I just hinted. Read the help WinRAR, there are complete lists of keys and commands, recommendations for use.

Additionally

  • WinRAR capable of archiving currently open files (read: open 1C databases), but! If you archive a database “on the go,” this can happen... 1s during archiving the database can change files, in the database archive it turns out that the files are *. dbfnot agreed upon. Hence the rule: at the time of archiving, all archived data (1C) must be closed. For others (MS Office) not relevant.
  • A new archive is not created automatically! It is necessary to indicate an existing one, even if it is empty.
  • When filling out a new archive, the procedure may drag on for..., then everything will work in accordance with the specified parameters.

P. S.: I apologize for the paucity of examples: I described only the most obvious ones. Then it’s a matter of your needs and imagination. Read the WinRAR Help, section "Command Line Mode".

rar.exe command options

http://www.forum.mista.ru/topic.php?id=227495

WinRAR can be controlled from the command line. The general command line syntax is: WinRAR<команда> –<ключ1> –<ключN> <архив> <файлы…> <@файл-список…> <путь для извлечения\>command A combination of characters indicating the action that WinRAR will perform. key Keys are used to define specific actions, compression ratio, archive type, etc. archive The name of the archive being processed. files Names of the files being processed. list file List files are simple text files containing the names of the files to be processed. Each file name must be on a separate line and begin at the first position of the line. It is allowed to place comments in the list file; the sign of the beginning of a comment is the symbols //. For example, to archive *.txt files from the c:\work\doc folder, *.bmp files from the c:\work\image folder, and all files from the c:\work\misc folder, you can create a backup.lst containing the following lines: c:\work\doc\*.txt //backup copy of textsc:\work\image\*.bmp //backup copy of picturesc:\work\miscAfter this, for archiving it will be enough to run the command:rar a backup @backup.lstIn one The command line is allowed to specify both ordinary names or groups of files to process, and list files. If neither files nor file lists are specified, then the *.* pattern is assumed (i.e. WinRAR will process all files). extraction path Used only with the e and x commands and specifies the folder where files should be extracted. If this folder does not exist, it will be created. Notes a) If neither files nor a file-list are specified, then the *.* pattern is assumed, and WinRAR will process all files. b) If the archive extension is not specified, then WinRAR will use the default archive format selected in the default archiving profile, but if you want to specify the archive type explicitly, this can be done by adding the RAR or ZIP extension to the archive name. c) Keys entered on the command line have higher priority than the corresponding settings in the configuration dialog, i.e. the parameters specified by the keys are used. d) For commands c, e, s, t, rr, k and x, templates can be used in the archive name, so one command can process several archives at once. Moreover, if you specify the -r switch along with these commands, then the archives will be searched in all subfolders. e) Some commands and switches apply only to RAR archives, some apply to RAR and ZIP archives, and some apply to archives of all supported formats. This depends on the capabilities included in the archive format. f) Commands and switches are not case sensitive, so you can type them in both lowercase and uppercase letters.

Options:

Ac Remove the "archive" attribute after archiving or extracting -ad Add archive name to destination path -af<тип>Specify the archive format -ag[format] Add the current date and time to the archive name -ao Add files with the "archive" attribute set -ap Set the path inside the archive -as Synchronize the contents of the archive -av Add an electronic signature -av- Prohibit adding/verifying electronic signatures -cl Convert file names to lower case -cu Convert file names to upper case -df Delete files after archiving -dh Open shared files -ds Do not sort files when archiving -ed Do not add empty folders -en Do not add an "end of archive" block " -ep Exclude paths from names -ep1 Exclude base folder from path -ep2 Save full file paths -f Refresh files -hp[password] Encrypt both data and file headers -ibck Run WinRAR as a background process in the system tray -ieml Send archive by email -ilog[name] Write the error log to a file -inul Do not display error messages -k Lock the archive -kb Save files extracted with errors to disk -m Set compression method -mc<параметры>Specify additional compression options -md Set dictionary size -ms Specify file types for uncompressed archiving -os Save NTFS streams -ow Process file permissions information -o+ Overwrite existing files -o- Do not overwrite existing files -p[password] Set password -r Recursively with nested ones folders -r0 Recursively with subfolders using a pattern -rr[N] Add recovery information -rv[N] Create recovery volumes -s Create continuous archive -s Create contiguous groups using the file counter -se Create contiguous groups using file extensions -sfx[name] Create a self-extracting archive -sv Create independent contiguous volumes -sv- Create dependent contiguous volumes -s- Disable the creation of contiguous archives -t Test files after archiving -ta<дата>Process files modified after the specified date -tb<дата>Process files modified before the specified date -tk Preserve the original archive time -tl Set the archive time to the newest file -tn<время>Process files no older than the specified time period -to<время>Process files older than the specified time period -u Update files -v Create a multi-volume archive -vd Clean up a removable disk before archiving onto it -ver File version control -vn Use the old volume naming scheme -vp Pause before each volume -x<файл >Do not process the specified file -x@<файл-список>Do not process files specified in the list file -y Answer "Yes" to all requests -z<файл>Read archive comment from file -- Interrupt further search for keys on the command line

Teams:

A Add files to the archive C Add an archive comment D Delete files from the archive E Extract files from the archive, ignoring paths F Refresh files in the archive K Lock the archive M Move files and folders to the archive R Restore a damaged archive RC Recreate missing volumes RR[N] Add recovery information RV[N] Create volumes for recovery S[name] Convert the archive into a self-extracting one S- Remove the SFX module T Test the files in the archive U Update the files in the archive X Extract files from the archive with full paths

L: View archive contents.

Our examples:

Add to archive named arh.rar All files with extensions .dbf and .cdx.

1. Create a subdirectory Arhiv in the BAZA directory.

2. Set the path to the Arhiv subdirectory:

SET DEFAULT TO "D:\BAZA\Arhiv"

RUN WinRAR\RAR.exe a arh.rar D:\BAZA\*.dbf

RUN WinRAR\RAR.exe a arh.rar D:\BAZA\*.cdx

Extract files from archive, ignoring paths ( All files with extensions .dbf and .cdx):

1. Create a Razarh subdirectory in the BAZA directory.

2. Set the path to the Razarh subdirectory:

SET DEFAULT TO "D:\BAZA\Razarh"

3. Place the WinRAR program in the Arhiv directory.

4. Enter MS-DOS command line commands:

RUN WinRAR\unrar.exe e -y arh.rar *.dbf "D:\BAZA\razarh"

RUN WinRAR\unrar.exe e -y arh.rar *.cdx "D:\BAZA\razarh"

A number of OS X users have difficulties working with RAR archives. Someone solves them by installing free utilities from the AppStore, but there are more correct solution.

In general, this note is for those who do not want to load their Mac with unnecessary software and know how to use the terminal.

The author of the WinRar archiver actually did not deprive other OSes of attention. Versions for Linux, FreeBSD and Mac OS X are available for download on the official website, they just do not have a graphical interface.

Download the archive for OS X and unpack it into any convenient folder.

Installation

In order to use the commands for archiving rar and unpacking unrar, they need to be installed. This is done as follows:

The command transfers the rar application to the /bin folder of the system: sudo install -c -o $USER rar /bin The command transfers the unrar application to the /bin folder of the system: sudo install -c -o $USER unrar /bin

or for El Capitan and higher:

The command transfers the rar application to the /usr/local/bin folder of the system: sudo install -c -o $USER rar /usr/local/bin The command transfers the unrar application to the /usr/local/bin folder of the system: sudo install -c -o $ USER unrar /usr/local/bin

That's all. Commands will now be available from any directory, no matter where you are.

You can check if everything is fine by simply running rar or unrar in the terminal. As a result, you should see the version number and other information!

And yet, below we have collected several typical examples of using the archiver via the command line on OS X.

Examples of using

Creating a catalog archive:

Rar a archive.rar folder/

Creating an archive from several files:

Rar a archive.rar file.jpg file.doc file.mov

Creating an archive of the directory folder with the password qwerty:

Rar a -pqwerty archive.rar folder/

Creating an archive with a password, encryption and a list of files:

Rar a -hpqwert archive.rar folder/

Creating an archive without compression algorithms:

Rar a -m0 archive.rar folder/

Creating an archive with maximum compression:

Rar a -m5 archive.rar folder/

Unpacking the archive into the current directory:

Unrar e archive.rar

Unpacking the archive into a separate directory:

Unrar x archive.rar

That's all. Thank you for reading to the end!

Updated February 26, installation on OS X El Capitan and higher. Thanks for your comments e33 And neprokin!