Make a exclusion list + files list using winrar command line - batch-file

I made this script below to make a backup of some files. It works fine, but i wanted make a list for the files that need be skipped from compressing.
For example:
my list.txt has all the files that will be compressed. But i wanted to make another list for the files that need be skipped, like exclusion_list.txt. Actually i put all files that i want be ignored from compressing into the command line, as shown below -x*\Test1 -x*\Test2.
But i really wanted to make a exclusion list for not keep changing the command line everytime i need to exclude a file or folder.
How i can do it?
"%winrar%\winrar.exe" a -x*\Test1 -x*\Test2 -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"

From the documentation: the exclusion option -x also supports a list file when it is preceded by #:
"%winrar%\winrar.exe" a -x#exclusion_list.txt -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
with the file exclusion_list.txt containing:
*\Test1
*\Test2
By the way, there is even a console version of WinRAR, called rar.exe, which is a non-GUI version.

Related

Winrar, "-or" overwrites file in archive instead of adding number to name if exists

After Googling and "researching" for over 3 hours to no avail, i have turned here to possibly get some help to my issue. Either if its possible or not to some extent.
This is a bit messy i know, but i'm fairly new to this.
What im trying to do.
I want to Backup a File which adds it to a archive folder With a Timestamp to it. YYYY-MM-DD Which then contains the File
2021-03-09.rar
File01.db
Then it takes the created file and adds it to a Backup.rar
Backup.rar
2021-03-09.rar
File01.db
Now i got this to work, My only problem here is that it instead overwrites the current existing File "2021-03-09.rar" in the Archive "Backup.rar" with the new one, instead of adding a number to the new backup that i added.
This is how i want/it should do;
Backup01: 2021-03-09.rar
Backup02: 2021-03-09-01.rar
Backup03: 2021-03-09-02.rar
Backup04: 2021-03-09-03.rar > and so on.
Code/what i have tried
I have tried using the commands "M" and "U" but same result, i tried using -or as well, which should rename files automatically if a file with the same name exists, but it doesnt work and the file(2021-03-09.rar) in my archive(Backup.rar) gets overwritten instead with the new backup(2021-03-09.rar).
Code:
"%ProgramFiles%\WinRAR\rar.exe" a -agYYYY-MM-DD -cfg -ep1 -m5 -r -y "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups\.rar" "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\File01db"
"%ProgramFiles%\WinRAR\rar.exe" a -or -ep "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups.rar" "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups\*"
While i know its not the smartest way to add a rar file to another rar file, its what i decided to do, it might be smarter to just have the bat file create a folder that it then adds to the archive or if it creates a folder in winrar and then adds the file to the folder in the archie, but it seemed to advanced.
Use YYYYMMDD and add an archive number, where the archive number is a numeric value starting from 1.
That will generate unique names even when the YYYY-MM-DD-NN format mask is used more than once in the same day.
WinRAR a -agYYYY-MM-DD-NN backup
WinRAR searches for already existing archives with that generated name and if found, increments the archive number to generate an unused name.
Refer to WinRAR, Help. Help topics and search for '-ag'

How to create a batch file that will zip few different files in one .zip file

I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.
I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.
Example (look at attached image):
I have a folder that contains 1.txt, 2.xml, a sub directory.
And I want to turn all of them into a .zip file.
If possible to get a solution both for windows and Mac.
On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.
On Contents tab there is the list item Command Line Version with the help pages:
Syntax ... Command Line Syntax
Commands ... Command Line Commands
Switches ... Command Line Switches
The target is to compress everything in folder test into a ZIP file with name of the folder as file name.
This could be done for example with the command line:
"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"
This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).
In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.

Batch file to create a zip of several files and copy it somewhere else

I want to back up important files to my USB drive every day. The USB drive is always plugged into the computer, so I don't need to worry about drive letters. I know how to create a batch file to simply copy and paste them into the drive, but I was wondering if there is a way to create a batch file that makes a zip file of all the folders I want (using winzip or winrar), and then has them sent to the drive. That way I can archive them instead of just copying and replacing them.
Thank you.
See:How can you zip or unzip from the command prompt using ONLY Windows' built-in capabilities?
Powershell can do this:
Add-Type -A System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory('C:\foo\', 'D:\foo.zip')
you can incorporate it into a batch file by calling powershell.exe like so:
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('C:\foo\', 'D:\foo.zip'); }"
I would recommend running it from a scheduled task so you don't have to start it manually or worry about it running all the time, and plan on disconnecting/replacing/archiving the drive itself occasionally - locally attached storage is not a backup
Start WinRAR, click in menu Help on first menu item Help topics, expand on help tab Contents the list item Command line mode and
read the help page Command line syntax,
expand the list item Commands and read the help page Alphabetic commands list and
expand the list item Switches and read the help page Alphabetic switches list.
Then you know how I created this single command line below and what all those switches mean.
"%ProgramFiles%\WinRAR\WinRAR.exe" a -ac -ao -afzip -agYYYY-MM-DD_NN -cfg- -ed -ep1 -ibck -inul -m5 -r -y -- "D:\Backup Folder\DataBackup_.zip" "C:\Path To Folder With Files To Backup\"
See also answer on Simply compress 1 folder in batch with WinRAR command line?
WinRAR adds to ZIP archive only files with archive attribute set because of switch -ao and clears the archive attribute after compressing the file into the archive because of -ac. The archive attribute is automatically set by Windows when a file is modified, renamed or moved. So this command line avoids compressing the same unmodified files again and again into ZIP archives.
The ZIP file is named automatically with current date in name and an automatic incremented number in case of this command line is executed multiple times on one day.

Post Build event xcopy - exclude some set of files

I want to copy some of the files to the specific folder after the successful compilation of the project. I have written a post build event as mentioned below:
xcopy "$(ProjectDir)bin" "$(TargetDir)..\..\Support Files\DBUpgradeUtility\" /Y
Note: the output path of my project has been set to bin folder for debug and release both the mode.
The above mentioned build event worked fine and all the files present under bin folder has been copied to destination folder. But along with the required files, the ‘vshost.exe’ files also copied, I don’t’ want this file. So, I have used the exclude parameter of xcopy build event as mentioned below:
xcopy "$(ProjectDir)bin" "$(TargetDir)..\..\Support Files\DBUpgradeUtility\" /Y /exclude:$(TargetDir)..\..\Support Files\DBUpgradeUtility\*.vshost.exe
With the above build event, the compilation failed and the error was:
The command "xcopy "C:\TFSWorkspace\FASTER.Web -
v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin"
"C:\TFSWorkspace\FASTER.Web -
v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin....\Support
Files\DBUpgradeUtility\" /Y /exclude:"C:\TFSWorkspace\FASTER.Web -
v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin....\Support
Files\DBUpgradeUtility*. vshost.exe" exited with code 4.
I have also googled for exclude parameter and then written the build event mentioned above. I cannot find what I am missing here or what I did wrong.
Please help me on this.
Thank you.
The /exclude option of the xcopy command works differently - it allows you to specify files which contain exclude filters:
Specifies a list of files. At least one file must be specified. Each
file will contain search strings with each string on a separate line
in the file.
When any of the strings match any part of the absolute
path of the file to be copied, that file will be excuded from being
copied. For example, specifying the string, \obj\ or .obj will exclude
all files underneath the directory obj or all files with the .obj
extension.
Therefore you may create a new file in your project (for example $(ProjectDir)excludes.txt) and add this line:
vshost.exe
Then change the option in your xcopy command to:
/exclude:"$(ProjectDir)excludes.txt"
This excludes all files containing vshost.exe in their absolute path. If you have to exclude other files, just add a new line to the file.

IBM i PASE tar - Excluding files or directories

I want to exclude some directories from an archive using the PASE tar command on an IBMi but the [-X Exclude File] option doesn't seems to work for me.
I tried using an exclude file that just contained a file name (/home/JSMITH/data/sub2/file2.txt) and then one that just contained a pattern (*.txt), and neither archive operation omitted anything.
Given the following directory structure:
/home/JSMITH/data
/home/JSMITH/data/sub1
/home/JSMITH/data/sub1/file1.txt
/home/JSMITH/data/sub2
/home/JSMITH/data/sub2/file2.txt
/home/JSMITH/data/sub3
/home/JSMITH/data/sub3/file3.txt
and the following command:
/qopensys/usr/bin/tar -cvf /home/JSMITH/test.tar -X /home/JSMITH/excludes.txt /home/JSMITH/data
The entire /home/JSMITH/data structure gets included in the resulting archive.
I have tried using the /home/JSMITH/excludes.txt file with either of these contents:
/home/JSMITH/data/sub2/file2.txt
or
*.txt
How does one exclude files/directories/patterns from the IBMi PASE tar command?
You need the full path in the exclude file.
I created mine via ls /home/JSMITH/data/*.txt > /home/JSMITH/excludes.txt
If you're doing it by hand, make certain you haven't got any trailing whitespace.
Also, I used Notepad++ when I created mine by hand. I found that the green screen edtf created an EBCDIC file with CRLF in it, and that didn't exclude for me.
IBM i 7.1

Resources